Write a program to print the prime numbers from 1 to 100?

Answers were Sorted based on User's Feedback



Write a program to print the prime numbers from 1 to 100?..

Answer / prth

#include<stdio.h>
#include<conio.h>
void main()
{
int flag,x;
clrscr();
printf("1\t");
for(int i=1;i<=100;i++)
{
flag=0;
for(x=2;x<=i;x++)
{
if(i%x==0)
{
flag=1;
break;
}
else
continue;
}
if(i==x)
printf("%d\t",i);
}
getch();
}

Is This Answer Correct ?    48 Yes 11 No

Write a program to print the prime numbers from 1 to 100?..

Answer / m santhosh

int count=0;
int number=100; //// print Prime no's from 1 to 100
for(int i=1;i<=number;i++)
{
count=0;
for(int j=1;j<=i;j++)
{
if((i%j==0))
{
count++;
}

}
if(count<=2)
{
printf("\nPrime Number = %d",i);

}

}

Is This Answer Correct ?    14 Yes 9 No

Write a program to print the prime numbers from 1 to 100?..

Answer / tirth raj

#include<stdio.h>
#include<conio.h>
void main()
{
int num,div;
clrscr();
printf("First two prime no.1&2");
for(num=3;num<=100;num++)
{
div=2;
while(div<=num-1)
{
if(num%div==0)
{
break;
}
else
{
div++;
}
}
if(div==num)

printf("\nPrime Number = %d",num);
}
getch();
}

Is This Answer Correct ?    6 Yes 6 No

Write a program to print the prime numbers from 1 to 100?..

Answer / nikith

#include<stdio.h>
#include<conio.h>
int main()
{
int num,n,div,p;
printf("Enter any number: ");
scanf("%d", &num);
for(n=2; n<=num; n++)
{
for(div=2; div<n; div++)
{
if(n%div==0)
{
p=0;
break;
}
p=1;
}
if(p)
printf("\t%d",n);
}
getch();
return 0;
}

Is This Answer Correct ?    8 Yes 8 No

Write a program to print the prime numbers from 1 to 100?..

Answer / aravind

#include<stdio.h?
int main()
{
int i,count=0;
for(i=1;i<=100;i++)
{
a=i%10;
if(a==0)
{
count++;
if(count<=2)
printf("the prime numbers are %d",i);
}
else
count=count;
}

the above answer is good but it will not print 1 as prime.

Is This Answer Correct ?    14 Yes 23 No

Write a program to print the prime numbers from 1 to 100?..

Answer / deva

int main()
{
int i,j,count=0;

for(i=2;i<100;i++)
{

for( j=2;j<i;j++)
{
if(i%j==0)
count++;

}
if (count==0)
printf("%d\t",i);
count=0;
}

}

Is This Answer Correct ?    22 Yes 37 No

Write a program to print the prime numbers from 1 to 100?..

Answer / dash

#include<stdio.h>
#include<conio.h>

void main()
{
int number,i;
clrscr();

for(i=1;i<=100;i++)
{
if(i%2==0)
{
printf("\n\n not prime number\t%d",i);
}
else

printf("\n\n prime number\t%d",i);
}
getch();
}

Is This Answer Correct ?    31 Yes 86 No

Post New Answer

More C Interview Questions

What is the purpose of clrscr () printf () and getch ()?

0 Answers  


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers   Mind Tree,


main() {char a[10]={1,2,3,4,5,6};int x; for(x=0;x<4;x++){ b[x]=x+'a';} printf("%s",b);}

3 Answers  


f(x,y,z) { y = y+1; z = z+x; } main() { int a,b; a = 2 b = 2; f(a+b,a,a); print a; } what is the value of 'a' printed

5 Answers  


How to convert decimal to binary in C using recursion??

4 Answers   HP, IBM,






What is the c language function prototype?

0 Answers  


given post order,in order construct the corresponding binary tree

0 Answers   S-Cube, Wipro,


Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.

0 Answers  


What is c method?

0 Answers  


a=5 a=a++/++a

14 Answers   Bhel,


Why header files are used?

0 Answers  


Write a program to accept a character & display its corrosponding ASCII value & vice versa?

9 Answers  


Categories