w3resource logo


C Programming Exercises

C Exercises: A simple structure of function

Secondary Nav

C Function : Exercise-1 with Solution

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

The total is :  11  

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
    }

C Practice online:


#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.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number