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 / dinesh

#include<stdio.h>
main()
{
int i,j;
for(i=2;i<=20;i++)
{
c=1;
for(j=2;j<i;j++)
{
if(i%j==0)
c=0;
}
if(c==1)
printf("%d",i);
}
}

Is This Answer Correct ?    46 Yes 21 No

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

Answer / ruth

#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();
}

Is This Answer Correct ?    18 Yes 3 No

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

Answer / binati mishra

prime number 1 to 20:
1 2 3 5 7 11 13 17 19

Is This Answer Correct ?    31 Yes 17 No

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

Answer / ricky dobriyal

sorry for above output mistake:

output :1 2 5 7 11 13 17 19

Is This Answer Correct ?    21 Yes 17 No

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

Answer / bheem rao

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,count=0;
for(i=2;i<=20;i++)
{
for(j=1;j<=i;i++)
{
if(i%j==0)
count++;
}
if(count==2)
printf("%d\n",i);
count=0;
}
}

Is This Answer Correct ?    12 Yes 8 No

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

Answer / sreejesh1987

//Ha Ha I'm the creator of shortest code
//for prime numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
printf("\t\t\tPRIME NUMBERS 1-20\n");
printf("\n\t2");
for(i=3;i<=20;i++)
for(j=2;j<i,i%j!=0;j++)
if(i-1==j)
printf("\n\t%d",i);
getch();
}

Is This Answer Correct ?    6 Yes 3 No

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

Answer / ritu

Write a program to generate the first n terms in the series --- 2,3,5,7,11,...,17

Is This Answer Correct ?    5 Yes 2 No

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

Answer / rupamrox

#include<stdio.h>
#include<conio.h>
main()
{
int i,j,prime;
clrscr();
for(i=2;i<20;i++)
{
prime=1;
for(j=2;j<i;j++)
{
if(i%j==0)
prime=0;
}
if(prime==1)
printf("%d",i);
}
getch();
}

Is This Answer Correct ?    9 Yes 7 No

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

Answer / aniruddha tripathi

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,m,i;
clrscr();
printf("\n ENTER THE NUMBER");
scanf("%d",&n);
i=2;
ab:mfmod(n,i);
if(m==0);
{
printf("\n it is not prime");
goto bc;
]
else
{
i=i+1;
if(i<=(n-1))
{
goto ab;
}
printf("\n it is a prime no.");
}
bc;
getch();
}

Is This Answer Correct ?    3 Yes 1 No

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

Answer / r@m$

#include<stdio.h>
void main(){
int x;
for(x=2;x<=20;x++){
if(x<4)
printf("%d\t",x);
else
if(x%2!=0 && x%3!=0)
printf("%d\t",x);
}
}

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

Why is c used in embedded systems?

0 Answers  


what is difference between null and nul in c language

2 Answers  


How to write a C program to determine the smallest among three nos using conditional operator?

2 Answers   Google,


Differentiate Source Codes from Object Codes

1 Answers  


#include<stdio.h> int main(){ int i=10; int *ptr=&i; *ptr=(int *)20; printf("%d",i); return 0; } Output: 20 can anyone explain how came the output is 20

0 Answers  






What is type qualifiers?

0 Answers  


Explain the Difference between the New and Malloc keyword.

0 Answers   InterGraph,


write a program to print the all 4digits numbers & whose squares must me even numbers?

2 Answers   Virtusa,


c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above

0 Answers  


Is there a way to have non-constant case labels (i.e. Ranges or arbitrary expressions)?

0 Answers  


What is the hardest programming language?

0 Answers  


how to get the starting address of file stored in harddisk through 'C'program.

2 Answers   Siemens,


Categories