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
Which is the memory area not included in C program? give the reason
What is difference between function overloading and operator overloading?
What Is The Difference Between Null And Void Pointer?
largest Of three Number using without if condition?
What's the difference between constant char *p and char * constant p?
What is a loop?
Between macros and functions,which is better to use and why?
Is multithreading possible in c?
Why malloc is faster than calloc?
What is the purpose of main( ) in c language?
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.?
What is the total generic pointer type?
Explain about block scope in c?
What are header files and what are its uses in C programming?
5 Write an Algorithm to find the maximum and minimum items in a set of ānā element.