Write a c program to reverse a given word using a function
Write a c program to reverse a given word using a function.
1 2 3 4 5 6 7 8 9 10 11 | #include <stdio.h> #include <string.h> int main() { char s[40]; printf("Please Enter a string to reverse it.\n"); gets(s); strrev(s); printf("The Reverse of the string is: %s\n", s); return 0; } |
Output
Please Enter a string to reverse it.
t4tutorials
The Reverse of the string is:
slairotut4t
Write a c program to reverse a given word without using a function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <stdio.h> int main () { char Array1[1000], Array2[1000]; int start, finish, count = 0; printf("Please Input a string\n"); gets(Array1); // Calculating string length while (Array1[count] != '\0') count++; finish = count - 1; for (start = 0; start < count; start++) { Array2[start] = Array1[finish]; finish--; } Array2[start] = '\0'; printf("%s\n", Array2); return 0; } |
Output
Please Input a string
t4tutorials
slairotut4t