c program to reverse a string

 Problem Statement:

Write a c program to reverse a string without using string reverse function.

Note: Here we use a temp variable in for loop to reverse a string. So this method is also known as reverse a string using temp.

Solution

#include<stdio.h>

#include<string.h>

int main()

{

    int n,i,j;

    char s[1000],t;

    scanf("%s",s);

    n=strlen(s);

    for(i=0,j=n-1;i<n/2;i++,j--)

    {

        t=s[i];

        s[i]=s[j];

        s[j]=t;

    }

    printf("%s",s);  

Input

Rajesh

Ouput

hsejar

Input 

Thulasi

Output

isaluht

Rajesh

This Blog will help you to find out the c programs solution easily and also you can able to understand the program.Please follow our blog for more useful updates.

Post a Comment (0)
Previous Post Next Post