Write a program to print prime nums from 1-20 using c
programing?

Answers were Sorted based on User's Feedback



Write a program to print prime nums from 1-20 using c programing?..

Answer / ankur mohan sharma

#include<stdio.h>
#include<conio.h>
int main()
{
int i,n;
for(n=2;n<=20;n++)
{
for(i=2;i<n;i++)
{if(n%i==0)
break;}
}
if(i==n)
printf("\n %d",n);
return 0;

}

Is This Answer Correct ?    2 Yes 5 No

Write a program to print prime nums from 1-20 using c programing?..

Answer / musa

#include <stdio.h>
main(){
printf("2 5 7 11 13 17 19");
}

Is This Answer Correct ?    10 Yes 14 No

Write a program to print prime nums from 1-20 using c programing?..

Answer / ricky dobriyal

/* hello i am ricky dobriyal software enginear*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,s;
printf("prime number 1 to 20 :\n");
for(i=1;i<=20;i++)
{
s=0;
for(j=2;j<i;j++)
{
if(i==1)
s=0;
else if(i%j==0)
s=1;
}
if(s==0)
printf("%d\t",i);
}
getch();
}

output:-1 2 3 4 7 11 13 17 19

Is This Answer Correct ?    18 Yes 27 No

Post New Answer

More C Interview Questions

to convert a string without using decrement operater and string functions

1 Answers  


Explain can you assign a different address to an array tag?

0 Answers  


how can I convert a string to a number?

0 Answers  


In C, What is the #line used for?

2 Answers  


a value that does not change during program execution a) variabe b) argument c) parameter d) none

0 Answers  






what are the advantage and disadvantage of recursion

5 Answers  


can we access one file to one directory?

1 Answers  


wap in c to accept n number display the highest and lowest value

2 Answers  


Convert a distance from miles to kilometers .there are 5280 feets per mile,12 inches per foot .2.54 centimeters per inch and 100000centimeters per kilometer

0 Answers   TCS,


#include <stdio.h> void main() { int i=-1,j=1,k,l; k=!i&&j; l=!i||j; printf ("%d%d",k,l) ; }

3 Answers   SRG,


Why c is a mother language?

0 Answers  


what would be the output of the following program main() { int a[] = {1,2,3,4,5}; int *ptr = {a,a+1,a+2,a+3,a+4}; printf("%d %d %d %d",a,*ptr,**ptr,ptr); } }

1 Answers  


Categories