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


Please Help Members By Posting Answers For Below Questions

What is a lvalue

883


What is the use of a conditional inclusion statement in C?

857


hi, which software companys will take,if d candidate's % is jst 55%?

1886


How can I write a function analogous to scanf?

911


How do you define a function?

802


Why is event driven programming or procedural programming, better within specific scenario?

2183


Explain the use of function toupper() with and example code?

889


What is the difference between printf and scanf )?

821


What is default value of global variable in c?

776


Do you know null pointer?

802


What is meant by operator precedence?

894


What are the different types of control structures?

819


Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.

931


Explain About fork()?

870


Can variables be declared anywhere in c?

852