Primetest - { if(n%i==0) { isPrime = 0;//set to false if n...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> # using namespace std; u int main () { int n; int i; int isPrime = 1; //1 is true and 0 is for false, there is no boolean in C not like C++ //it should be set initialy to true printf("Enter your number: "); scanf("%d",&n); s for(i=n;i>1;i--)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { if(n%i==0) { isPrime = 0;//set to false if n is evenly divisible break; //then exit the loop leaving isPrime == false } } if(isPrime) printf(&quot;It is a prime number.&quot;); else printf(&quot;it is not a prime number.&quot;); scanf(&quot;%d&quot;,i); }...
View Full Document

This note was uploaded on 08/25/2011 for the course IT 109 taught by Professor Bucao during the Spring '11 term at Ateneo de Manila University.

Ask a homework question - tutors are online