Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?

4 Answers  


What is meant by 'bit masking'?

0 Answers  


what is the height of tree if leaf node is at level 3. please explain

0 Answers  


without using arithmatic operator convert an intger variable x into x+1

3 Answers  


What is the most efficient way to store flag values?

0 Answers  


How can you find the exact size of a data type in c?

0 Answers  


How do we declare variables in c?

0 Answers  


please give me some tips for the placement in the TCS.

0 Answers   TCS,


How can you access memory located at a certain address?

0 Answers  


Write any data structure program (stack implementation)

1 Answers   HTC,


what are bitwise shift operators?

4 Answers  


Can stdout be forced to print somewhere other than the screen?

0 Answers  


Categories