Answer to Question #243865 in C++ for xtian

Question #243865

 LOOP: (TURBOc++)



Prg16: Program that accepts a number then output the sum of the squares from 1 to n.

Enter a number : 4

1^2 + 2^2 + 3^2 + 4^2 = 30


PLEASE USE:

#include<stdio.h>

#include<conio.h>


scanf

printf

 


example:

#include<stdio.h>

#include<conio.h>

main()

{

int n=1, x=20;

clrscr();

printf("While Loop Example");


while (n<=5)

{

gotoxy(x, 3);printf(" %d", n);

n++;x=x+5;

}

getch();

}


1
Expert's answer
2021-09-29T01:19:03-0400






#include<stdio.h>


#include<conio.h>


main()


{

printf("Enter a number");
int n;
scanf("%d", &n);




int squares = 0;
int i = 1;
while (i<=n)


{


squares += (i*i);


i++;


}
gotoxy(squares, 3); printf(" %d", squares);
getch();


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS