Use the atoi() or atol() function.
int a; -- variable definition"int a" -- string literal
You can perform arithmetic with it. int x {42}; x *= 2; // ok std::string s {"Hello"}; s *= 2; // error: std::string::operator*= (int) is undefined
Use an implicit or explicit cast. Since integers are whole numbers, the decimal portion will be truncated. Example in C: float f; int i; f = 1.5; i = f; // i = 1.0 Example in C++: float f = 1.5; int i = ( int ) f;
C language: int (but C is NOT a .net language) C# language: object or System.Object
data-type
#include #include using std::cin;using std::cout;using std::string;int main(){string myStr = "0";cout myStr;int myStrLength = sizeof(myStr)/sizeof(myStr[0]);for (int i = (myStrLength - 1); i >= 0; i--){cout
/* Write a function that will scan a character string passed as an argument & convert all lowercase characters into their uppercase characters*/ #include<stdio.h> #include<conio.h> #include<string.h> #include<ctype.h> int str_upp(char c[]) { int i; char x; printf("\n \n"); for(i=0;i<strlen(c);i++) { x=toupper(c[i]); printf("%c",x); } return (0); } void main() { char c[10]; clrscr(); printf("Enter string : \n"); scanf("%s",c); str_upp(c) ; getch(); } /* Output: Enter string : Heloo HELOO */
#include #include #include int reverse(int i);char st[]="ven123kat";void main() {printf("\nThe string is: %s", st);reverse(0);printf("\nReversed string is: %s", st);getch();}int reverse(int i) {if (i
Character.toString('c')
a string constant
To reverse a number, first convert the number to a string, then reverse the string. Given your number consists of alphanumeric characters, the number must already be a string so simply reverse the string: #include<string> using std::string; string reverse (const string& s) { string str {}; for (auto c : s) str.insert (str.begin(), c); return str; } int main () { std::cout << "Enter a number: "; string s {}; std::cin >> s; std::cout << "The number in reverse is: " << reverse (s); }
#include<stdio.h> #include<conio.h> void main() { char string[20]; int i=0; printf("Enter the string.\n"); while(i<=19) { scanf("%c",&string[i]); i++; } while(i>=0) { printf("%c",string[i]); i--; } getch(); } In this program it is compulsory to enter 20 characters. Now we can write a program in which it is not necessary. #include<stdio.h> #include<conio.h> #include<string.h> void main() { char string[20]; int length; printf("enter the string.\n"); gets(string); length=strlen(string); length--; while(length>0) { printf("%c",string[length]); length--; } getch(); }