Page Rank Checker

Saturday 5 July 2014

Print All Prime Numbers Between 1 - 300 Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to print all prime numbers from 1 to 300.
      (Hint: Use nested loops, break and continue)

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int num=2,i;
    for(;num<=300;num++)
    {
        for(i=2;i<300;i++)
        {
            if(i==num)
                continue;
            if(num%i==0)
                break;
            if((num%i!=0) && i==299)
                printf(" %d ",num);
        }
    }
    getch();
}