mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
Update disarium.c
added comments and indented properly
This commit is contained in:
parent
9140bea155
commit
6974f28d61
@ -1,21 +1,22 @@
|
|||||||
|
// a disarium number is a number such that sum of the digits of the number raised to their respective position equals the number
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include<math.h>
|
#include <math.h>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int n,i=0,j,sum=0,l,k;
|
int n,i=0,j,sum=0,l,k;
|
||||||
scanf("%d",&n);
|
scanf("%d",&n);
|
||||||
k=n;
|
k=n; //number stored in temporary variable
|
||||||
j=k;
|
j=k;
|
||||||
while(n>0)
|
while(n>0)
|
||||||
{
|
{
|
||||||
d=n%10;
|
d=n%10;
|
||||||
n=n/10;
|
n=n/10;
|
||||||
i++;
|
i++; //to get the number of digits which will be the position for last digit
|
||||||
}
|
}
|
||||||
while(k>0)
|
while(k>0)
|
||||||
{
|
{
|
||||||
l=k%10;
|
l=k%10; //to get the digit
|
||||||
sum=sum+pow(l,i);
|
sum=sum+pow(l,i);
|
||||||
k=k/10;
|
k=k/10;
|
||||||
i--;
|
i--;
|
||||||
|
Loading…
Reference in New Issue
Block a user