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
Why #include is used in c language?
Explain can the sizeof operator be used to tell the size of an array passed to a function?
Explain the use of keyword 'register' with respect to variables.
What is null pointer constant?
write a program to print data of 5 five students with structures?
What is the use of a ‘ ’ character?
Write a program to reverse a given number in c language?
find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }
What is the data segment that is followed by c?
what is the basis for selection of arrays or pointers as data structure in a program
What are register variables? What are the advantage of using register variables?
Is it cc or c in a letter?
Why can’t constant values be used to define an array’s initial size?
How many types of operators are there in c?
What is a char in c?