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
What library is sizeof in c?
How can I get the current date or time of day in a c program?
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
What is infinite loop?
How does pointer work in c?
Explain what are the advantages and disadvantages of a heap?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
The file stdio.h, what does it contain?
Describe dynamic data structure in c programming language?
Explain how can I avoid the abort, retry, fail messages?
What is main function in c?
Why is structure important for a child?
How many keywords (reserve words) are in c?
Explain argument and its types.
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?