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 for loop in C.


Place value of number using for loop


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

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

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

void main()
{
int num,num1,rem,pval,rev,len,l;
clrscr();

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 */ 
for(len=0;num1>=1;len++)
{
rem=num1%10;
num1=num1/10;
rev=rev*10+rem;
}


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

}

No comments: