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

Differentiate fundamental data types and derived data types in C.

0 Answers   HCL,


what is a pointer

4 Answers   Bank Of America, TCS,


Can we use visual studio for c?

0 Answers  


Explain argument and its types.

0 Answers  


How can you draw circles in C?

0 Answers   Accenture,


1. Write a C program to count the number of occurrence of a specific word in the given strings. (for e.g. Find how many times the word “live” comes in the sentence “Dream as if you’ll live forever, live as if you’ll die today ”)

12 Answers   Eskom, TCS,


N O S I E R + A S T R A L ---------------- 7 2 5 6 1 3

3 Answers   Honeywell,


What is gets() function?

0 Answers  


can u give me the good and very optimised code for a car racing game?

0 Answers  


main is a predefined or user define function if user defined why? if predefined whay?

12 Answers   TCS,


What is the right way to use errno?

0 Answers  


What is the -> in c?

0 Answers  


Categories