Answer to Question #265827 in C++ for Urooj

Question #265827

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. 


1
Expert's answer
2021-11-14T09:21:51-0500


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







Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS