Chapter 2 - Basic of c - Function in c
Chapter 2 - Basic of c - Function in c
D ATA S T R U C T U R E a n d A L G O R I T H M S
#include <stdio.h>
//function definition – return-type function
int sum(int a, int b)
{
return a+b;
}
int main()
{
int x,y,z;
printf("Nhap gia tri x,y: ");
scanf(“%d%d”, &x, &y);
z = sum(x,y); //function call
printf("\nz = %d ",z);
return 0;
}
2.4 FUNCTION:
#include <stdio.h>
//function definition – return-type function
int sum(int a, int b)
{
printf(“Ket qua: %d”, a+b);
}
int main()
{
int x,y,z;
printf("Nhap gia tri x,y: ");
scanf(“%d%d”, &x, &y);
sum(x,y); //function call
return 0;
}
2.4 FUNCTION:
⚬ And if the return-function, then you can store the returned value
with a variable.
variable = Function_name (value1, value2,…);
2.4 FUNCTION:
⚬ Note:
⚬ Function call is neccessary to bring the program control to the
function definition. If not called, the function statements will not be
executed.
2.4 FUNCTION:
return 0;
}
2.4 FUNCTION:
return 0;
}
2.4 FUNCTION:
return 0;
}
2.4 FUNCTION: