Algorithm
1) Start
2) initialize i -->0,count-->1,temp-->1.
3) Take number from user store it on n.
4) find the number of digit it contain using while loop, and
multiply counter by 10 each time.
5) while n > 0
6) Assign temp --> n/coumt
7) subtract temp from n.
8) divide count by 10
9) print the value of temp
10) if n greater then 0 then goto step 6
11) else end.
C Program
======================================================
#include<stdio.h>
int main()
{
int i=0,n, num,count=1,temp=1;
printf(“\nEnter a number\n”);
scanf("%d",&n);
num = n;
while(num>0)
{
count=count*10;
num = num/10;
}
}
count = count/10;
while (n>0){
temp = n/count;
temp = temp *count;
n = n - temp;
count =
count/10;
if(n>0)
printf("%d+",temp);
else
printf("%d",temp);
}
getchar();
return 0;
}
OUTPUT
1234
1000+200+30+4
No comments:
Post a Comment