Define function. Write a C program to calculate sum of two numbers using user-defined function.
A function in C is a block of code that performs a specific task. It is a reusable code module that can be called by other parts of a program. Functions help in modular programming, where complex programs are divided into smaller, simpler parts that can be easily understood and maintained.
OUPUT:
enter two number 4 5
the sum of two numbers is 9
PROGRAMS:
#include<stdio.h>
int sum(int*,int*);
int main()
{
int a,b;
printf("enter two number ");
scanf("%d%d",&a,&b);
int c=sum(&a,&b);
printf("the sum of two numbers is %d",c);
}
int sum(int *a,int *b)
{
int c=*a+*b;
return c;
}
Structures in Cis a user-defined data type available in C that allows to combining of data items of different kinds. Structures are used to represent a record.
Defining a structure:To define astructure, you must use thestructstatement. The struct statement defines a newdata type, with more than or equal to one member. The format of the struct statement is as follows:
struct [structure name] { member definition; member definition; ... member definition; }; (OR) struct [structure name] { member...