C Code 40 _ To Write a C Program to Reverse each word in a given sentence

C Code 40 _ To Write a C Program to Reverse each word in a given sentence


Sample Input: 


abcd  efg  hij

Sample Output:


dcba  gfe  jih


Program:


#include<stdio.h>
#include<string.h>
int main()
{
char input[20];
int size,i,initial=0,j;
printf("\nEnter a Sentence : ");
gets(input);
size=strlen(input);
printf("\n\nSentence with reversed words : ");
for(i=0;i<=size;i++)

if(input[i]==' '||input[i]=='\0')
{
for(j=i-1;j>=initial;j--)
{
  printf("%c",input[j]);
}
printf(" ");
initial=i+1;
    }
}
return 0;
}



Output:










Thank You ...


* * * * * * * *  The above Program is contributed by AjayRam KV  * * * * * * * * *

Popular Posts