Translate

Thursday, April 30, 2020

C Program to swap two numbers without using third(temporary) variable.



    /*C Program to swap two numbers without third variable*/
    In C we have two techniques to swap the number
    1. Without using third variable
    2. Using third variable

    1. Without using third variable swap the number:


    #include<stdio.h>

    #include<conio.h>
    void main()
    {
        int a, b;
        printf("Enter First number in a = ");
        scanf("%d",&a);
        printf("Enter Second number in b = ");
        scanf("%d",&b);
        a= a+b;
        b=a-b;
        a=a-b;
        printf("\nafter swaping the value of a = %d", a);
        printf("\nafter swaping the value of b = %d", b);
        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:

    Saturday, April 25, 2020

    The else if ladder

    The else if ladder

    /*Control Statement: else if ladder*/


    • The else if Ladder Statement:
    This is a type of nesting in which there is an if...else statement in every else part except the last else part. This type nesting is called the else if Ladder Statement.

    The Syntax of else if Ladder:

    if(Condition 1)
           Statement A;
    else if(Condition 2)
             Statement B;
     else if(Condition 3)
                  Statement C;
      else if(Condition 4)
                    Statement C;
           else
                     Statement D;

    The Example of else if Ladder :

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
        float per;
      
        printf("Enter your percentage = ");
        scanf("%f",&per);
        if(per>=85)
        printf( "grade B");
        else if(per>=70)
        printf( "grade B");
        if(per>=55)
        printf( "grade ='C'");
        else if(per>=40)
        printf( "grade D");
        else
        printf("Fail");
        getch();
           
    }

    Output:





    The Nested if-else Statements :

    The Nested if-else Statement

    /*Control statement Nested if-else statement*/

    • The Nested if-else Statements :
    In C language, we can have another if..else statement in the if block or the else block. This is called nested if-else.

    The Syntax of Nested if-else:

    if(condition 1)
    {
        if(condition 2)
              statement A1;
           else
              statement A2;
    }
    else
    {
       if(condition 3)
              statement B1;
            else
              statement B2;
    }

    The Example of Nested if-else:


    #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:







         



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