Wednesday, December 4, 2019

Write a program in C to print individual characters of string in reverse order

#include<stdio.h>
#include <string.h>
#include <stdlib.h>
void main()
{
    char str[100]; /* Declares a string of size 100 */
    int l=0;
   
  printf("\n\nPrint individual characters of string in reverse order :\n");
       printf("------------------------------------------------------\n");    
       printf("Input the string : ");
       fgets(str, sizeof str, stdin);
       l=strlen(str);
       printf("The characters of the string in reverse are : \n");
       for(str[l]='\0';l
>=0;l--)
        {
          printf("%c  ", str[l]);
        }
    printf("\n");
}
 

OUTPUT:
Print individual characters of string in reverse order :
------------------------------------------------------
Input the string : hello
The characters of the string in reverse are :
 
  o  l  l  e  h

No comments:

Post a Comment