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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between null pointer and void pointer.

675


Write a factorial program using C.

647


can any one provide me the notes of data structure for ignou cs-62 paper

1708


Describe the modifier in c?

610


what is a function method?give example?

1918






What are bitwise shift operators in c programming?

650


Can you explain what keyboard debouncing is, and where and why we us it? please give some examples

1664


What are structural members?

576


write a c program to do the following: a) To find the area of a triangle. b) To convert the temperature from Fahrenheit to Celsius. c) To convert the time in hours : minutes : seconds to seconds.

1520


Which is better pointer or array?

606


Explain can static variables be declared in a header file?

684


What is the difference between far and near in c?

604


What are variables and it what way is it different from constants?

793


What is a 'null pointer assignment' error?

728


List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.

2305