Q : Write a C program to read a line and print it reverse using recursive function.
Solution :
#include<stdio.h>
#include<string.h>
#include<process.h>
void print(int len,char str[])
{
int n=len;
if(n==-1)
else
{
printf("%c",str[n]);
print(n-1,str);
}
}
void main()
{
char ch[100];
int len,i;
printf("Enter a line>> ");
gets(ch);
len=strlen(ch);
print(len,ch);
}
No comments:
Post a Comment