Search This Blog


Friday, 19 April 2019

Program to reverse a String

WELCOME BACK TO codejunction.in . hope you are enjoying our blogs , we have also uploaded some latest blogs on c coding make sure to check out them.


IN THIS PROGRAM THE USER NEEDS TO ENTER A STRING AND THEN THE PROGRAM WILL REVERSE THAT STRING .


WHAT IS STRING?
A STRING IS A COLLECTION OF ALPHABETS USED TOGEATHER TO MAKE A SENTENCE.



CODE


#include<stdio.h>
#include<conio.h>
void main()
{
    int i, j, k;
    char str[100];
    char rev[100];
    printf("Enter a string:\t");
    scanf("%s", str);
    printf("The original string is %s\n", str);
    for(i = 0; str[i] != '\0'; i++);
    {
        k = i-1;
    }
    for(j = 0; j <= i-1; j++)
    {
        rev[j] = str[k];
        k--;
    }
    printf("The reverse string is %s\n", rev);
    getch();

}



OUTPUT



No comments:

Post a Comment