or

5 Computer -- Programming II

Define function. Write a C program to calculate sum of two numbers using user-defined function.

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;

}

More questions on Programming II

Differentiate between structure and union.

Structures in C is 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 a structure, you must use the struct statement. The struct statement defines a new data 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;...
Close Open App