Question:

Write a C Program to check Prime number using C Programming Language.(For Loop)

by  |  earlier

0 LIKES UnLike

You have to accept a number from the user and check whether its a prime number or not. Or you can also calculate the number of Prime numbers between 1 to 100

 Tags:

   Report

21 ANSWERS


  1. #include<conio.h>

    main()

    {

    int n;

    int i,j,s=0;

    printf(" enter the upper limit from the set of even number ");

    scanf("%d",&n);

    {

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




    {

    for(j=2;j<=i/2;j++)

    {

    if(i%j==0)

    {


    break;

    }}


    if(i%j!=0)

    {

    s=s+i;




    }

    }

    printf("suum of the prime number is=%d",s);

    }

    }


    prime and their sum

     


  2. Write a program that calculates the sum of the digits of an integer. For example,

    the sum of the digits of the number 2155 is 2 + 1 + 5 + 5 or 13.The program

    should accept any arbitrary integer typed in by the user.


  3. write a program that print the prime numbers between 1 and 100?


  4. voidmain()


    {


    int i,n;


    printf("enter the number to be checked");


    scanf("%d",&n);


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


    {


    if(n%i==0)


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


    }


    else


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


    getch();


    }


  5. /*Write a program to find the prime numbers and perfect numbers between 1 to 100 and

    also find how many prime numbers are there */


    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int i,j,k,m,l,s,t;

    clrscr();

    m=0;

    printf("\nThe prime numers are=\n");

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

    {

    k=0;

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

    {

    if(i%j==0)

    {

    k++;

    }

    }

    if(k==2)

    {

    printf(",%d",i);

    m++;

    }

    }

    printf("\n\nThe number of prime numbers are=%d",m);

    printf("\nthe perfect numbers are=");

    for(l=1;l<=32765;l++)

    {

    s=0;

    for(t=1;t<l;t++)

    {

    if(l%t==0)

    {

    s=s+t;

    }

    }

    if(l==s)

    {

    printf(",%d",s);

    }

    }

    getch();

    }


    Antareen.


  6. polidrome number


  7. #include<stdio.h>

    #include<conio.h>

    void main()

    { i

    nt n,i,p=1;

    clrscr(); printf("enter a number\n");

    scanf("%d",&n);

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

    {

    if(n%2==0)  

    p=0;

    break;

    }

    }

    if(p==1)

    {

    printf("prime number");

    }

    else

    {

    printf("not a prime number");

    }

    getch();


  8.  #include <stdio.h>


    void main()

    {

    int i,j,n=100,count=0;

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

    {

    for (j=2;j<n/2 ;j++ )

    {

    if (i%j == 0)

    {

    count++;

    }

    }

    if (count>1)

    {

    count=0;

    }

    else printf("\n %d",i);

    }



    }


  9. #include<stdio.h>


    void main ()


    {


     int n,i;


    printf("enter any no.");


    for("i=2 ,i < n, i++")


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


    if (n%i==0)


    printf("no.is composite")


    else


    printf("no is prime")


    }


    }


  10. #include<conio.h>


    #include<stdio.h>


    void main()


    {


    int n,i;


    clrscr();


    printf("Enter the number to be checked");


    scanf("%d",&n);


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


    {


    if(n%i==0)


    {


    printf("the number is not prime");


    break;


    }


    else


    {


    printf("the number is prime");


    break;


    }


    }

    }


  11. #include<stdio.h>


    #include<conio.h>


    void main()


    {      


         int i;


    if(i%2==0)


    {


        printf("The Entered Numbred is Prime");


    else


           printf("The Entered Number is Not Prime");


    }


    /*Programm by rana.................*/


  12. #include<stdio.h>
    #include<conio.h>
    void main 90
    {
    int n,a=0,i;
    printf("\n Enter the number \n");
    scanf("%d"& n);
    for(i=1;i<=n; i++)
    {
    if(n% i==0)
    a++
    }
    if(a==2)
    printf("\n %d is a prime number",n);
    else
    printf("\n %d is not a prime number',N0;
    getch();
    }

  13. #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int i,n,c=0;
    printf("enter the number to be checked\n");
    scanf("%d",&n);
    for(i=2;i<=n-2;i++)
    {
    if(n%i==0)
    c++;
    }
    if(c==1)
    printf("prime number");
    else
    printf("noooooooo");
    getch();
    }

  14. #include<stdio.h>

    void main()
    {
    int a,c=0,i,n;
    clrscr();

            for(i=1;i<=n;i++)
    {
       a=n%i;
       if(a==0)
        {
          c = c + 1;
        }
    }

    if (c==2)
    {
       printf("\n   %d is the Prime Number",n);
    }
    else
    {
       printf("\n   %d is not Prime Number",n);
    }
            getch();
    }

  15. #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int a,i,c=0;
    clrscr();
    printf("Enter number=");
    scanf("%d",&a);
    for(i=2;i<a;i++)
    {
      if(a%i==0)
      {
       c=c++;
       break;
      }
    }
    if(c>=1)
    printf("%d is not Prime",a);
    else
    printf("%d is prime",a);

    getch();
    }

  16. void main()
    {
        int i=2;
        int count=0;
        int n;
        printf("enter a no");
        scanf("%d",&n);
        for(i=2;i<=ceil(sqrt(n));i++)
        {
            if(n%i==0)
            {
                count++;
                break;
            }
        }
        if(count>=1)
            prinf("prime");
        else
            printf("not prime");
    }

  17. Most simple program


    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int n,a,c=0;
    clrscr();
    printf("Enter number to be checked\n");
    scanf("%d",&n);
    for(a=2;a<n;a++)
    {
    if(n%a==0)
    c++;
    }
    if(c>0)
    printf("Not a prime number\n");
    else printf("Prime number\n");
    getch();
    }

  18. #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int i,a=1,n;
    clrscr();
    do
    {
    printf("ENTER THE NUMBER/to end enter 0:\n");
    scanf("%d",&n);
    for(i=2;i<n;i++)
    {
    if(n%i==0)
    {
    a=0;
    printf("NOT A PRIME NO\n");
    break;
    }
    }
    if(a==1)
    printf("PRIME NO\n");
    a=1;
    }while(n>0);
    getch();
    }

  19. you what.

  20. #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int n,i,p=1;
    clrscr();
    printf("enter a number\n");
    scanf("%d",&n);
    for(i=2;i<=n;i++)
    {
    if(n%2==0)
    {
    p=0;
    break;
    }
    }
    if(p==1)
    {
    printf("prime number");
    }
    else
    {
    printf("not a prime number");
    }
    getch();
    }

  21. main()
    {
    int i,j=2,ch=0;
    clrscr();
           printf("\nENTER ANY NUMBER");
           scanf("%d",&i);
      while(j<=i/2)
           {
            if(i%j==0)
              {
                printf("%d IS NOT PRIME",i);
                ch=1;
                break;
              }
            else
              {
               j++;
              }
          }
    if(ch==0)
       {
       printf("%d IS PRIME",i);
       }
    }

Question Stats

Latest activity: earlier.
This question has 21 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions