Total Pageviews

956,999

Tuesday, March 5, 2024

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;

}


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

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


#include<stdio.h>

int main()

{

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

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

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

    sum=0,f=1,s=-1;

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

    {

        f=f*i;

        s=s*-1;

        sum=sum+pow(a,i)*s/(float)f;

    }

    printf("%d",sum);

    return 0;

}


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

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


#include<stdio.h>

int main()

{

    int i,n,a,f,sum;

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

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

    sum=0,f=1;

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

    {

        f=f*i;

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

    }

    printf("%d",sum);

    return 0;

}


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


#include<stdio.h>

int main()

{

    int i,n,a,sum;

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

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

    sum=0;

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

    {

        sum=sum+pow(a,i)/(float)i;

    }

    printf("%d",sum);

    return 0;

}


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

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


#include<stdio.h>

int main()

{

    int i,n,a,s,sum;

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

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

    sum=0,s=-1;

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

    {

        s=s*-1;

        sum=sum+pow(a,i)*s;

    }

    printf("%d",sum);

    return 0;

}


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

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


#include<stdio.h>

int main()

{

    int i,n,a,sum;

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

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

    sum=0;

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

    {

        sum=sum+pow(a,i);

    }

    printf("%d",sum);

    return 0;

}


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

 


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


#include<stdio.h>

int main()

{

    int i,f,n,s,sum;

    printf("enter a value of n ");

    scanf("%d",&n);

    sum=0,f=1,s=-1;

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

    {

        s=s*-1;

        f=f*i;

        sum=sum+f*s;

    }

    printf("%d",sum);

    return 0;

}


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

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


#include<stdio.h>

int main()

{

    int i,f,n,sum;

    printf("enter a value of n ");

    scanf("%d",&n);

    sum=0,f=1;

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

    {

        f=f*i;

        sum=sum+f;

    }

    printf("%d",sum);

    return 0;

}


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;

}