
- Forum
- Programming Talk
- C and C++
- Print Prime numbers
Print Prime numbers
This is a discussion on Print Prime numbers within the C and C++ forums, part of the Programming Talk category; HI, Want help in writing a program in C. :Print first 25 prime numbers....
-
Print Prime numbers
HI,
Want help in writing a program in C. :Print first 25 prime numbers.
-
here is the answer
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int a,c=0;
printf(" First fifteen prime numbers\n");
printf("2 \n3\n5\n7\n");
for (a=8;a<99;a++)
{if ((a%2!=0)&&(a%3!=0)&&(a%5!=0)&&(a%7!=0))
printf("%d\n",a);
}
system ("PAUSE");
return 0;
}
-
02-24-2012, 07:17 AM #3
- Join Date
- Feb 2012
- Answers
- 66
‡include<stdio.h>
main()
{
int ct=0,n=0,i=1,j=1;
while(n<25)
{
j=1;
ct=0;
while(j<=i)
{
if(i%j==0)
ct++;
j++;
}
if(ct==2)
{
printf("%d ",i);
n++;
}
i++;
}
getch();
}
-
Prime nos upto 25
[By Brajraj]
#include<iostream.h>
#include<conio.h>
main()
{
int num=25,prime;
for(int i=2;i<=num;i++)
{ prime=0;
for(int j=2;j<=i/2;j++)
{
if((i%j)==0)
{
prime=1;
break;
}
}
if(prime==0)
{
cout<<i<<endl;
}
prime=0;
}
getch();
}
-
C/C++ with informic DB, Please help
-
Sponsored Ads
«
Scope of a variable in a program to calculate average
|
Help pls !! Array or Strucure ??? which is best??
»

Reply With Quote






