Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday, December 18, 2014

Program to find place value of all digits of any number given by user using while loop in C.


Place value of number by while loop



Code Box
-----------------------------------------------------

/*Program to find place value of all digits of any number given by user using while loop in C */

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int num,num1,rem,pval,rev,len;
clrscr();
len=0;
rev=0;
printf("\n\tSum of Digits Finder");
printf("\n-------------------------");
printf("\nEnter a number:");
scanf("%d",&num);

num1=num; //to save actual number

/*Finding the length of number & reverse */ 
while(num1>=1)
{
rem=num1%10;
num1=num1/10;
rev=rev*10+rem;
len++;
}


/*Calculation the place value */
len=len-1;
while(rev>=1)
{
rem=rev%10;
rev=rev/10;
pval=rem*pow(10,len);
printf("\nPlace value of %d is = %d",rem,pval);
len--;
}
getch();

}

No comments: