Write a Program to print Prime Numbers between 1 to 100

#include <stdio.h>
#include <conio.h>
void main()
{
  int a[100],i,j=2;
  clrscr();
  for(i=0;i<100;i++)
   a[i]=i+1;
printf("Prime Number between 1 to 100 \n");
  for(i=0;i<100;i++)
   {
    for(j=2;a[i]>j;j++)
      {
     if(a[i]%j==0)
     break;
      }
     if(a[i]==j || a[i]==1)
       printf("%d\t",a[i]);
    }
getch();
}

17 comments:

  1. thanks for post this it is great

    ReplyDelete
  2. thx ya..
    helped complete ma assignment.(chuckle
    :P)

    ReplyDelete
  3. #include

    int isPrime(int);

    int main()
    {
    int num,prime;

    printf("Enter range : ");
    scanf("%d",&num);

    for(int i=2; i<num; i++)
    {
    prime = isPrime(i);

    if(prime == 1)
    {
    printf("%d ",i);
    }
    }

    return 0;
    }

    int isPrime(int num)
    {
    int i=2;
    while(i <= num-1)
    {
    if(num%i ==0)
    {
    return 0;
    }
    i++;
    }
    if(i == num)

    return 1;


    return 1;
    }

    ReplyDelete
  4. #include
    #include
    void main()
    {
    int c,d=0,e=0,i,j;
    for(i=1;i<=100;i++)
    {

    j=(i/2);

    for(j;j>1;j--)
    {
    c=i%j;
    if(c==0)
    {
    d++;
    break;


    }
    else
    {

    }
    }

    if(d==0)
    {
    e++;
    printf("\n%d", i);
    }
    d=0;

    }
    printf("\n\ntotal %d prime no.s\n\n", e);



    }

    ReplyDelete
  5. #include
    void main()
    {
    int i,j,num;
    printf("enter a number");
    scanf("%d",&num);
    for(i=2;i<num;i++)
    {
    if(num%i==0){
    printf("not a prime number");
    }else{
    printf("prime number");
    }break;




    }


    }

    i think this one is easier than others!! thanks

    ReplyDelete
  6. Good
    Here is a link for C/C++ programs and pointer programs. This may be useful for you.

    C Programs

    C++ Programs

    ReplyDelete
  7. A prime number is a whole number greater than 1, which is only divisible by 1 and itself. First few prime numbers are : 2 3 5 7 11 13 17 19 23
    2 is the only even Prime number. Prime number program in C++. Every prime number can represented in form of 6n+1 or 6n-1, where n is natural number. 2, 3 are only two consecutive natural numbers which are prime too.

    ReplyDelete
  8. I want to buy your blog call me 8076671483

    hitesh.xc@gmail.com

    ReplyDelete

Related Post

Array:
String functions:
General (Loops-for/while)
Write a Program to print reverse of a given number Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number Write a C++ Program to Convert Binary into Decimal Number