Translate

Showing posts with label Simple Programs. Show all posts
Showing posts with label Simple 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:




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:




    Monday, April 20, 2020

    Request the user for two integers and print their remainder after division

    /*Print remainder after division*/



    #include<stdio.h>
    #include<conio.h>
     void main()
    {
      int x, y, remain,div;
    printf("Enter your first integer in x =");
    scanf("%d",&x);
    printf("Enter your second integer in y =");
    scanf("%d",&y);
    //division
    div=x/y;
    printf("division = %d",div);     
    //modulus
    remain=x%y;
    printf("\nremainder after division = %d",remain);
    getch();
    }
    Output:









    Useful Notes:

    • Division: The ‘/’ divide operator divides the first operand by the second. For example, div=x/y. Here, dividend is divided by the divisor.
    • Modulus: The ‘%’  modulus operator returns the remainder when first operand is
    • divided by the second. The modulus "%" operator give us remainder  For example, remain=x%y.

    Request the user for two integers and output them and their sum.

    Friday, April 17, 2020

    Calculation of simple interest

    /* Calculation of simple interest*/

    #include<stdio.h>
    #include<conio.h>
     void main()
    {
    int p, t;
    float r, si;
    clrscr();
    printf("enter principle amount");
    scanf("%d,& p);
    printf(enter the value of rate");
    scanf("%f,& r); 
    printf(enter time");
    scanf("%d,& r); 
    /*formula for simple interest*/
    si= p*t*r /100;
    printf("\n simple interest = Rs. %f", si);
    getch();
    }

    Useful  Notes & Tips

    1.)  The scanf() function can be written as-
    Scanf("control string" , address1, address2,.....);
     here you can see we are  using int and float type of variable to store the value. 
    In this program
      
    printf("enter principle amount");
    scanf("%d,& p);

    here, %d is used, which implies that one integer value should be entered as input. 
    the next one is

     printf(enter the value of rate");

     scanf("%f,& r); 

    in this statement %f is used, which means that a floating point number should be entered as input.

    2.) \n is an escape sequence provide special formatting control. and here, \n represents new line.

    3.) Simple interest is calculated by, 
    simple interest = Principle*Time*Rate/100;

    4.) getch() function is used to hold the screen until user gives any input or press any key.

    5.) clrscr() function is a predefined function in conio.h header file. it's used to clear the screen or you can say clear the previous data of previous running program.








    Request the user for two integer and print their sum.

    Sum of two numbers


    #include<stdio.h>
    #include<conio.h>
      void main()
    {
      int a, b, sum;

    /* Printf() outputs the values to the screen whereas scanf() receive them from the keyboard.
       and  &   is a address used in scanf(). */
     printf("enter  first no=");
      scanf("%d", & a);
      printf("enter second no=");
      scanf("%d", & b);
      sum= a+b;
      printf("Sum of two number is =%d",sum);
      getch();
    }
    Output:






     Useful Notes & Tips

     1.) semicolon(;) - end of statement  C statement must end with a semicolon because it's acts as an statement terminator.


    2.)  a, b, sum are variables. Here, you can use x/y/z because variable is just a name that can be store values.  it is an identifiers whose value vary during program execution. 


    3.)  & is a address used in scanf(). when we say &a or any variable name , we are telling the scanf() at which memory location  should it store the value supplied by the user from the keyboard.


     4.) main() is function. every C program must be contain one function that is called main() function because program execution always start with main().  

     

    5.) Comment about the program should be enclosed within /*  write your comment */
     

    6.) comment is not mandatory but it's indicating the purpose of the program so easy to understand by user or programmer.
     

    7.) you can write a comment at any place.

     8.) we can comment in small, capital, or special character. there is no any rules because comments are completely ignored by the compiler. 


    9.) stdio.h is a header file. it's stands for standard input output.  it contain printf() and scanf() function.


    10. conio stands for console input output. it is used for following functions: clrscr(), getch().

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