write the program for prime numbers?
Answer Posted / 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 |
Post New Answer View All Answers
Is return a keyword in c?
What are the types of pointers?
What is the difference between struct and union in C?
What is the use of void pointer and null pointer in c language?
Which is better pointer or array?
Why clrscr is used after variable declaration?
Explain how can I right-justify a string?
What is a string?
Why do we use namespace feature?
What is scope rule of function in c?
console I/O functions means a) the I/O operations done on disk b) the I/O operations done in all parts c) the input given through keyboard is displayed VDU screen d) none of the above
why do some people write if(0 == x) instead of if(x == 0)?
How do I determine whether a character is numeric, alphabetic, and so on?
What is a sequential access file?
Can you please compare array with pointer?