C Coding Questions With Solutions


Question :

Write a C-program which will Reverse a String

  
  
    int main()
{
    char a[50];
    int l,i=0,j,temp;
    printf("Enter a String/Number: ");
    gets(a);
    for(l=0;a[l]!='\0';l++); 
     //to determine length of String
    j=l-1;   // l is the length of String
    for(i=0;i<=l/2;i++)
    {
        temp=a[i];
        a[i]=a[j];
        a[j]=temp;
        j--;
    }
    puts(a);
    return 0;

}