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 sizeof int in c?
Can a variable be both static and volatile in c?
What is structure padding in c?
Explain about C function prototype?
What are disadvantages of C language.
How do you determine a file’s attributes?
why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above
Why n++ execute faster than n+1 ?
Whats s or c mean?
What is the description for syntax errors?
Can one function call another?
Do you know what are the properties of union in c?
Explain what is the best way to comment out a section of code that contains comments?
Difference between macros and inline functions? Can a function be forced as inline?
Explain the advantages of using macro in c language?