Programs of C Language


 /*Ex-1 Program to Add 2 Numbers.*/

main()
{
    int a,b,c;        //Declaration of Variable with Data Type.
    scanf("%d",&a);   // For Take Input from user.
    scanf("%d",&b);
    c=a+b;
    printf("%d",c);      // For Display Output of Program on Screen.
    getch();        //getch() function is used for display output on screen.
}


 /*Ex-2 Program to Find Average of 3 Numbers.*/

main()
{
    int a,b,c;
    float d;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    d=(a+b+c)/3;
    printf("%f",d);
    getch();
}


 /*Ex-3 Program to Find Area of Circle.*/

main()
{
    int r;
    float a;
    scanf("%d",&r);
    a=3.14*r*r;
    printf("%f",a);
    getch();
}


/*Ex-4 Program to Find Area of Rectangle.*/

main()
{
    int l,h,area;
    scanf("%d",&l);
    scanf("%d",&h);
    area=l*h;
    printf("%d",area);
    getch();
}


/*Ex-5 Program to Find Area of Square.*/

main()
{
    int l,area;
    scanf("%d",&l);
    area=l*l;
    printf("%d",area);
    getch();
}


/*Ex-6 Program to Find Volume of Cube.*/


main()
{
    int l,vol;
    scanf("%d",&l);
    vol=l*l*l;
    printf("%d",vol);
    getch();
}

/*Ex-7 Program to Find Simple Interest.{Interactive Prgrm}*/
main()
{
    int p,n;
    float r,si;
    printf("Enter the Principle Amount:");
    scanf("%d",&p);
    printf("Enter the Number of Years:");
    scanf("%d",&n);
    printf("Enter the Rate of Interest:");
    scanf("%f",&r);
    si=(p*r*n)/100;
    printf("Your Simple Interest is %f",si);
    getch();
}

/*Ex-8 Program to Find Simple Interest, where r=?
                                                          if               n<3=6%
                                                         n>=3 and n<5 =7%
                                                                         n>=5=9%
(Using if..........else statement)     */

main()
{
    int p,n;
    float r,si;
    printf("Enter the Principle Amount:");
    scanf("%d",&p);
    printf("Enter the Number of Years:");
    scanf("%d",&n);
    if(n<3)
        r=6.0;
    else if(n<5)
        r=7.0;
           else
        r=9.0;
    si=(p*r*n)/100;
    printf("Your Simple Interest is %f",si);
    getch();
}

Make a free website with Yola