turboc++
-------------------------------------------------------------------------------------------------
//program to know a number is prime or composite or not using function.use no parameter;use return value
#include<stdio.h> //header file
#include<conio.h>
int prime_number(); // function prototype/declaration with return type zero.
int main() //main function
{
int result;
result=prime_number(); // function calling.
if(result==0) //condition testing
{
printf("it is prime\n"); //printing output
}
else
{
printf("it is not prime\n");
}
getch();
return 0; //returns 0 value
}
int prime_number() // function body line ; also called function definition
{
int i,number,count=0; // variable declaration
printf("enter a number\n"); //message display to input a number
scanf("%d",&number); //gets input
for(i=2;i<number;i++) //executing from 2 to <n
{
if(number%i==0) //testing for next number
{
count=1; //assigning to 1 to count
}
}
if(count==0) //testing count ;whetehre it has 0 or 1
{
return count; //returning count
}
else
{
return; //returns nothing
}
}
--------------------------------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------------------------------------
//program to know a number is prime or composite or not using function.use no parameter;use return value
#include<stdio.h> //header file
#include<conio.h>
int prime_number(); // function prototype/declaration with return type zero.
int main() //main function
{
int result;
result=prime_number(); // function calling.
if(result==0) //condition testing
{
printf("it is prime\n"); //printing output
}
else
{
printf("it is not prime\n");
}
getch();
return 0; //returns 0 value
}
int prime_number() // function body line ; also called function definition
{
int i,number,count=0; // variable declaration
printf("enter a number\n"); //message display to input a number
scanf("%d",&number); //gets input
for(i=2;i<number;i++) //executing from 2 to <n
{
if(number%i==0) //testing for next number
{
count=1; //assigning to 1 to count
}
}
if(count==0) //testing count ;whetehre it has 0 or 1
{
return count; //returning count
}
else
{
return; //returns nothing
}
}
-------------------------------------------------------------------------------------------------
//program to know a number is prime or composite or not using function.use no parameter;use return value
#include<stdio.h> //header file
#include<conio.h>
int prime_number(); // function prototype/declaration with return type zero.
int main() //main function
{
int result;
result=prime_number(); // function calling.
if(result==0) //condition testing
{
printf("it is prime\n"); //printing output
}
else
{
printf("it is not prime\n");
}
getch();
return 0; //returns 0 value
}
int prime_number() // function body line ; also called function definition
{
int i,number,count=0; // variable declaration
printf("enter a number\n"); //message display to input a number
scanf("%d",&number); //gets input
for(i=2;i<number;i++) //executing from 2 to <n
{
if(number%i==0) //testing for next number
{
count=1; //assigning to 1 to count
}
}
if(count==0) //testing count ;whetehre it has 0 or 1
{
return count; //returning count
}
else
{
return; //returns nothing
}
}
--------------------------------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------------------------------------
//program to know a number is prime or composite or not using function.use no parameter;use return value
#include<stdio.h> //header file
#include<conio.h>
int prime_number(); // function prototype/declaration with return type zero.
int main() //main function
{
int result;
result=prime_number(); // function calling.
if(result==0) //condition testing
{
printf("it is prime\n"); //printing output
}
else
{
printf("it is not prime\n");
}
getch();
return 0; //returns 0 value
}
int prime_number() // function body line ; also called function definition
{
int i,number,count=0; // variable declaration
printf("enter a number\n"); //message display to input a number
scanf("%d",&number); //gets input
for(i=2;i<number;i++) //executing from 2 to <n
{
if(number%i==0) //testing for next number
{
count=1; //assigning to 1 to count
}
}
if(count==0) //testing count ;whetehre it has 0 or 1
{
return count; //returning count
}
else
{
return; //returns nothing
}
}