Please write me a program to print the first 50 prime
numbers (NOT between the range 1 -50)
Answers were Sorted based on User's Feedback
Answer / antony
#include<stdio.h>
void main()
{
int count=0;
int num=1;
int i;
printf("prime nums \n");
while(count<50)
{
num++;
for (i=2;i<=num-1;i)
{
if(num%i==0)break;
i++;
}
if(i>=num-1)
{
printf("%d ",num);
count++;
}
}
}
Is This Answer Correct ? | 93 Yes | 47 No |
Answer / pirya
#include<stdio.h>
#include<conio.h>
void main()
{
int count==0,n=0,i=1,j=1;
clrscr();
while(n<50)
{
j=1;
count=0;
while(j<=1)
{
if(count%i==0)
count++;
j++;
}
if(count==2)
{
printf("%d ",i);
n++;
}
i++;
}
getch();
}
Is This Answer Correct ? | 13 Yes | 15 No |
Answer / ankurmohansharma
#include<stdio.h>
#include<conio.h>
main()
{
int loop_counter,count_prime=1,divisor;
clrscr();
loop_counter=51; //it will exclude all less then 50
while(count_prime!=50)
{
for(divisor=2;divisor<=loop_counter-1;divisor++)
{
if (loop_counter % divisor==0)
{ break;
}
}
if(loop_counter==divisor)
{
printf("\n%d",loop_counter);
count_prime++;
}
loop_counter++;
}
getch();
}
Is This Answer Correct ? | 8 Yes | 19 No |
Answer / sofi
#include <stdio.h>
#include <conio.h>
main()
{
int num,count_prime=1,divisor;
//clrscr();
num =1; //it will exclude all less then 50
while(count_prime!=50)
{
for(divisor=2;divisor<=num;divisor++)
{
if (num % divisor==0)
{ break;
}
}
if(num==divisor)
{
printf("\n%d",num);
count_prime++;
}
num++;
}
getch();
}
Is This Answer Correct ? | 10 Yes | 21 No |
Answer / azad sable, chiplun
void main()
{
int i,n=1;
clrscr();
printf("\nprime no. between 1 to50 are:\n1\t);
while(n<=50)
{
i=2;
while(i<n)
{
if(n%1==0)
break;
else
i++;
}
if(i==n)
printf("%d\t",n);
n++;
}
getch();
}
Is This Answer Correct ? | 20 Yes | 34 No |
An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above
What is a char in c?
Explain how can I read and write comma-delimited text?
WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management?
28 Answers 3D PLM, Code Studio, Deltech, IBM,
which do you prefer C or Pascal?
main() { printf("\n %d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); }
What is alloca() and why is its use discouraged?
How to write c functions that modify head pointer of a linked list?
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
Write a program which calculate sum of several number and input it into an array. Then, the sum of all the number in the array is calculated.
what do the 'c' and 'v' in argc and argv stand for?
Explain void pointer?