C programming examples with output
Reverse of a number
Program
#include<stdio.h>
#include<conio.h>
main()
{
int n,rev=0;
printf("Enter a number to rev:\n");
scanf("%d",&n);
while(n!=0)
{
rev=rev*10;
rev=rev+n%10;
n=n/10;
}
printf("Reverse of entered number is=%d\n",rev);
getch();
}
Output:
Enter a number to reverse:
1234
Reverse of entered number is=4321
Reverse of a number
Program
#include<stdio.h>
#include<conio.h>
main()
{
int n,rev=0;
printf("Enter a number to rev:\n");
scanf("%d",&n);
while(n!=0)
{
rev=rev*10;
rev=rev+n%10;
n=n/10;
}
printf("Reverse of entered number is=%d\n",rev);
getch();
}
Output:
Enter a number to reverse:
1234
Reverse of entered number is=4321
0 komentar:
Post a Comment