In this c programming example user input a string and get reverse of accepted string.
Aim - C program to reverse accepted string [Using strrev function]
Program Code
//String Reverse using strrev function #include"stdio.h" #include"conio.h" #include"string.h" void main() { char str[20]; clrscr(); printf("********* String Reverse Using strrev Function *******\n"); printf("Enter a string: "); gets(str); strrev(str); printf("\n Reverse string is: %s",str); getch(); }Output
Aim - C program to reverse accepted string [without using strrev function]
Program Code
//String Reverse without using strrev function #include"stdio.h" #include"conio.h" #include"string.h" void main() { char str1[20],str2[20]; int i,j=0; clrscr(); printf("***********String Reverse*********\n"); printf("Enter String:"); gets(str1); for(i=strlen(str1)-1;i>=0;i--,j++) { str2[j]=str1[i]; } str2[j]=NULL; printf("\nReverse String is:"); puts(str2); getch(); }
Output
Dont SPAM