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
What is integer constants?
What is the hardest programming language?
How can I get random integers in a certain range?
Where are some collections of useful code fragments and examples?
What is difference between %d and %i in c?
When would you use a pointer to a function?
What oops means?
Explain Basic concepts of C language?
What do you understand by normalization of pointers?
What is the use of getchar functions?
Explain what is the advantage of a random access file?
process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,
Explain threaded binary trees?
how to execute a program using if else condition and the output should enter number and the number is odd only...
What are c header files?