How can i write a code in c# to take a number from the user
and then find all the prime numbers till the number entered
by the user.

Answers were Sorted based on User's Feedback



How can i write a code in c# to take a number from the user and then find all the prime numbers til..

Answer / kumar gaurav

void main()
{
int num=0, i=0;
printf("Enter the number to ckeck");
scanf("%d",&num);
for (i=2;i<num;i++)
{
if (num%i==0)
{
printf("Number is not prime");
break;
}
}
if (i==num)
{
printf("Number is prime");
}
getch();
}

Is This Answer Correct ?    10 Yes 1 No

How can i write a code in c# to take a number from the user and then find all the prime numbers til..

Answer / shuklaamit565

using System;
class Test2
{
public static void Main()
{
int prime,num=100;

for(int i = 3; i <num; i++)
{
prime = 1;
for(int n = 2; n <= i - 1;
n++)
{
if(i % n == 0)
{
prime = 2;
}
}
if(prime==1)
{
Console.WriteLine( "
is prime :"+i);
}
}
}
}

Is This Answer Correct ?    0 Yes 0 No

How can i write a code in c# to take a number from the user and then find all the prime numbers til..

Answer / guest

for(i=0;i<n;i++)
{
if(i==1||i==2||i==3||i==5||i==7)
{
printf("No is prime");
}
else if(i%2==0&&i%3==0&&i%5==0&&i%7==0)
{
printf("No is prime");
}
else
printf("No is not prime");
}

Is This Answer Correct ?    5 Yes 9 No

How can i write a code in c# to take a number from the user and then find all the prime numbers til..

Answer / anjali

while(num>0)
{
if(num%2==1)
printf("num is prime value");
}

Is This Answer Correct ?    1 Yes 10 No

Post New Answer

More OOPS Interview Questions

Why multiple inheritance is not allowed?

0 Answers  


given a set based questions and 5 questions based on it next data sufficiciency questions 2 and 2/3 english sentence completion with options very easy and 2 synononmys paragraph with 10 questions 10 minutes replace =,-,*,% with -,%,+,* type questions 5 3 questions lik following itssickhere itssickthere itssickhere istsickhere which is nt alike the others very easy

0 Answers   DELL,


Definition of Object Oriented Programming in single line?

33 Answers   Impact Systems, Q3 Technologies, TCS,


What is pure oop?

0 Answers  


Why is destructor used?

0 Answers  






Give an example where we have to specifically use C programming language and C++ programming language cannot be used?

0 Answers   CAT,


What are oops methods?

0 Answers  


What is an orthogonal base class?

2 Answers  


What is a template?

7 Answers  


how to create thread in java?

17 Answers   IBM, Infosys, Wipro,


Why do we need oop?

0 Answers  


Write a program in c++ to read two floating point numbers and find their sum and average.

2 Answers  


Categories