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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
Comments
Post a Comment