w3resource logo
C Programming Exercises

C Exercises: A simple structure of function

C Function : Exercise-1 with Solution

Write a program in C to show the simple structure of a function.

Sample Solution:

C Code:

#include <stdio.h>

    int sum (int, int);//function declaration
    int main (void)
    {
        int total;
		printf("\n\n Function : a simple structure of function :\n");
		printf("------------------------------------------------\n");	
        total = sum (5, 6);//function call
        printf ("The total is :  %d\n", total);
        return 0;
    }
    
    int sum (int a, int b) //function definition
    {
	    int s;
		s=a+b;
        return s; //function returning a value
    }

Sample Output:

 Function : a simple structure of function :
------------------------------------------------
The total is :  11

C Programming Code Editor:

#include <stdio.h>

    int sum (int, int);//function declaration
    int main (void)
    {
        int total;
		printf("\n\n Function : a simple structure of function :\n");
		printf("------------------------------------------------\n");	
        total = sum (5, 6);//function call
        printf ("The total is :  %d\n", total);
        return 0;
    }
    
    int sum (int a, int b) //function definition
    {
	    int s;
		s=a+b;
        return s; //function returning a value
    }

Improve this sample solution and post your code through Disqus.