c program to find and count the prime number upto given number ?
>> Friday, October 28, 2011
This program find the Prime number upto the number you desire and will also count the number of prime numbers. This program uses goto Statement which is very infrequently used but sometime desired at some places and so as here. So in this program will we also learn to use goto statement. Below is the program with its output, with prime number upto 100.
Have a look on it :
#include<stdio.h>
#include<conio.h>
int main()
{
int n=2, count=0; //count variable store the number of prime number
int i, m;
printf("enter the number upto which you want to find prime numbers : ");
scanf("%d",&m);
printf("prime numbers are : ");
while(n<m)
{
for(i=2; i<n; i++)
{
if(n%i==0)
goto t; // goto is referring to line or code 't'
}
printf("\t%d ", n);
count++;
t : n++; //when goto is executed it will directly jump to this statement
}
printf("\n\nNumber of prime numbers are %d",count);
getch();
}
Here is the output :
0 comments:
Post a Comment