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
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
If I have a char * variable pointing to the name of a function ..
What are the 32 keywords in c?
An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above
What functions are in conio h?
What does *p++ do?
void main(int n) { if(n==0) return; main(--n); printf("%d ",n); getch(); } how it work and what will be its output...............it any one know ans plz reply
Tell me with an example the self-referential structure?
What does %c do in c?
Can you please explain the difference between exit() and _exit() function?
What extern c means?
Give the rules for variable declaration?
What does == mean in texting?
What is static identifier?
What will the code below print when it is executed? int x = 3, y = 4; if (x = 4) y = 5; else y = 2; printf ("x=%d, y=%d ",x,y);