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

Explain two-dimensional array.

0 Answers  


What is cohesion and coupling in c?

0 Answers  


Write a function that accepts a sentence as a parameter, and returns the same with each of its words reversed. The returned sentence should have 1 blank space between each pair of words. Demonstrate the usage of this function from a main program. Example: Parameter: “jack and jill went up a hill” Return Value: “kcaj dna llij tnew pu a llih”

5 Answers   Mind Tree,


15.what is the disadvantage of using macros? 16.what is the self-referential structure? 17.can a union be self-referenced? 18.What is a pointer? 19.What is the Lvalue and Rvalue? 20.what is the difference between these initializations? 21.Char a[]=”string”; 22.Char *p=”literal”; 23.Does *p++ increment p, or what it points to?

2 Answers   CTS,


why the execution starts from main function

9 Answers  






A set of N billiard balls are set on a one-dimensional table. The table is 1 meter long, set north-south with two pockets at either side. Each ball has zero width and there is no friction so it is moving with a fixed velocity of either northward or southward and bounces back in a perfect elastic collision from other balls it encounter on its way (or drop into one of the pockets). Your job is to keep track of the balls movements. Task Please write a program that gets the initial place, speed and direction of all the balls and gives the position of a specific ball after t seconds. Input The first line contains the number of scenarios. Each one of the other lines in the input contains a scenario: The first number, N, is the number of balls; followed by N pairs of numbers: the distance in centimeters from the south end of the table and the speed (positive speed meaning it moves northward); the last two numbers are the number i of the target ball you should track and the time T in seconds. Output The output is a single number for each line which is the place (distance in centimeters from the south end of the table) of the tracked ball after T seconds. Note: There is no new line character at the end of the result. Sample Input 5 1 50 1 1 1000 1 50 1 1 6 1 60 -2 1 6 2 10 1 95 -1 2 30 2 10 1 95 -1 2 60 Sample Output 100 56 48 65 70

0 Answers  


Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?

0 Answers  


What is "Duff's Device"?

0 Answers   Celstream,


what are brk, sbrk?

1 Answers   Oracle,


What should malloc() do? Return a null pointer or a pointer to 0 bytes?

0 Answers  


write a program to swap two variables a=5 , b= 10 without using third variable

5 Answers  


write a program in c to read array check element is present or not?

1 Answers  


Categories