Total Pageviews

956,996

Tuesday, March 5, 2024

16. Input a number and check it is palindrome or not :—


16. Input a number and check it is palindrome or not :—


#include<stdio.h>

int main()

{

    int r,n,k,rev;

    printf("enter a number ");

    scanf("%d",&n);

    k=n;

    rev=0;

    while(k>0)

    {

        r=k%10;

        k=k/10;

        rev=rev*10+r;

    }

    if(n==rev)

    {

        printf("%d is a palindrome",n);

    }

    else

    {

        printf("%d is not a palindrome",n);

    }

    return 0;

}


15. Sum of digits :—

15. Sum of digits :—


#include<stdio.h>

int main()

{

    int r,n,sum;

    printf("enter a value of n ");

    scanf("%d",&n);

    sum=0;

    while(n>0)

    {

        r=n%10;

        sum=sum+r;

        n=n/10;

    }

    printf("%d",sum);

    return 0;

}


14. Print the digit in reverse :—

14. Print the digit in reverse :—


#include<stdio.h>

int main()

{

    int r,n;

    printf("enter a value of n ");

    scanf("%d",&n);

    while(n>0)

    {

        r=n%10;

        printf("%d",r);

        n=n/10;

    }

    return 0;

}


13.Print : 10 9 8 7 ... 1 :—

 

13.Print : 10 9 8 7 ... 1 :—


#include<stdio.h>

int main()

{

    int i;

    for(i=10;i>=1;i--)

    {

        printf("%d ",i);

    }

    return 0;

}


12. Print : 0 10 20 30 ... 100 :—

 


12. Print : 0 10 20 30 ... 100 :—


#include<stdio.h>

int main()

{

    int i;

    for(i=0;i<=100;i+=10)

    {

        printf("%d ",i);

    }

    return 0;

}


11. 100+95+90+...+0 :—

 11. 100+95+90+...+0 :—


#include<stdio.h>

int main()

{

    int i,sum;

    sum=0;

    for(i=100;i>=0;i-=5)

    {

        sum=sum+i;

    }

    printf("%d",sum);

    return 0;

}


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;

}


Saturday, February 24, 2024

17. Given two ordered arrays of integers, write a program to merge the two-arrays to get an ordered array.

 #include <stdio.h>

int main()

{

    int n1,n2,n3;            

    int a[20], b[20], c[40];

    printf("Enter the size of first array: ");

    scanf("%d",&n1);

    printf("Enter the array elements: ");

    for(int i = 0; i < n1; i++)      

       scanf("%d", &a[i]);

    printf("Enter the size of second array: ");

    scanf("%d",&n2);

    printf("Enter the array elements: ");

    for(int i = 0; i < n2; i++)      

       scanf("%d", &b[i]);

    n3 = n1 + n2;

    int i = 0, j = 0, k = 0;


    while (i < n1 && j < n2)    

    {

        if (a[i] < b[j])

            c[k++] = a[i++];    

        else

            c[k++] = b[j++];

    }

  

    while (i < n1)    

        c[k++] = a[i++];

  

    while (j < n2)    

        c[k++] = b[j++];

    

    printf("Final array after merging: ");

    for(int i = 0; i < n3 ; i++)       

        printf(" %d ",c[i]);

    return 0;   

}