Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Function in C Programming Language

Posted on December 30, 2016December 26, 2019

Table of Contents

  • Function in C Programming Language
      • C functions
      •  1. Add two numbers using the function (No return without argument)
      •  2. Different two numbers using function (No return with argument)
      •  3 multiply  two numbers using the function (Return without argument)
      •  4 add  two numbers using function (Return with argument)

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

Function in C Programming Language
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

Function in C Programming Language
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);
}

Function in C Programming Language
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

Function in C Programming Language
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

Function in C Programming Language
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

Function in C Programming Language
Example
Example
Program 1
Function in C Programming Language
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
Structure with function in C Language                    Structure with function C++ Language
 Structure with pointer in C Language                     Structure with pointer in C++
                                            
 
Nested function  in C        

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes