Questions ListCategory: chow to write a c program using while loop to find the square of the first five numbers and their sum?
Anonymous asked 1 year ago

output is:

1
4
9
16
25
the total is: 55

1 Answers
Profile photo of wikistackwikistack Staff answered 1 year ago

Here is sample code
#include<stdio.h>

int main()
{
  int i = 5;
  int j = 1;
  int sum = 0;
  int sq = 0;
  while(i)
  {
     sq = j*j;
     printf(“%d\n”,sq);
     sum = sum + sq;
     j = j + 1;
     i–;
  }
  printf(“the total is %d \n”, sum);
  return 0;
}

Your Answer

20 + 1 =