Question #5222

A PROGRAM INPUT A NUMBER AND CHECK WEATHER PRIME OR NOT.

Expert's answer

C++:

A PROGRAM INPUT A NUMBER AND CHECK WHEATHER PRIME OR NOT

# include<iostream.h>

# include<conio.h>

//calculation

int isprime(int valuex)

{

int x,j;

x=1;

& for (j=2 ; j<valuex2; j++)

{ if ((valuex%j)==0) x=0; }

& if(x!=0) return 1;

& else return 0;

}

void main(){

int isprime(int);

int value;

//input

cout<<"Enter a number to verify whether it is prime or not "<<endl;

cin>>value;

//output

& if (isprime(value)==1) cout<<"Yes the number is prime"<<endl;

& else cout<<"Sorry, not a prime"<<endl;

& getch();

}

PROGRAM TO DO A MULTIPLICATION USING DO WHILE LOOP

# include<iostream.h>

# include<conio.h>

void main(){

int a,b,ab;

cout<<"Enter a first number: "<<endl;

cin>>a;

cout<<"Enter a second number: "<<endl;

cin>>b;

ab=0;

while (b>0){

& ab = ab+a;

& b--;

& }

cout<<"a*b = "<<ab;

getch();

}

A PROGRAM INPUT A NUMBER AND CHECK WHEATHER PRIME OR NOT

# include<iostream.h>

# include<conio.h>

//calculation

int isprime(int valuex)

{

int x,j;

x=1;

& for (j=2 ; j<valuex2; j++)

{ if ((valuex%j)==0) x=0; }

& if(x!=0) return 1;

& else return 0;

}

void main(){

int isprime(int);

int value;

//input

cout<<"Enter a number to verify whether it is prime or not "<<endl;

cin>>value;

//output

& if (isprime(value)==1) cout<<"Yes the number is prime"<<endl;

& else cout<<"Sorry, not a prime"<<endl;

& getch();

}

PROGRAM TO DO A MULTIPLICATION USING DO WHILE LOOP

# include<iostream.h>

# include<conio.h>

void main(){

int a,b,ab;

cout<<"Enter a first number: "<<endl;

cin>>a;

cout<<"Enter a second number: "<<endl;

cin>>b;

ab=0;

while (b>0){

& ab = ab+a;

& b--;

& }

cout<<"a*b = "<<ab;

getch();

}

## Comments

## Leave a comment