write the program for prime numbers?

Answer Posted / azka sumbel

namespace prime_381
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int a;
int result;
int i, j;

private void button1_Click(object sender, EventArgs
e)
{

a = Convert.ToInt32(textBox1.Text);
prime();
textBox1.Clear();
textBox1.Focus();

}
int flag;
public void prime()
{
flag = 1;

for (i = 2; i <= a / 2; i++)
{
if (a % i == 0)
flag = 0;
}
if (flag == 1)
MessageBox.Show("Prime.");
else
MessageBox.Show("not Prime");
}
}
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain #pragma statements.

693


What are register variables? What are the advantage of using register variables?

778


I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...

9771


What is adt in c programming?

728


Why doesnt long int work?

707






What is call by reference in functions?

736


Can a variable be both constant and volatile?

658


What is the function of volatile in c language?

760


Which is best book for data structures in c?

696


What is the condition that is applied with ?: Operator?

750


write a programming in c to find the sum of all elements in an array through function.

1811


Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.

764


Explain how do you list files in a directory?

723


What is a rvalue?

843


Explain how can I convert a number to a string?

730