Translate

Showing posts with label if else-Programs. Show all posts
Showing posts with label if else-Programs. Show all posts

Tuesday, May 12, 2020

check whether a given number is even or odd? If the number is an even number, print it's square.


C program to check whether a given number is even or odd? if the number is even number, print it's square...

#include<stdio.h>
#include<conio.h>
void main()
{
    int num, squ;
    printf("enter number = ");
    scanf("%d",& num);
    if(num%2==0)
       { 
           printf("The number is Even");
           squ = num*num;
           printf("\nsquare of this even number is %d", squ);
       }
          
    else 
         printf("The number is Odd");
         
    getch();


}
Output:






Click Here for, All Important Questions with Answers
Click here for, C Programs


Friday, May 1, 2020

Program How to calculate Gross salary of employee

Calculate Gross Salary

Write a program to calculate gross salary of employee, basic salary is enter by the user, da is calculated on the basic of the following criteria.


bsal da
below 5000 10% of bsal
5000-10000 15% of bsal
10000-20000 20% of bsal
20000-above 40% of bsal

#include<stdio.h>
#include<conio.h>
void main()
{
    int bsal, da, gsal;
    printf("enter bsal = ");
    scanf("%d",& bsal);
    if(bsal<5000)
       da=(bsal*0.10);
    
    if((bsal>=5000)&&(bsal<10000))
       da=(bsal*0.15);
       
    if((bsal>=10000)&&(bsal<20000))
       da=(bsal*0.20);
       
    if(bsal>=20000)
       da=(bsal*0.40);
       
       gsal=bsal+da;
       printf("Gross salary of employee is= %d",gsal);
       getch();
       
}
Output:




Wednesday, April 29, 2020

Check eligibility

/*Program to check whether a person is eligible to vote or not */

* Control Statement - if else Statement

#include<stdio.h>

#include<conio.h>
void main()
{
    int age;
    printf("Enter Your Age? = ");
    scanf("%d",&age);
    if(age>=18)
      {
          printf("You are eligible to vote");
      }
    else
     {
          printf("You are not eligible to vote");
     }
     getch(); 
}
Output:




Tuesday, April 28, 2020

C Program to calculate gross salary of an employee

/* Enter Basic Salary and Calculate Gross Salary of employee */

#include<stdio.h>
#include<conio.h>
void main()
{
    float bs, gs, da, hra;
    printf("Enter Basic Salary = ");
    scanf("%f", &bs);
    if(bs<1500)
      {
          hra=bs*10/100;
          da=bs*90/100;
      }
      else
      {
          hra=500;
          da=bs*98/100;
      }
      gs=bs+hra+da;
      printf("Gross salary = Rs %f", gs);
      getch();
}
Output:





Sunday, April 26, 2020

C Program to find the Largest Number among three numbers

/* Print the Largest Number*/

#include<stdio.h>
#include<conio.h>
void main()
{
   int a, b, c;
 printf("enter value in a = ");
 scanf("%d",& a);
 printf("enter value in b = ");
 scanf("%d",& b);
 printf("enter value in c = ");
 scanf("%d",& c);

  if(a>b)
     {
         if(a>c)
              printf("\na is Largest %d", a);
           else
              printf("\nc is Largest %d", c);
     }
     else
     {
         if(b>c)
            printf("\nb is Largest %d",b);
           else
            printf("\nc is Largest %d",c);
     }
    getch();

}
Output:




C Program to find the smallest number among three number

#include<stdio.h>

#include<conio.h>
void main()
{
     int a, b, c;
     
    printf("enter value in a = ");
    scanf("%d",& a);
    printf("enter value in b = ");
    scanf("%d",& b);
    printf("enter value in c = ");
    scanf("%d",& c);
    
if(a<b)
     {
         if(a<c)
              printf("\na is smallest %d", a);
           else
              printf("\nc is smallest %d", c);
     }
     else
     {
         if(b<c)
              printf("\nb is smallest %d",b);
           else
              printf("\nc is smallest %d",c);
     }
    getch();

}

Output:

Thursday, April 23, 2020

C program to check even or odd

C program to Check Whether the Given Number is Even or Odd.

Even numbers are integers that are completely divisible by 2 and has no remainder. For example- 2, 4, 6, 8, 0
Odd numbers are not completely divisible by 2. either leaves a remainder or the result is a fraction. For example- 1, 3, 5, 7, 9.

Here is, Program to check Even or Odd.

#include<stdio.h>
#include<conio.h>
void main()
{
    int num;
    printf("enter number = ");
    scanf("%d",& num);
    if(num%2==0)
        printf("The number is Even");
    else
        printf("The number is Odd");
    getch();

}
Output:
When user enter the even number the output is..

When user enter the Odd number the output is.

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.....






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;     ...