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.
Answer Posted / 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 |
Post New Answer View All Answers
How to handle exception in c++, For example in a functions i am assigning memory to some variables and also in next instructions in am dividing one variable also. If this functions generates a error while allocating memory to those variable and also while dividing the variable if i divide by zero then catch block how it will identify that this error has cone from perticular instruction
Can we have inheritance without polymorphism?
How Do you Code Composition and Aggregation in C++ ?
If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?
write a program that takes input in digits and display the result in words from 1 to 1000
What are oops functions?
Is react oop?
write a program to find 2^n+1 ?
What is the purpose of polymorphism?
when to use 'mutable' keyword and when to use 'const cast' in c++
What is encapsulation in ict?
What is use of overloading?
What are the three main types of variables?
What is class encapsulation?
What is static in oop?