Thursday, February 24, 2011

Decision Making and Looping

Rewrite the program of the reverse the digits of the number using the for statement.

#include <stdio.h>
#include <math.h>
void main()
{
int x,y,i=0,ans,P,n;
clrscr();
printf("Enter a number and number of digits:");
scanf("%d %d",&x,&n);
for(;i<n;i++)
{
y=pow(10,i);
P=x/y;
ans=P%10;
printf("%d",ans);
}
getch();
}

No comments:

Post a Comment