Friday 6 July 2012

Write a C program to reverse all words but not string.


// Input :   My name is Kumar
// Outout: yM eman is ramuK

#include<stdio.h>
int main()
{
    char S[50];
    int i,j,t;
    printf("\nEnter Sentence : ");
    gets(S);
    printf("\nOUTPUT : ");
    for(i=0;S[i-1]!='\0';i++)
    {
        j=i;
        while(S[j]!=' ' && S[j]!=NULL)
            j++;
        t=j;
        while(j>=i)
            printf("%c",S[j--]);
        printf(" ");
        i=t;
    }
    printf("\n");
return 0;
}

No comments:

Post a Comment