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

What is wild pointer in c?

0 Answers  


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

5 Answers   ABS, Accenture, HCL, Infosys, Infotech, SoftSolve, Software India, TCS, Vertex, Vimukti Technologies,


What is the difference between #include and #include 'file' ?

0 Answers  


give an example of type casting by a simple c program

2 Answers   TCS,


c program to compute Income tax and Net Salary for its employees. The company offers tax relief of Kshs. 650 for single employees and Kshs. 1,100 for married employees. The relief will be deducted from the Gross salary, to give the taxable income. This will be computed at the following rates: [10mks] Taxable Income Rate (%) <5000 0 5000-19999 6 20000-36999 9 37000 and above 16

1 Answers  






Difference between fopen() and open()?

3 Answers   Aricent,


How can I implement opaque (abstract) data types in C? What's the difference between these two declarations? struct x1 { ... }; typedef struct { ... } x2;

2 Answers  


I have an array of 100 elements, each of which is a random integer. I want to know which of the elements: a) are multiples of 2 b) are multiples of 2 AND 5 c) have a remainder of 3 when divided by 7

1 Answers  


a way in which a pointer stores the address of a pointer which stores the value of the target value a) reference b) allocation c) multiple indirection d) none

0 Answers  


Compare and contrast compilers from interpreters.

0 Answers  


What are the general description for loop statement and available loop types in c?

0 Answers  


How can I find the day of the week given the date?

0 Answers  


Categories