Total Pageviews

Tuesday, March 5, 2024

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;

}


32.Sum of all factors :—

 32.Sum of all factors :—


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

        }

    }

    printf("%d",sum);

    return 0;

}


31.Prime number checking :—

31.Prime number checking :—


#include<stdio.h>

int main()

{

    int i,n,r,count;

    printf("enter a value of n ");

    scanf("%d",&n);

    count=0;

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

    {

        r=n%i;

        if(r==0)

        {

            count++;

        }

    }

    if(count==2)

    {

        printf("It is a prime number");

    }

    else

    {

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

    }

    return 0;

}


30.Count total number of factors :—

 30.Count total number of factors :—

#include<stdio.h>

int main()

{

    int i,n,r,count;

    printf("enter a value of n ");

    scanf("%d",&n);

    count=0;

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

    {

        r=n%i;

        if(r==0)

        {

            count++;

        }

    }

    printf("%d",count);

    return 0;

}

29. Print all factors of a number :—

29. Print all factors of a number :—


#include<stdio.h>

int main()

{

    int i,n,r;

    printf("enter a value of n ");

    scanf("%d",&n);

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

    {

        r=n%i;

        if(r==0)

        {

            printf("%d",i);

        }

    }

    return 0;

}


28. Armstrong number checking :—

 28. Armstrong number checking :—


#include<stdio.h>

int main()

{

    int i,n,m,k,r,sum;

    printf("enter value of n ");

    scanf("%d",&n);

    m=n;

    k=0;

    while(n>0)

    {

        n=n/10;

        k++;

    }

    n=m;

    sum=0;

    while(n>0)

    {

        r=n%10;

        n=n/10;

        sum=sum+pow(r,k);

    }

    if(sum==m)

    {

        printf("It is an Armstrong number");

    }

    else

    {

        printf("It is not an Armstrong number");

    }

    return 0;

}


27. Count the total number of digits :—

27. Count the total number of digits :—


#include<stdio.h>

int main()

{

    int i,n,count;

    printf("enter value of n ");

    scanf("%d",&n);

    count=0;

    while(n>0)

    {

        n=n/10;

        count++;

    }

    printf("%d",count);

    return 0;

}


26. Sum of digits :—

 26. Sum of digits :—


#include<stdio.h>

int main()

{

    int i,n,r,k,sum;

    printf("enter value of n ");

    scanf("%d",&n);

    sum=0,k=n;

    while(n>0)

    {

        r=n%10;

        n=n/10;

        sum=sum+r;

    }

    printf("%d",sum);

    return 0;

}


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

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


#include<stdio.h>

int main()

{

    int i,n,a,f,k,sum;

    printf("enter value of n and a ");

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

    sum=0,f=1;

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

    {

        k=2*i;

        sum=sum+pow(a,k)/(float)f;

        f=f*(k+1)*(k+2);

    }

    printf("%d",sum);

    return 0;

}


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

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


#include<stdio.h>

int main()

{

    int i,n,a,f,k,sum;

    printf("enter value of n and a ");

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

    sum=0,f=1;

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

    {

        k=2*i-1;

        sum=sum+pow(a,k)/(float)f;

        f=f*(k+1)*(k+2);

    }

    printf("%d",sum);

    return 0;

}