Write a program to find the number and sum of all integers between 0 till 200 which are divisible by 9. Only a single do-while loop is required for this exercise.
SOLUTION TO THE ABOVE QUESTION
SOLUTION CODE
#include<iostream>
using namespace std;
int main()
{
//declare two variables one to store the number of integers and the pother
// to store the sum of the integers and initilaize the to 0
int number_of_integers = 0;
int sum_of_integers = 0;
int number = 1;
//lets code the do while loop
do
{
//check if the nummber is divisible by 9
if (number%9==0)
{
//increment the number of integers by 1
number_of_integers = number_of_integers + 1;
//increment the sum of the integers by the number
sum_of_integers = sum_of_integers + number;
}
//update the condition of the do while loop
number = number + 1;
}
while (number<=200);
cout<<"\nThe number of integers between 0 and 200 divisible by 9 are "<<number_of_integers<<endl;
cout<<"\nThe sum of integers between 0 and 200 divisible by 9 is "<<sum_of_integers<<endl;
return 0;
}
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment