The given code is supposed to find the sum of numbers from 1 to n. Due to some logical errors or syntax errors, it fails to print the desired result. Fix the code to pass the test case.
Sample Input:
5
Sample Output:
15
Answers
Answered by
0
Explanation:
The given code is supposed to find the sum of numbers from 1 to n. Due to some logical errors or syntax errors, it fails to print the desired result. Fix the code to pass the test case.
Sample Input:
5
Sample Output:
15
1
#include
2
int main(){
3
int n=5, sum;
4
std::cin>>n;
5
for(int i = 1; i 6
sum = sum + i
7
}
8
std::cout< 9
} please make me Brianliest
Answered by
0
Answer:
#include<iostream>
int main()
{
int n=5, sum;
std::cin>>n;
for(int i =1; i <6; i++){
sum = sum + i;
}
std::cout<<sum;
}
Explanation
Similar questions
English,
4 months ago
India Languages,
9 months ago
Math,
9 months ago
Social Sciences,
1 year ago
Math,
1 year ago