Functions in C

A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions.

Source code :

#include<stdio.h>
float square ( float x ); //function declaration                              

int main( ) // main function              
{
    float m, n ;
    printf ( "\nEnter some number for finding square \n");
    scanf ( "%f", &m ) ;
    n = square ( m ) ; // function call                     
    printf ( "\nSquare of the given number %f is %f",m,n );
}
 
float square ( float x )   // function definition
{
    float p ;
    p = x * x ;
    return ( p ) ;
}

Output :

Enter some number for finding square
2
Square of the given number 2.000000 is 4.000000

Algorithm :

  1. Declare a function.
  2. Make function call in main function.
  3. Define the function.

Output :


                

Comments :