Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Listing 5.13. The addemup.c Program /* addemup.c -- four kinds of statements */

ID: 3773572 • Letter: L

Question

Listing 5.13. The addemup.c Program
/* addemup.c -- four kinds of statements */
#include <stdio.h>
int main(void) /* finds sum of first 20 integers */
{
int count, sum; /* declaration statement */
count = 0; /* assignment statement */
sum = 0; /* ditto */
while (count++ < 20) /* while */
sum = sum + count; /* statement */
printf("sum = %d ", sum);/* function statement */
return 0;
}

b) Now modify the given program so that it computes the sum
of the squares of the integers. (If you prefer, how much money you receive if you
get $1 the first day, $4 the second day, $9 the third day, and so on. This looks
like a much better deal!) C doesn't have a squaring function, but you can use the
fact that the square of n is n * n. Please do it as simple as possible :) and Use C programming techniques.

Explanation / Answer

#include<stdio.h>

int main()
{
    int i=0;/* declarative statement */
    int n=20; /*assignment statement*/

   //clrscr();
    while(i++<20)
{
if(i=1)
     printf("$ %d the first day" ,i*i);
if(i=2)
     printf("$ %d the second day" ,i*i);
     if(i=3)
     printf("$ %d the third day" ,i*i);
if(i=4)
     printf("$ %d the forth day" ,i*i);
if(i=5)
     printf("$ %d the fifth day" ,i*i);
if(i=6)
     printf("$ %d the sixth day" ,i*i);
if(i=7)
     printf("$ %d the seventh day" ,i*i);
if(i=8)
     printf("$ %d the eigth day" ,i*i);
if(i=9)
     printf("$ %d the nineth day" ,i*i);
if(i=10)
     printf("$ %d the tenth day" ,i*i);
    if(i=11)
     printf("$ %d the eleventh day" ,i*i);
if(i=12)
     printf("$ %d the twelveth day" ,i*i);
     if(i=13)
     printf("$ %d the thirteen day" ,i*i);
if(i=14)
     printf("$ %d the forteen day" ,i*i);
if(i=15)
     printf("$ %d the fifteen day" ,i*i);
if(i=16)
     printf("$ %d the sixteen day" ,i*i);
if(i=17)
     printf("$ %d the seventeen day" ,i*i);
if(i=18)
     printf("$ %d the eigtheen day" ,i*i);
if(i=19)
     printf("$ %d the nineteen day" ,i*i);
if(i=20)
     printf("$ %d the twenty day" ,i*i);
}
return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote