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

Can we assign integer value to char in c?

619


Can you explain what keyboard debouncing is, and where and why we us it? please give some examples

1664


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

637


Can you please explain the difference between malloc() and calloc() function?

623


What is an arrays?

659






Are comments included during the compilation stage and placed in the EXE file as well?

674


What is indirection in c?

631


Explain logical errors? Compare with syntax errors.

633


Explain what happens if you free a pointer twice?

615


What is the use of function in c?

716


How can you increase the allowable number of simultaneously open files?

599


Is that possible to add pointers to each other?

907


What are enumerated types?

657


Why isn't any of this standardized in c? Any real program has to do some of these things.

630


What are all different types of pointers in c?

581