Translate

Wednesday, April 22, 2020

Check if the number is divisible by two..if-else program

* The if-else statement


 Q. Request the user to inputs an integer and, if the number is divisible by two, divides it by two, otherwise multiplies it by three and output the result.
Ans.
#include<stdio.h>
#include<conio.h>
  void main()
{
    int num;
    
    printf("enter the integer number in num = ");
    scanf("%d",& num);
    //check is the number is divisible by two
    if(num%2==0)
        { 
           num = num/2;
           printf("The number is divisible by 2 so divide it by 2 \n and after divided by 2 the result is = %d ", num );
        }
        else
        {
           num=num*3;
           printf("the number is not divisible by 2 so multiply it by 3 \n and after mulplied by 3 the result is = %d", num);
        }
        getch();
        
}

Output:
  • when user enter the number that is divisible by 2 then the output is....


  • when user enter the number that is not divisible by 2 then the
output is.....






No comments:

Post a Comment

C program to make a calculator using the switch statement.

/*perform arithmetic calculation on integers in C language*/ #include<stdio.h> #include<conio.h> void main() {     char op;     ...