Printing sum of cubes of a digits of a number.[C Program Code]


This program prints the sum of cubes of a digits of a number.
For eg. If we input 111, we get the output as 3 which equals (1³+1³+1³ = 3).
#include<stdio.h>
int main()
{
int a,sum = 0 ,copy,n,i;
printf("Enter the number: ");
scanf("%d",&a);
copy = a;
while(a!=0)
{
i=a%10;
sum = sum + (i*i*i);
a=a/10;
}
printf("The sum of cube of digits of %d is %d",copy,sum);
getch();
return(0);
}
view raw gistfile1.txt hosted with ❤ by GitHub

Comments