#include
#include
void pr_reverse(char *s);
int main(void)
{
pr_reverse("I like C");
return 0;
}
void pr_reverse(char *s)
{
register int i;
for(i = strlen(s) - 1; i >= 0; i--)
putchar( s [ i ] );
}
//reverse a string using pointers
# include<stdio.h>
# include<string.h>
void main()
{
char *first,*last;
char temp;
int len;
char str[20];
printf("enter ur string to be reverse: ");
gets(str);
len=strlen(str);
first=str; //point at first character
last=&str[len-1]; //point at last character
for(int i=0;i<=len/2;i++)
{
temp=*first;
*first=*last;
*last=temp;
first++;
last--;
}
puts(str);
}
//BY..RAJAT JAIN
The use of the reverse string in C program is used to reverse the letters in the string. An example would be reverse me would be reversed to em esrever.
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); }
a string constant
wefwfe
Assume C#, not C: Traditional way: public string Reverse(string s) { if (string.IsNullOrEmpty(s)) return s; // "" or null char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } or as an extension method: public static string Reverse(this string s) { if (s == "") return ""; char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } The differences of the 2 methods above is on the caller (how to use Reverse()), and they may co-exist: For example: string test = "abc"; string result1 = Reverse(test); // traditional way string result2 = test.Reverse(); // call the extension
The use of the reverse string in C program is used to reverse the letters in the string. An example would be reverse me would be reversed to em esrever.
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); }
a string constant
wefwfe
Assume C#, not C: Traditional way: public string Reverse(string s) { if (string.IsNullOrEmpty(s)) return s; // "" or null char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } or as an extension method: public static string Reverse(this string s) { if (s == "") return ""; char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } The differences of the 2 methods above is on the caller (how to use Reverse()), and they may co-exist: For example: string test = "abc"; string result1 = Reverse(test); // traditional way string result2 = test.Reverse(); // call the extension
Null is not a capital letter. It is not any letter. It is a null, '\0', (most often 0x00) and that is a special character, usually indicating the end of a string.
special character in c language are as follows~ ' ! @ # % ^ & * () _ - + = | \ {} [] : ; " <> , . ? /
#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
its just like a string of c++
I'd use sprintf (assuming the number wasn't a string already) and pointers. If that's not enough of a clue, you're really not ready to be in this programming class.
Use the atoi() or atol() function.
console.wrikerle("""");