#include <stdio.h> int main() { int num, cube, sum = 0, i = 1; /* get the input value n from user */ scanf("%d", &num); printf("\n"); if((num<0) || (num>100)) { printf("Invalid Input\n"); } else { /* calculate the sum of cubes of 1st n natural nos */ while (i <= num) { cube = i * i * i; sum = sum + cube; i++; } /* print the sum of cubes of 1st n natural nos */ printf("%d\n",sum); } return 0; }
0 comments:
Post a Comment