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
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 |
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 |
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 |
Answer / anjali
while(num>0)
{
if(num%2==1)
printf("num is prime value");
}
| Is This Answer Correct ? | 1 Yes | 10 No |
Can a varargs method be overloaded?
what is the definition of incapsulation
i=20;k=0; for(j=1;k-i;k+=j<10?4:3) { cout<<k; } //please comment on the output
What is the full form of oops?
where is memory for struct allocated? where is memory for class-object allocated? I replied for struct in stack and for class-object in heap. THen he asked if class has struct member variable what happens.class on heap and what about struct in that class? couldnt ans :( :-?
what is difference between String s=new String("vali"); String s="vali"
how to get the oracle certification? send me the answer
Can private class be inherited?
What is difference between class and object with example?
Why do we need oop?
What is constructor overloading in oop?
1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321