Write a c++ program to calculate the sum of odd numbers from 5-20
Answers
Answered by
3
Answer:
This is the required C++ program for the question.
#include <iostream>
using namespace std;
int main() {
int s=0,i=5;
for(;i<=20;i+=2)
s+=i;
cout << "Sum is: " << s;
return 0;
}
Algorithm:
- START.
- Initialise s = 0.
- Iterate a loop in range i = 5 to 20.
- Add the value of i to s.
- Increment the value of i by 2.
- Display the value of s.
- STOP.
See the attachment for output ☑.
Attachments:
Similar questions