Table of Contents
In this tutorial, we will discuss of the Function in C Programming Language
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
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
Two type of function available in C Programming.
4 type of function available in C Language
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);
}
#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
#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
#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
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.