+ 2
Solve this c++ program...on fatal errror
#include <iostream> #include <conio.h> using namespace std; int main() { { int i= 1, sum = 0; clrscr(); while(i++ <= 5) { cout<< '\n'<<i; S += i; } { cout << "\nvalue of the variable i after executing the while loop.." <<i<<"\nsum:...” <<s; return 0; }
2 Réponses
+ 8
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int i = 1, sum = 0;
while(i++ <= 5)
{
cout << '\n' << i;
sum += i;
}
cout << "\nvalue of the variable i after executing the while loop.." << i << "\nSum: " << sum << endl;
return 0;
}
+ 5
Use sum where you have used S and s. If you want the value of i to be displayed from 1 to 5 (not from 2 to 6) do the incrementing inside the loop towards the end rather than in the loop condition.