write the program for prime numbers?

Answers were Sorted based on User's Feedback



write the program for prime numbers?..

Answer / nischal

plz write the pl/sql program for prime numbers? in simple way
dat can be understood easily....

Is This Answer Correct ?    0 Yes 0 No

write the program for prime numbers?..

Answer / lavanya

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public static void prime(int number)
{
for (int i = 1; i <= number; i++)
{
for (int j = 2; j <= number; j++)
{
if (i % j == 0)
{
if(i==j)
Console.WriteLine(i.ToString());
break;
}
}
}
}
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
int number = Convert.ToInt32(Console.ReadLine());
prime(number);
Console.ReadLine();
}
}
}

Is This Answer Correct ?    0 Yes 0 No

write the program for prime numbers?..

Answer / karthika

#include<stdio.h>
#include<conio.h>
void main()
{
int num,i=2;
clrscr();
printf("\n entert a number");
scanf("%d",&num);
while(c<=num-1)
{
if(num%i==0)
{
printf("given number is not a prime number\n");
break;
}
i++;
}
if(i==num);
printf(given number is a prime number\n");
getch();
}

Is This Answer Correct ?    0 Yes 0 No

write the program for prime numbers?..

Answer / varun raj s p

#include<stdio.h>

int main()
{
int n, i = 3, count, c;

printf("Enter the number of prime numbers required\n");
scanf("%d",&n);

if ( n >= 1 )
{
printf("First %d prime numbers are :\n",n);
printf("2\n");
}

for ( count = 2 ; count <= n ; )
{
for ( c = 2 ; c <= i - 1 ; c++ )
{
if ( i%c == 0 )
break;
}
if ( c == i )
{
printf("%d\n",i);
count++;
}
i++;
}

return 0;
}

Is This Answer Correct ?    0 Yes 0 No

write the program for prime numbers?..

Answer / noble

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter any number:");
scanf("%d",&a);
for(b=2;b<=a-1;b++)
{
if(a%b==0)
break;
}
if(a==b)
{
printf("%d is prime number",a);
}
else
{
printf("%d is not prime number",a);
}
getch();
}

Is This Answer Correct ?    0 Yes 0 No

write the program for prime numbers?..

Answer / anesh kumar

# include <iostream.h>
# include <conio.h>
int main()
{
int i,j=2,num=0;
cout<<"\n Enter the number";
cin>>i%j>>i;
while(j<=i/2)
{
if(i%j==0)
{
Cout<<"%d Is not prime number"<<i;
ch=1;
break;
}
else
{
j++;
}
}
if(num==0)
{
Cout<<"%d Is prime number"<<i;
}
getch();
return 0;

}

Is This Answer Correct ?    0 Yes 0 No

write the program for prime numbers?..

Answer / sudesh kumar

#include<iostream.h>
#include<conio.h>
void main()
{
int no,i,r,p=1;
cout<<"enter a no";
cin>>no;
for(i=2;i<no;i++)
{
if(r==no%i)
{
p=0;
break;
}
}
if(p==0)
{
cout<<"the prime no";
}
else
{
cout<<"the no is note prime";
}
getch();
}

Is This Answer Correct ?    13 Yes 14 No

write the program for prime numbers?..

Answer / ashok

void main()
{
int i,n;
clrscr();
printf("\nEnter the range:");
scanf("%d",&n)
printf("Prime numbers are:");
for(i=1;i<=n;i++)
{
if(i==2 || i==3 || i==5 || i==7)
printf("%d ",i);
if(i%2!=0 && i%3!=0 && i%5!=0 && i%7!=0)
printf("%d ",i);
}
getch();
}

Is This Answer Correct ?    7 Yes 8 No

write the program for prime numbers?..

Answer / oza priyanka

#include<stdio.h>
void main()
{
int num,i,cnt;
clrscr();
printf("\n\nEnter the number = ");
scanf("%d",&num);
for(i=2,cnt=0;i<num;i++)
{
if(num%i==0)
cnt=1;
}
if(cnt==0)
printf("\n\nprime number");
else
printf("\n\n not a prime number");
getch();
}

Is This Answer Correct ?    0 Yes 1 No

write the program for prime numbers?..

Answer / naseer

main(){
int no,i,count=0;
printf("enter any no");
scanf("%d",&no);
//the main logic is here
for(i=2;i<no;i++){

if(no%2==0){
count++;
}
}
if(count>=1)// if the no is less than
//5 then it shows prime
{
printf("not Prime");
}

else
printf("prime");

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

Where local variables are stored in c?

0 Answers  


Write one statement equalent to the following two statements x=sqr(a); return(x); Choose from one of the alternatives a.return(sqr(a)); b.printf("sqr(a)"); c.return(a*a*a); d.printf("%d",sqr(a));

6 Answers   TCS,


Would you rather wait for the results of a quicksort, a linear search, or a bubble sort on a 200000 element array? 1) Quicksort 2) Linear Search 3) Bubble Sort

3 Answers  


What is the use of static variable in c?

0 Answers  


1. Write a C program to count the number of occurrence of a specific word in the given strings. (for e.g. Find how many times the word “live” comes in the sentence “Dream as if you’ll live forever, live as if you’ll die today ”)

12 Answers   Eskom, TCS,


What are the average number of comparisons required to sort 3 elements?

2 Answers   DRDO,


What is scope and lifetime of a variable in c?

0 Answers  


write the output of following code .. main() { static int a[]={10,20,30,40,50}; int *ptr=a; static int arr[2][2]={1,2,3,4}; char str[]="ABCD * 4#"; char *s=str+2; int i,j; for(i=0;i<5,i++) printf("%d",*ptr++); for(i=0;i<2;i++) for(j=0;j<2;j++) printf("%d\n",*(*(n+i)+j)); printf("%c\n%c\n%c\n",*(str+2),*s++,*--s); }

1 Answers  


Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80

0 Answers  


union { char ch[10]; short s; }test; test.s = 0xabcd; main() { printf("%d",ch[10]); }

3 Answers  


What is #include in c?

0 Answers  


How to write a C program to determine the smallest among three nos using conditional operator?

2 Answers   Google,


Categories