-->

program to get factorial value of a number using function

using codeblocks
-------------------------------------------------------------------------------------------

//program to get factorial value of a number using function
#include<stdio.h>                      //header file
void factorial();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
factorial();                                     // function calling.
return 0;                                       //returns 0 value
}
void factorial()                              // function body line ; also called function definition
{
int factorial_value=1,i;                             //initialization to value 1
 int n;                                       // variable declaration
 printf("enter a number\n");
 scanf("%d",&n);                            //input
for(i=1;i<=n;i++)                     //loop running from 1 to 100 with increment 1 each time
{
    factorial_value=factorial_value*i;                //formulation for factorial
}
printf("factorial=%d\n",factorial_value);      //output
}
--------------------------------------------------------------------------------------------------
using turboc++
------------------------------------------------------------------------------------------------
//program to get factorial value of a number using function
#include<stdio.h>                      //header file
#include<conio.h>
void factorial();                          // function prototype/declaration with return type zero.
void main()                              //main function
{
factorial();                         // function calling.
getch ();                                       //holds the output
}
void factorial()                              // function body line ; also called function definition
{
int factorial_value=1,i;                             //initialization to value 1
 int n;                                       // variable declaration
 printf("enter a number\n");
 scanf("%d",&n);                            //input
for(i=1;i<=n;i++)                     //loop running from 1 to 100 with increment 1 each time
{
    factorial_value=factorial_value*i;                //formulation for factorial
}
printf("factorial=%d\n",factorial_value);      //output
}
----------------------------------------------------------
/* here we have used top down approach. i.e calling from top and writing its body line down.
 we can also reverse the process.*/

program to get sum of 1,2,3,4,5,.............100 using function

using codeblock
--------------------------------------------------------------------------------------------------


//program get sum of  1,2,3,4,5,.............100 using function
#include<stdio.h>                      //header file
void sum_series();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
sum_series();                                     // function calling.
return 0;                                       //returns 0 value
}
void sum_series()                              // function body line ; also called function definition
{
int sum=0;           //initialization of sum to zero
 int i;                    // variable declaration 
for(i=1;i<=100;i++)       //loop running from 1 to 100 with increment 1 each time
{
    sum=sum+i;           // summing all the numbers repetitively
}
printf("sum=%d\n",sum);      //output
}


----------------------------------------------------------------------------------------------------------
using turboc++
-------------------------------------------------------------------------------------------------
//program get sum of  1,2,3,4,5,.............100 using function
#include<stdio.h>                      //header file
#include<conio.h>
void sum_series();                          // function prototype/declaration with return type zero.
void main()                              //main function
{
sum_series();                                     // function calling.
getch();                                       //returns 0 value
}
void sum_series()                              // function body line ; also called function definition
{
int sum=0;           //initialization of sum to zero
 int i;                    // variable declaration 
for(i=1;i<=100;i++)       //loop running from 1 to 100 with increment 1 each time
{
    sum=sum+i;           // summing all the numbers repetitively
}
printf("sum=%d\n",sum);      //output
}


/* here we have used top down approach. i.e calling from top and writing its body line down.
 we can also reverse the process.*/

program to generate series 1,2,3,4,5,.............100 using function

using codeblock
----------------------------------------------------------------------------------------
// to generate 1,2,3,4,5,....100 series using function.
#include<stdio.h>                      //header file
void series();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
series();                                     // function calling.
return 0;                                       //returns 0 value
}
void series()                              // function body line ; also called function definition
{
 int i;                    // variable declaration
for(i=1;i<=100;i++)       //loop running from 1 to 100 with increment 1 each time
{
    printf("%d\n",i);      //output
}
}

----------------------------------------------------------------------------------------------------

using turboc++
---------------------------------------------------------------------------------------------------
// to generate 1,2,3,4,5,....100 series using function.
#include<stdio.h>                      //header file
#include<conio.h>
void series();                          // function prototype/declaration with return type zero.
void main()                              //main function
{
series();                                     // function calling.
getch();                                       //holds the output
}
void series()                              // function body line ; also called function definition
{
 int i;                    // variable declaration
for(i=1;i<=100;i++)       //loop running from 1 to 100 with increment 1 each time
{
    printf("%d\n",i);      //output
}
}


/* here we have used top down approach. i.e calling from top and writing its body line down.
 we can also reverse the process.*/

program to know a number is positive or negative or zero using function.

using codeblock
---------------------------------


//program to know a number is positive or negative or zero using function.
#include<stdio.h>                      //header file
void number();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
number();                                     // function calling.
return 0;                                       //returns 0 value
}
void number()                              // function body line ; also called function definition
{
 int number;                    // variable declaration 
printf("enter number\n");           // displays message to input data
scanf("%d",&number);        // gets data from user.
if(number>0)                     //condition testing
{
printf("%d is positive\n",number);    // displays output
}

else if(number<0)                     //second condition testing
{
   printf("%d is negative\n",number); 
}
else                                   // if none of above condition satisfy
{
    printf("%d is zero\n",number);      //output
}
}


------------------------------------------------------------------------------------------
using turboc++
----------------------------------------------------------------------------------------------
//program to know a number is positive or negative or zero using function.
#include<stdio.h>                      //header file
#include<conio.h>
void number();                          // function prototype/declaration with return type zero.
void main()                              //main function
{
number();                                     // function calling.
getch();                                       //holds the output
}
void number()                              // function body line ; also called function definition
{
 int number;                    // variable declaration 
printf("enter number\n");           // displays message to input data
scanf("%d",&number);        // gets data from user.
if(number>0)                     //condition testing
{
printf("%d is positive\n",number);    // displays output
}

else if(number<0)                     //second condition testing
{
   printf("%d is negative\n",number); 
}
else                                   // if none of above condition satisfy
{
    printf("%d is zero\n",number);      //output
}
}

to know a number is even or odd using function.

using codeblocks
----------------------------------------------------------------------------------------------------
//to know a number is even or odd using function.
#include<stdio.h>                      //header file
void evenodd();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
evenodd();                                     // function calling.
return 0;                                       //returns 0 value
}
void evenodd()                              // function body line ; also called function definition
{
 int number;                    // variable declaration 
printf("enter number\n");           // displays message to input data
scanf("%d",&number);        // gets data from user.
if(number%2==0)                     //condition testing
{
printf("%f is even\n",number);    // displays output
}

else
{
   printf("%d is odd\n",number); //displays output
}
}



---------------------------------------------------------------------------------------

using turbo c++
----------------------------------------------------------------------------
//to know a number is even or odd using function.
#include<stdio.h>                      //header file
#include<conio.h>
void evenodd();                          // function prototype/declaration with return type zero.
void main()                              //main function
{
evenodd();                                     // function calling.
getch();                                       //returns 0 value
}
void evenodd()                              // function body line ; also called function definition
{
 int number;                    // variable declaration 
printf("enter number\n");           // displays message to input data
scanf("%d",&number);        // gets data from user.
if(number%2==0)                     //condition testing
{
printf("%f is even\n",number);    // displays output
}

else
{
   printf("%d is odd\n",number); //displays output
}
}



function related programs with types

function related programs with types


click below to see programs:
-----------------------------------------------------------------------------------------------

 FUNCTION WITH NO ARGUMENTS AND NO RETURN VALUES.


program to print smallest number among three numbers using function.

using codeblock
--------------------------------------------------------------------------------------------------------------------
//to print smallest number among three numbers using function.
#include<stdio.h>                      //header file
void smallest();                          // function prototype/declaration with return type zero.
int main()                              //main function
{
smallest();                                     // function calling.
return 0;                                       //returns 0 value
}
void smallest()                              // function body line ; also called function definition
{
 float number1,number2,number3;                    // variable declaration 
printf("enter three numbers\n");           // displays message to input data
scanf("%f%f%f",&number1,&number2,&number3);        // gets data from user.
if(number1>number2 &&number1>number3)                     //condition testing
{
printf("%f is greater\n",number1);    // displays output
}
else if(number2>number1 &&number2>number3)
{
    printf("%f is greater\n",number2);    // displays output for second condition
}
else
{
   printf("%f is greater\n",number3); 
}

}

--------------------------------------------------------------------------------------------------------------------------
using turbo C++
-----------------------------------------------------------------
//to print smallest number among three numbers using function.
#include<stdio.h>                      //header file
#include<conio.h>
void smallest();                          // function prototype/declaration with return type zero.
void main()                              //main function
{
smallest();                                     // function calling.
getch();                                       //returns 0 value
}
void smallest()                              // function body line ; also called function definition
{
 float number1,number2,number3;                    // variable declaration 
printf("enter three numbers\n");           // displays message to input data
scanf("%f%f%f",&number1,&number2,&number3);        // gets data from user.
if(number1>number2 &&number1>number3)                     //condition testing
{
printf("%f is greater\n",number1);    // displays output
}
else if(number2>number1 &&number2>number3)
{
    printf("%f is greater\n",number2);    // displays output for second condition
}
else
{
   printf("%f is greater\n",number3); 
}

}