100% SET4- 11a: Prog to find prime or not using functions
#include <stdio.h>
void primeornot(int num)
{
int i = 2;
while(i <= num / 2)
{
if(num % i == 0)
{
printf ("\n given number %d is not prime", num);
break;
}
i++;
}
if(i == (num / 2) + 1)
printf ("\n given number %d is prime", num);
}
void main()
{
int numb;
printf ("\nenter a int >1 and <32768 that has to be checked for prime or not:");
scanf ("%d", &numb);
if(numb>1 && numb <32768)
primeornot (numb);
else
printf("\n entered number is out of prescribed limits:");
} //end of main
enter a int >1 and <32768 that has to be checked for prime or not:24
given number 24 is not prime
enter a int >1 and <32768 that has to be checked for prime or not:2
given number 2 is prime
void primeornot(int num)
{
int i = 2;
while(i <= num / 2)
{
if(num % i == 0)
{
printf ("\n given number %d is not prime", num);
break;
}
i++;
}
if(i == (num / 2) + 1)
printf ("\n given number %d is prime", num);
}
void main()
{
int numb;
printf ("\nenter a int >1 and <32768 that has to be checked for prime or not:");
scanf ("%d", &numb);
if(numb>1 && numb <32768)
primeornot (numb);
else
printf("\n entered number is out of prescribed limits:");
} //end of main
తెరమీద
enter a int >1 and <32768 that has to be checked for prime or not:24
given number 24 is not prime
తెరమీద మరోసారి
enter a int >1 and <32768 that has to be checked for prime or not:2
given number 2 is prime
ఇంకోసారి
enter a int >1 and <32768 that has to be checked for prime or not:43221
entered number is out of prescribed limits:
enter a int >1 and <32768 that has to be checked for prime or not:43221
entered number is out of prescribed limits:
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.