Tuesday, March 5, 2024

C program practice set:






15.Sum of digits :—CLICK

16.

17. 1!+2!+3!+...n :—CLICK

18.1!-2!+3!-4!+...n :—CLICK

19. a+a²+a³+a⁴+a⁵... :—CLICK

20. a-a²+a³-a⁴... :—CLICK

21. (a/1)+(a²/2)+(a³/3)+(a⁴/4)+... :—

22. (a/1!)+(a²/2!)+(a³/3!)+(a⁴/4!)+... :—CLICK

23.a-(a²/2!)+(a³/3!)-(a⁴/4!)... :—CLICK

24. a+(a³/3!)+(a⁵/5!)+... :—CLICK

25. (a²/2!)+(a⁴/4!)+(a⁶/6!)+... :—CLICK

26. Sum of digits :—CLICK

27. 

28. Armstrong number checking :—CLICK

29. Print all factors of a number :—CLICK

30.Count total number of factors :—CLICK

31.Prime number checking :—CLICK

32.Sum of all factors :—CLICK

33. Perfect number checking :—  CLICK

34. Count total numbers of 0 in a number :—CLICK

35. Sum of all odd digits :—CLICK

36. Sum of all odd position and even position digits :—CLICK

37. Decimal to Binary :—CLICK

38. Binary to Decimal :—CLICK

39. Decimal to Octal :—CLICK

40. Octal to Decimal :—CLICK

41. Sum an average of n numbers :—CLICK

42. Program of a^b :—CLICK HERE

43. Input a number and check it is divisible by 3 or not :—CLICK

44. Input a number and check it is divisible by 3 or divisible by 5 or divisible by both or divisible by none :— CLICK

45. Input a salary and increament 10% salary :— CLICK


46. Pattern  

“11111

  22222

  33333

  44444”


 46. Print :

“11111

  22222

  33333

  44444”


#include<stdio.h>

int main()

{

    int i,j;

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

    {

        for(j=1;j<=5;j++)

        {

            printf("%d",i);

        }

        printf("\n");

    }

    return 0;

}


45. Input a salary and increament 10% salary :—

 45. Input a salary and increament 10% salary :—


#include<stdio.h>

int main()

{

    int s,i,us;

    printf("enter a salary ");

    scanf("%d",&s);

    i=s*10/100;

    us=s+i;

    printf("Updated salary=%d",us);

    return 0;

}


44. Input a number and check it is divisible by 3 or divisible by 5 or divisible by both or divisible by none :—

 44. Input a number and check it is divisible by 3 or divisible by 5 or divisible by both or divisible by none :—


#include<stdio.h>

int main()

{

    int a;

    printf("enter a value of n ");

    scanf("%d",&a);

    if(a%3==0)

    {

        if(a%5==0)

        {

            printf("%d is divisible by both",a);

        }

        else

        {

            printf("%d is divisible by 3 only",a);

        }

    }

    else

    {

        if(a%5==0)

        {

            printf("%d is divisible by 5 only",a);

        }

        else

        {

            printf("%d is divisible by none of 5 and 3",a);

        }

    }

    return 0;

}


43. Input a number and check it is divisible by 3 or not :—

43. Input a number and check it is divisible by 3 or not :—


#include<stdio.h>

int main()

{

    int n;

    printf("enter a value of n ");

    scanf("%d",&n);

    if(n%3==0)

    {

        printf("divisible by 3");

    }

    else

    {

        printf("not divisible by 3");

    }

    return 0;

}


42. Program of a^b :—

 


42. Program of a^b :—


#include<stdio.h>

int main()

{

    int a,b,f,i;

    printf("enter a value and a power ");

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

    f=1;

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

    {

        f=f*a;

    }

    printf("%d",f);

    return 0;

}


41. Sum an average of n numbers :—

 41. Sum an average of n numbers :—


#include<stdio.h>

int main()

{

    int i,sum,n,k,m;

    printf("enter a value of n ");

    scanf("%d",&n);

    sum=0;

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

    {

        printf("enter a value ");

        scanf("%d",&m);

        sum=sum+m;

    }

    k=sum/n;

    printf("%d    %d",sum,k);

    return 0;

}


40. Octal to Decimal :—

 40. Octal to Decimal :—


#include<stdio.h>

int main()

{

    int i,sum,n,r;

    printf("enter a value of n ");

    scanf("%d",&n);

    i=1;

    sum=0;

    while(n>0)

    {

        r=n%10;

        sum=sum+i*r;

        n=n/10;

        i=i*8;

    }

    printf("%d",sum);

    return 0;

}


39. Decimal to Octal :—

39. Decimal to Octal :—


#include<stdio.h>

int main()

{

    int i,sum,n,r;

    printf("enter a value of n ");

    scanf("%d",&n);

    i=1;

    sum=0;

    while(n>0)

    {

        r=n%8;

        sum=sum+i*r;

        n=n/8;

        i=i*10;

    }

    printf("%d",sum);

    return 0;

}


38. Binary to Decimal :—

 38. Binary to Decimal :—


#include<stdio.h>

int main()

{

    int i,sum,n,r;

    printf("enter a value of n ");

    scanf("%d",&n);

    i=1;

    sum=0;

    while(n>0)

    {

        r=n%10;

        sum=sum+i*r;

        n=n/10;

        i=i*2;

    }

    printf("%d",sum);

    return 0;

}


37. Decimal to Binary :—

37. Decimal to Binary :—


#include<stdio.h>

int main()

{

    int i,sum,n,r;

    printf("enter a value of n ");

    scanf("%d",&n);

    i=1;

    sum=0;

    while(n>0)

    {

        r=n%2;

        sum=sum+i*r;

        n=n/2;

        i=i*10;

    }

    printf("%d",sum);

    return 0;

}


36. Sum of all odd position and even position digits :—

 36. Sum of all odd position and even position digits :—


#include<stdio.h>

int main()

{

    int i,sumo,sume,n,r;

    i=0,sumo=0,sume=0;

    printf("enter a value of n ");

    scanf("%d",&n);

    while(n>0)

    {

        r=n%10;

        if(i%2==0)

        {

            sume=sume+r;

            printf("sum of even positions=%d\n",sume);

        }

        else

        {

            sumo=sumo+r;

            printf("sum of odd positions=%d\n",sumo);

        }

        n=n/10;

        i++;

    }

    return 0;

}


35. Sum of all odd digits :—

35. Sum of all odd digits :—


#include<stdio.h>

int main()

{

    int sum,n,r;

    sum=0;

    printf("enter a value of n ");

    scanf("%d",&n);

    while(n>0)

    {

        r=n%10;

        if(r%2!=0)

        {

            sum=sum+r;

        }

        n=n/10;

    }

    printf("%d",sum);

    return 0;

}


34. Count total numbers of 0 in a number :—

34. Count total numbers of 0 in a number :—


#include<stdio.h>

int main()

{

    int count,n,r;

    count=0;

    printf("enter a value of n ");

    scanf("%d",&n);

    while(n>0)

    {

        r=n%10;

        if(r==0)

        {

            count++;

        }

        n=n/10;

    }

    printf("%d",count);

    return 0;

}


33. Perfect number checking :—

33. Perfect number checking :—


#include<stdio.h>

int main()

{

    int i,n,r,sum;

    printf("enter a value of n ");

    scanf("%d",&n);

    sum=0;

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

    {

        r=n%i;

        if(r==0)

        {

            sum=sum+i;

        }

    }

    if(sum==n)

    {

        printf("It is a perfect number");

    }

    else

    {

        printf("It is not a perfect number");

    }

    return 0;

}