Search This Blog

Print all prime numbers from 1 to 1000 | c programming

 Print all prime numbers from 1 to 1000






 Problem

 Print all prime numbers from 1 to 1000



 Solution

 We have to make a program same as checking prime number. Just have to create an extra loop to input numbers from 1 to 1000.


#include<stdio.h>

int main()
{
    int i,N,flag;


    for(N=2;N<=1000;N++){
            flag = 0;
        for(i=2;i<=N/2;i++){
                if(N%i == 0){
                    flag = 1; ///not prime
                    break;
                }

        }
        if(flag == 0){
            printf("%d\n",N);
        }
    }


    return 0;
}

No comments

Powered by Blogger.