C Language

Function in C Programming Language

Function in C Programming Language

In this tutorial, we will discuss of the Function in C Programming Language

C functions

In the tutorial, We learn how to use functions in C language. generally, the function is a block of statement that together perform one of the specific tasks in C language similar to any programming languages etc java(called methods), C++(called methods)

Syntex in the function of C programming

Syntax

return_type: The return_type is a data type of the value returned by the function. when use void data type, it never returns any value but any data type return the value eg – int

function_name:funtion_name helps to identify the function in C Programming. Every function should be a name because the function_name represent the unique function and function_name  use to call the function to need

parameter list: a function may contain a parameter and some functions may contain no parameter (it is optional) however when a funtion is invoked, pass a value to the parameter of the parameter list refer to the parameter type, parameter order, and number of parameters of the function.

Body of the function – the body of the function consist of group of statements that will be invoked when this function is called. Because a function contains a set of statements of for the unique purpose. we can call any function to my need of a group of the function of the program

Explanation of function

Two type of function available in C Programming.

  • Standard library function – pre-drfine function  – Already define and included compiler in C programming
  • uder defined function – a function define the user to need

4 type of function available in C Language

  1. No return without argument
  2. No return with argument
  3. Return without argument
  4. Retunn with argment
Eg –
void add(); – //No return without argument
void sub(int,int); – //No return with argument
int mul(); – //Return without argument
float div(int,int); –  //Return with argument

 

1. Add two numbers using the function (No return without argument)

Program 1

#include <stdio.h>
#include <stdlib.h>
void main()
{
add();
return 0;
}
void add()
{
int a,b,c;
printf(“n Enter first number”);
scanf(“%d”,&a);
printf(“n Enter second number”);
scanf(“%d”,&b);
c=a+b;
printf(“Total value of c:%d”,c);
}

Example

 

2. Different two numbers using function (No return with argument)

program 2
#include <stdio.h>
#include <stdlib.h>
void main()
{
    sub();//function call

    return 0;
}
void sub(int a,int b)
{
    printf("Enter first numbern");
    scanf("%d",&a);
    printf("Enter second numbern");
     scanf("%d",&b);
     int c;
     c=a-b;
    printf("Total value of c:%d",c);
}

 

When the above code is executed it producesthe  following result

Example

 

 

3 multiply  two numbers using the function (Return without argument)

Program 3
#include <stdio.h>
#include <stdlib.h>
int main()
{
    printf("mul total: %d",mul());
    return 0;
}
int mul()
{
    int a,b,c;
    printf("Enter first numbern");
    scanf("%d",&a);
    printf("Enter second numbern");
     scanf("%d",&b);
     c=a*b;
    return(c);
}

 

When the above code is executed it producesthe  following result

Example

 

4 add  two numbers using function (Return with argument)

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int result;
    result=add(100,50);
    printf("the result is :%d",result);
    return 0;
}
int add(int a,int b){
int temp;
temp=a+b;
return temp;

}

When the above code is executed it producesthe  following result

Example
Example
Program 1
Example
When the above code is executed it producesthe  following result
Enter three marks of students
56
67
78
sum=201
Related post
Structure in C Language                                       Structure in C++ Language
                                       
Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

9 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

10 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

10 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

10 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

10 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

10 months ago

This website uses cookies.