Write a c program to reverse a string






Reverse a string in c without using temp
String reverse using strrev in c programming language

#include<stdio.h>
#include<string.h>
int main(){
    char str[50];
    char *rev;
    printf("Enter any string : ");
    scanf("%s",str);
    rev = strrev(str);
   
    printf("Reverse string is : %s",rev);
   
    return 0;
}

String reverse in c without using strrev
String reverse in c without using string function
How to reverse a string in c without using reverse function

#include<stdio.h>
int main(){
    char str[50];
    char rev[50];
    int i=-1,j=0;

    printf("Enter any string : ");
    scanf("%s",str);
   
    while(str[++i]!='\0');

    while(i>=0)
     rev[j++] = str[--i];

    rev[j]='\0';
  
    printf("Reverse of string is : %s",rev);
  
    return 0;
}

Sample output:
Enter any string : cquestionbank.blogspot.com
Reverse of string is : moc.topsgolb.knabnoitseuqc

Reverse a string in c using pointers
C program to reverse a string using pointers

#include<stdio.h>
int main(){
    char str[50];
    char rev[50];
    char *sptr = str;
    char *rptr = rev;
    int i=-1;

    printf("Enter any string : ");
    scanf("%s",str);
   
    while(*sptr){
     sptr++;
     i++;
    }

    while(i>=0){
     sptr--;
     *rptr = *sptr;
     rptr++;
     --i;
    }

    *rptr='\0';
  
    printf("Reverse of string is : %s",rev);
  
    return 0;
}


Sample output:
Enter any string : Pointer
Reverse of string is : retnioP







3. Write a c program to delete the all consonants from given string.

21 comments:

  1. write a program if a customer has an account more than 5 years and is a government servant then loan approve , government servant or not an account more than 5 years loan approve , customer account less than 5 years and not a government servant then loan not approve.

    ReplyDelete
    Replies
    1. #include
      #include
      #include

      int main()
      {
      int j,l,i;
      char s[10];
      printf("\n\nEnter the String to get reversed\n");
      gets(s);// taking string in variable s

      l=strlen(s);
      printf("\n\nreverse string is \n");
      for(j=l-1;j>=0;j--)
      {
      printf("%c",s[j]);
      }
      getch();
      }

      Delete
  2. I am not a pro, just tried about what you asked, here is the code, may this help you.


    #include
    #include
    #include
    void main()
    {
    int atime;
    char gsev[10];
    clrscr();
    printf("Enter the time you are active about the account:");
    scanf("%d",&atime);
    printf("Government servant? Enter YES or NO:");
    scanf("%s",gsev);
    if(atime>=5 && strcmp(gsev,"yes")==0)
    printf("Loan has approved for you!");

    else if(atime<5 && strcmp(gsev,"yes")==0)
    printf("Loan hasn't approved.");

    else if(atime<5 && strcmp(gsev,"no")==0)
    printf("Loan hasn't approved.");

    else if(atime>=5 && strcmp(gsev,"no")==0)
    printf("Loan hasn't approved.");
    getch();
    }

    ReplyDelete
  3. write a program to print the following pattern using 1 loop(i.e. u can use a loop only once any loop)
    2 4 6 8 10
    1 3 5 7 9

    ReplyDelete
    Replies
    1. #include
      #include
      int main()
      {
      int a[]={1,2,3,4,5,6},n,i=0,flag,j=0,b[25],p;
      n=(sizeof(a)/sizeof(int));

      flag=0;
      for(i=0;i<=n;i++)
      {
      if(flag==0)
      {
      if(a[i]%2==0)
      {
      printf("%d\n",a[i]);
      }
      if(i==n)
      {
      flag=1;
      i=0;
      }
      }
      if(i<n)
      {
      if(flag==1)
      {
      if(a[i]%2!=0)
      {
      printf("%d\n",a[i]);
      }
      }
      }
      }
      }

      Delete
  4. Acc to gregarian calander it was monday on 01/01/01. If any year is input through the keyboard write a programme to find outwhat is the day on 1st january of this year

    ReplyDelete
  5. useful very useful

    ReplyDelete
  6. any one can give me an explanation for this string reverse program

    ReplyDelete
  7. i want C program using string to display
    Input:KUMAR
    Output: K1U2M3A4R5... anyone plz ...

    ReplyDelete
  8. Hey Surya Kumar Here is the Solution::
    #include
    #include

    void main(){
    char str[50];
    int i=0;
    clrscr();
    printf("\nEnter a string::");
    gets(str);
    while(str[i]!='\0'){
    printf("%c%d",str[i],i+1);
    i++;
    }
    getch();
    }

    ReplyDelete
  9. #include
    #include
    #include
    void main()
    {
    char a[40],b[40];
    int i,l;
    cout<<"\nenter ur string";
    gets(a);
    l=strlen(a);
    for(i=0;i<l;i++)
    {
    b[i]=a[l-(i+1)];
    }
    for(i=0;i<l;i++)
    {
    cout<<b[i];
    }}

    ReplyDelete
  10. Wap to reverse I Am as I ma...

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. hay Anjali thanx for submit this. here is solution for u

      #include
      #include
      int main(){
      char str[50];
      char *rev;
      printf("Enter any string : ");
      scanf("%s",str);
      rev = strrev(str);

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

      return 0;
      }

      Delete
  11. would you please tell me how to check wheather the string is palindrome or not using for loop

    ReplyDelete
  12. Using strrev function string and original string .then compare two function by strcmp and then give solution

    ReplyDelete
  13. second program has a mistake.. while (i>0) not >= because --i become -1 at the end

    ReplyDelete
  14. write a programme in c language:Enter a disordered string
    the outpt alphabetic ordered string

    ReplyDelete
  15. my version:
    void reverse(char* s, char* r)
    {
    r+=strlen(s);
    *r--='\0';

    while( *s )
    *r-- = *s++;
    }

    ReplyDelete
  16. Guys code for
    Input: 12/02/1993
    Output: 12-feb-1993

    ReplyDelete
  17. want prog ;
    input : vector 123 india 567
    output : vector 321 india 765

    ReplyDelete