0
a for loop
ok using a for loop to calculate and display the the sum of 1 to n. where n is an input by the user . the result from the for loop should be some thing like 1+2+3+4=10 when n =4
2 Respostas
+ 1
#include <iostream>
using namespace std;
int main() {
int x;
cout<<"Enter a number n to calculate the sum from 1 to n"<<endl;
for (int i =1 ; i<=x; i++)
{
if(i==x){
cout<< "Sum of 1 through " << i << " is " << i*(i+1)/2<<endl;
}
}
}
//Write this code and it will work :)
+ 1
Thank you