Ads 468x60px

Labels

Monday, 17 September 2012

Reverse of a string using pointers

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
char *a;
clrscr();
printf("enter a string");
scanf("%s",a);
i=0;
while(*(a+i)!='\0')
i++;
for(j=i-1;j>=0;j--)
printf("%c",*(a+j));
getch();
}

C Program for Factorial of a Number using Recursive Functiol

#include<stdio.h>
#include<conio.h>
long int factorial(int n);
void main()
{
int n;
clrscr();
printf("Enter the number:\n\n");
scanf("%d",&n);
printf("Factorial of %d is %ld",n,factorial(n));
getch();
}
long int factorial(int n)
{
if(n<=1)
{
return(1);
}
else
{
n=n*factorial(n-1);
return(n);
}
}