i want to asked a question about c program the question is:

create a c program that displays all prime numbers less than
500? using looping statement

Answers were Sorted based on User's Feedback



i want to asked a question about c program the question is: create a c program that displays all ..

Answer / vadivelt

Hi.
Have a look on the code i hav written below.
Just give max no(in this question 500) as a input, u ll get
the prime nos in this range.


#include<stdio.h>
#include<conio.h>

main()
{
int n, j, k, flag = 0;
printf("ENTER THE NO\n");
scanf("%d", &n);
printf("\nPRIME NOS IN THIS RANGE\n");
for(j = 1; j<= n; j++)
{
for(k = j; k>=1; k--)
{
if(j%k == 0)
flag++;
}
if(flag == 2)
{
printf("%d ", j);
}
flag = 0;
}
getch();
}

Is This Answer Correct ?    3 Yes 0 No

i want to asked a question about c program the question is: create a c program that displays all ..

Answer / vadivelt

Is This Answer Correct ?    1 Yes 0 No

i want to asked a question about c program the question is: create a c program that displays all ..

Answer / ashwin kumar

I hope this is right code for you
1st it promt for max number then enter 500 then you will
get result.


#include<stdio.h>
#include<conio.h>
int main()
{
int value,j,i,value2,flag=0,count=0;
clrscr();
printf("enter limit up to which prime numbers to be
printed : ");
scanf("%d",&value2);
printf("\n\n\nlist of prime numbers are:\n\n");
for(j=1;j<=value2;j++)
{
flag=0;
value=j;
for(i=2;i<value;i++)
{
if(value%i==0)
{

flag=flag+1;
goto l1;

}


}
l1:
if(!(flag==1||value==2))
{
printf("%-10d",value);
count+=1;
}
}
printf("\n\ntotal number of prime numbers between 1 and %d
are : %d",value2,count);
getch();
return 0;

}



if their is any changes required or any suggestions mail
me at molugu.ashwin@gmail.com

Is This Answer Correct ?    1 Yes 0 No

i want to asked a question about c program the question is: create a c program that displays all ..

Answer / ashwin kumar

its just to find weather given number is prime or not


#include<stdio.h>
#include<conio.h>
int main()
{
int value,i,flag=0;
clrscr();
printf("enter value to check for prime number : ");
scanf("%d",&value);
for(i=2;i<value;i++)
{
if(value%i==0)
{

flag=flag+1;
break;

}


}
if(flag==1||value==2)
printf(" %d is not a prime number",value);
else
printf(" %d is a prime number",value);

getch();
return 0;

}

Is This Answer Correct ?    0 Yes 0 No

i want to asked a question about c program the question is: create a c program that displays all ..

Answer / vishnu nayak

int main()
{
unsigned int i,k;
unsigned int temp;
int count =0;
printf("enter the number \n");
scanf("%u",&i);
printf("\n");

for(temp =2;temp<i;temp++)
{
count =0;
for(k =2;k<=i;k++)
{
if((temp % k) == 0)
count++;

}
if(count <=1 )
printf("%u \n",temp);

}
getch();
}

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Interview Questions

Is c still relevant?

0 Answers  


void main() { int a=1; while(a++<=1) while(a++<=2); }

4 Answers   HCL,


find the output of the following program main() { int x=5, *p; p=&x; printf("%d",++*p); }

10 Answers   Amdocs, TCS,


What are void pointers in c?

0 Answers  


number 2 plssssss help !!....using array.. turbo c.. create a program that will accept a number and determine if it is a happy number or an unhappy number.. example: enter a number : 7 7*7=49 then 4 and 9 4*4 and 9*9== 16 + 18 gives you 97 then 9 and 7 9*9 and 7*7 == 81 + 49 gives you 130 then 1 and 3 1*1 and 3*3 == 1 + 9 gives you 10 1*1 gives you 1 sample output: 7= 49= 16+81= 97= 81+49=130 =1+9=10 =1 "7 is a happy number" . if the last number is 2 then the number being inputed is not a happy number.

3 Answers  






What are the similarities between c and c++?

0 Answers  


When is a void pointer used?

0 Answers  


What is the return type of sizeof?

0 Answers  


WHAT IS PRE POSSESSORS?

6 Answers   TATA,


How many ways are there to swap two numbers without using temporary variable? Give the each logic.

9 Answers  


Write a program to check prime number in c programming?

0 Answers  


Explain what standard functions are available to manipulate strings?

0 Answers  


Categories