The While and if statements Write an if statement that reduc

The While and if statements Write an if statement that reduces n by half n when n is positive Write an if statement that adds 1 to n when n is odd, otherwise it subtracts 1 from n Write a while statement that subtracts 5 from n so long as n is greater than 11. What will be the value of n afterwards if n is originally 37? What will be the value of n afterwards if n is originally 10? A C++ teacher wants to find how many students he has in his classroom. He did the following to discover the number: When he forms groups of 4, he is left with one group of 3 students When forming groups of 3, he is left with one group of 2 students Finally when forming groups of 5, no odd group is left. All groups have five students. Write a program to help the teacher find how many students in his classroom.

Solution

#include <iostream>
using namespace std;
int main() {
   /* if statement for n positive */
   int n = 10;
   if(n>0){
       n = n/2;
   }
   /* if else statemnt if m is odd or even */
   int m = 5;
   if(m%2==0){
       m = m-1;
   }
   else{
       m = m+1;
   }
  
   /* while statemnt when m is greater the 11 */
   int x = 10;
   while(x>11){
       x = x-5;
   }
  
   /* program to find the number of students */
   int y=1;
   while(true){
       if(y%4==3 && y%3==2 && y%5==0){
           break;
       }
       y++;
   }
  
    cout << y;
}

/* sample output

3.a

3.b 10

B. 35

*/

 The While and if statements Write an if statement that reduces n by half n when n is positive Write an if statement that adds 1 to n when n is odd, otherwise i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site