Solved programming problem

Revers String in C.

Source code

#include <stdio.h>

int main()

{

    int i,j,len;

    int count=0;

    char str[20],rev[20];

    printf("Please Enter a Massage:");

    gets(str);

    for(i=0;str[i]!='';i++)

    {

        count++; ///counting the length

    }

    len=count;

    for(i=len-1,j=0;i>=0;i--,j++)

    {

        rev[j]=str[i];  ///saving the string from the last element of string

    }

    rev[j]=''; ///assign the last value as Null Character

    printf("Reverse: %s",rev);

    return 0;

}

Output

Please Enter a Massage: code to haven

Reverse: nevha ot edoc

Join the discussion

Add your comment