how to reverse a string in c
#include <iostream>
using namespace std;
int main()
{
char str[] = "Reverseme";
char reverse[50];
int i=-1;
int j=0;
/*Count the length, until it each at the end of string.*/
while(str[++i]!='\0');
while(i>=0)
reverse[j++]=str[--i];
reverse[j]='\0';
cout<<"Reverse of a string is"<< reverse;
return 0;
}
4.5
4
#include <stdio.h>
#include <string.h>
int main()
{
char str[2][100];
printf("Type Text: ");
scanf("%[^\n]%*c", str[0]);
int length = strlen(str[0]);
int i, j;
for (i = 0, j = length - 1; i < length; i++, j--)
{
str[1][i] = str[0][j];
}
printf("Original Word: %s\n", str[0]);
printf("Reverse word: %s\n", str[1]);
return 0;
}
Thank you!
4
0
3
1
#include <stdio.h>
int main() {
int n, rev = 0, remainder;
printf("Enter an integer: ");
scanf("%d", &n);
while (n != 0) {
remainder = n % 10;
rev = rev * 10 + remainder;
n /= 10;
}
printf("Reversed number = %d", rev);
return 0;
}
Thank you!
1
0
0
0
#include <stdio.h>
int main() {
int n, rev = 0, remainder;
printf("Enter an integer: ");
scanf("%d", &n);
while (n != 0) {
remainder = n % 10;
rev = rev * 10 + remainder;
n /= 10;
}
printf("Reversed number = %d", rev);
return 0;
}
Thank you!
0
0
Are there any code examples left?
New code examples in category C
-
C 2022-03-27 22:30:45 Problem Statement Print the following output: \ Input Format IN Output Format \
-
-
-
-
-
-
-