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
Can a pointer be null?
What is the maximum length of an identifier?
What does p mean in physics?
What is the difference between c and python?
write a program to print largest number of each row of a 2D array
What is a keyword?
In which layer of the network datastructure format change is done
how can I convert a string to a number?
disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit
How is a macro different from a function?
Explain logical errors? Compare with syntax errors.
What are variables c?
Explain what are bus errors, memory faults, and core dumps?
What is getch c?
What is string function in c?