Using a do while loop, write a program in C++ that can display all the odd numbers from 25 to 10 inclusively. The program should be able to display the sum of the numbers as well.
#include <iostream>
using namespace std;
int main()
{
int i=25;
int sum=0;
do{
if (i%2 !=0){
cout<<i<<endl;
sum=sum+i;
}
i--;
}
while(i>=10);
cout<<"\nSum: "<<sum;
return 0;
}
Comments
Leave a comment