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

Which is the memory area not included in C program? give the reason

1508


What is difference between function overloading and operator overloading?

657


What Is The Difference Between Null And Void Pointer?

640


largest Of three Number using without if condition?

1005


What's the difference between constant char *p and char * constant p?

653






What is a loop?

554


Between macros and functions,which is better to use and why?

1568


Is multithreading possible in c?

566


Why malloc is faster than calloc?

590


What is the purpose of main( ) in c language?

617


Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?

628


What is the total generic pointer type?

724


Explain about block scope in c?

661


What are header files and what are its uses in C programming?

632


5 Write an Algorithm to find the maximum and minimum items in a set of ā€˜nā€™ element.

1582