Tuesday, March 5, 2024

10. 0 7 26 ... 999

10. 0 7 26 ... 999

=(1³-1) (2³-1) (3³-1) ... (10³-1) :—


#include<stdio.h>

int main()

{

    int i,sum;

    sum=0;

    for(i=1;i<=10;i++)

    {

        sum=sum+i*i*i-1;

    }

    printf("%d",sum);

    return 0;

}


9. 0+3+8+...+99

     

9. 0+3+8+...+99

=(1²-1)+(2²-1)+(3²-1)+...+(10²-1) :—


#include<stdio.h>

int main()

{

    int i,sum;

    sum=0;

    for(i=1;i<=10;i++)

    {

        sum=sum+i*i-1;

    }

    printf("%d",sum);

    return 0;

}


8. 1²+2²+3²+4²+...+10² :—

8. 1²+2²+3²+4²+...+10² :—


#include<stdio.h>

int main()

{

    int i,sum;

    sum=0;

    for(i=1;i<=10;i++)

    {

        sum=sum+i*i;

    }

    printf("%d",sum);

    return 0;

}


7. 1+2+3+4+...+10 :—

7. 1+2+3+4+...+10 :—


#include<stdio.h>

int main()

{

    int i,sum;

    sum=0;

    for(i=1;i<=10;i++)

    {

        sum=sum+i;

    }

    printf("%d",sum);

    return 0;

}


6. Multiplication table of n by user :—


#include<stdio.h>

int main()

{

    int i,j,n;

    printf("enter value of n ");

    scanf("%d",&n);

    for(i=1,j=n;i<=10;i++)

    {

        printf("%d×%d=%d\n",i,j,i*j);

    }

    return 0;

}


5.Input a number from user and then print the factorial of the number :—

5.Input a number from user and then print the factorial of the number :—


#include<stdio.h>

int main()

{

    int i,j,n;

    printf("enter a number ");

    scanf("%d",&n);

    j=1;

    for(i=1;i<=n;i++)

    {

        j=j*i;

    }    

    printf("factorial of %d=%d\n",n,j);

    return 0;

}


4. Grade calculation :—


#include<stdio.h>

int main()

{

    int n;

    printf("enter value of 'n' ");

    scanf("%d",&n);

    if(n>=80)

    {

        printf("Greade A");

    }    

    else

    {

        if(n>=60)

        {

            printf("Grade B");

        }

        else

        {

            if(n>=40)

            {

                printf("Grade C");

            }

            else

            {

                printf("F");

            }

        }

    }

    return 0;

}


3. Input basic salary. Then find DA=50% of basic salary, HRA=30% of basic salary, PF=20% of basic salary, Medical=5% of basic salary, Gross Salary=Basic salary+DA+HRA-PF-Medical. If gross salary>40000, Bonus=5000, otherwise Bonus=6000.

3. Input basic salary. Then find DA=50% of basic salary, HRA=30% of basic salary, PF=20% of basic salary, Medical=5% of basic salary, Gross Salary=Basic salary+DA+HRA-PF-Medical. If gross salary>40000, Bonus=5000, otherwise Bonus=6000.


#include<stdio.h>

int main()

{

    int bs,da,hra,pf,md,b,gs;

    printf("enter basic salary ");

    scanf("%d",&bs);

    da=bs*50/100;

    hra=bs*30/100;

    pf=bs*20/100;

    md=bs*5/100;

    gs=bs+da+hra-pf-md;

    printf("gross salary=%d\n",gs);

    if(gs>40000)

    {

        gs=gs+5000;

    }

    else

    {

        gs=gs+6000;

    }

    printf("gross salary after bonus=%d",gs);

    return 0;

}


2. Input a year and check it is leap year or not :—

 


2. Input a year and check it is leap year or not :—


#include<stdio.h>

int main()

{

    int y;

    printf("enter a year ");

    scanf("%d",&y);

    if(y%4==0)

    {

        if(y%100==0)

        {

            if(y%400==0)

            {

                printf("%d is leap year",y);

            }

            else

            {

                printf("%d is not leap year",y);

            }

        }

        else

        {

            printf("%d is leap year",y);

        }

    }

    else

    {

        printf("%d is not leap year",y);

    }

    return 0;

}


1. Largest of 3 numbers using nested :—

 1. Largest of 3 numbers using nested :—


#include<stdio.h>

int main()

{

    int a,b,c;

    printf("enter 3 values ");

    scanf("%d%d%d",&a,&b,&c);

    if(a>=b)

    {

        if(a>=c)

        {

            printf("%d is the largest",a);

        }

        else

        {

            printf("%d is the largest",c);

        }

    }

    else

    {

        if(b>=c)

        {

            printf("%d is the largest",b);

        }

        else

        {

            printf("%d is the largest",c);

        }    

    }

    return 0;

}