Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Comment



Header file



" ; " after loop



Specifer



Working with switch case




Revers of a given number




// AHF C PROGRAM SOLVING

//solving here ITERATIVES STATEMENTS type of programming problem

We can solve this problem in two ways:
The first way is below:
#include<stdio.h> #include<math.h> #define pf printf int main() { int n,temp; //taking the value to continue the loop pf("\nEnter any integer number: "); scanf("%d",&n); pf("\nThe reserve number is: "); while(n!=0) //ending condition of the loop { temp=n%10; pf("%d",temp); //printing revers number n/=10; //update loop } return 0; }
The second way is below:
#include<stdio.h> #include<math.h> #define pf printf int main() { int x,temp,r=0; //taking the value to continue the loop pf("Enter any integer number: "); scanf("%d",&x); pf("\nThe reveres of %d = ",x); while(x!=0) //ending condition of the loop { temp=x%10; r=r*10+temp; //revers the given number and reserved in r variable x/=10; //update loop } pf("%d",r); //printing revers number return 0; }
OUTPUT:


© 2018 - All rights reserved