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 a lvalue
What is the use of a conditional inclusion statement in C?
hi, which software companys will take,if d candidate's % is jst 55%?
How can I write a function analogous to scanf?
How do you define a function?
Why is event driven programming or procedural programming, better within specific scenario?
Explain the use of function toupper() with and example code?
What is the difference between printf and scanf )?
What is default value of global variable in c?
Do you know null pointer?
What is meant by operator precedence?
What are the different types of control structures?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
Explain About fork()?
Can variables be declared anywhere in c?