Connecting Tech Pros Worldwide Forums | Help | Site Map

what does the following program print ?

Newbie
 
Join Date: Nov 2008
Posts: 7
#1: Nov 21 '08
Hi all , i have this question due my homework ?

what does the following program print ?
@the out put @

#include <iostream>
using namespace std ;

int main ()

{
int y ;
int x = 1 ;
int total = 0 ;

while ( x<=10)
{
y = x*x ;
cout<<y<<endl;
total+=y;
x++;
}
cout<<"Total is " << total << endl;
return 0 ;
}

Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#2: Nov 21 '08

re: what does the following program print ?


Try putting into your compiler and see.
Newbie
 
Join Date: Nov 2008
Posts: 7
#3: Nov 21 '08

re: what does the following program print ?


i put it, but there was an error existing

"cannot excute file "
Member
 
Join Date: Nov 2008
Posts: 64
#4: Nov 21 '08

re: what does the following program print ?


Did you compile the file?
Newbie
 
Join Date: Nov 2008
Posts: 7
#5: Nov 21 '08

re: what does the following program print ?


yes , i put it in the compilor but there was an error saying

" error excuting link "
Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#6: Nov 21 '08

re: what does the following program print ?


Are you sure you've set up your compiler correctly? What compiler are you using?
Newbie
 
Join Date: Nov 2008
Posts: 7
#7: Nov 21 '08

re: what does the following program print ?


microsoft visual c++ 6.0
Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#8: Nov 21 '08

re: what does the following program print ?


Your code runs just fine on Bloodshed Dev C++ 4.9.9.2, and I can't stand Visual Studio, so I can't test your code on that. Regardless, there's nothing wrong with your code; your compiler must be the problem.

Anyway, you can probably look at that code and get an idea as to what it is printing (if not what it prints exactly).
Newbie
 
Join Date: Nov 2008
Posts: 21
#9: Nov 21 '08

re: what does the following program print ?


//output
1
4
9
16
25
36
49
64
81
100
Total is 385

if you look close this is 1-10 squared.
1^2 = 1
2^2 = 4
3^2 = 9
.
.
.
10^2

358 is the total!
Newbie
 
Join Date: Nov 2008
Posts: 21
#10: Nov 21 '08

re: what does the following program print ?


use g++ to compile ........
Newbie
 
Join Date: Nov 2008
Posts: 7
#11: Nov 21 '08

re: what does the following program print ?


thanks all very much
Reply