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
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 |
Answer / vadivelt
Is This Answer Correct ? | 1 Yes | 0 No |
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 |
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 |
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 |
How to write a multi-statement macro?
What is information technology.
Q. where is the below variables stored ? - volatile, static, register
What are near, far and huge pointers?
0 Answers Hexaware, Thomson Reuters, Virtusa,
WHAT IS PRE POSSESSORS?
Write an implementation of “float stringToFloat(char *str).” The code should be simple, and not require more than the basic operators (if, for, math operators, etc.). • Assumptions • Don’t worry about overflow or underflow • Stop at the 1st invalid character and return the number you have converted till then, if the 1st character is invalid return 0 • Don’t worry about exponential (e.g. 1e10), instead you should treat ‘e’ as an invalid character • Write it like real code, e.g. do error checking • Go though the string only once • Examples • “1.23” should return 1.23 • “1a” should return 1 • “a”should return 0
hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?
Name the language in which the compiler of "c" in written?
What is string concatenation in c?
write a program to print calender using for loop.
what is the use of operator ^ in C ? and how it works?
Explain what’s a signal? Explain what do I use signals for?