• Now Online : 29
  • admin@codemyne.net

Introduction

The program shows how to display prime numbers. Here two for loops are used.

#include<stdio.h>
#include<conio.h>
void main()
{
    int num,count,i,n;
    clrscr();
    printf("\n Enter a number:");
    scanf("%d",&n);
    printf("\n The prime numbers are:");
    for(num=2;num<=n;num++)
    {
        count=0;
        for(i=1;i<=num;i++)
        {
            if(num%i==0)
            count++;
        }
        if(count==2)
        printf("%d",num);
    }
    getch();
}

Comments/Suggestions are invited. Happy coding......!

Comments Post a Comment