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
Answer Posted / 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 |
Post New Answer View All Answers
What does the c preprocessor do?
What is #define?
what is use of malloc and calloc?
How to define structures? ·
Can the curly brackets { } be used to enclose a single line of code?
hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .
Explain what is the purpose of "extern" keyword in a function declaration?
What is the benefit of using const for declaring constants?
What is null in c?
What is the difference between typedef struct and struct?
we need to calculating INCOME TAX for the person. The INCOME TAX is as follows:- First $10000/- of income : 4% tax Next $10000/- of income : 8% tax Next $10000/- of income : 11.5% tax above $10, 00,00/- : 15% tax What is the Solution of this Question ?
When should structures be passed by values or by references?
What are the differences between new and malloc in C?
What is meant by high-order and low-order bytes?
What is the difference between char array and char pointer?