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 the use of structure padding in c?

799


Why c is called procedure oriented language?

802


Do you know the difference between exit() and _exit() function in c?

807


Explain what are multidimensional arrays?

825


#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }

902


i want to know the procedure of qualcomm for getting a job through offcampus

2204


What are identifiers c?

840


Explain the use of fflush() function?

853


What are the two types of functions in c?

770


What is extern c used for?

768


PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM

1954


How does free() know explain how much memory to release?

815


Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

926


What is #ifdef ? What is its application?

857


What is function prototype in c language?

812