0% found this document useful (0 votes)
26 views

Functions Example in C

The document contains two examples of functions in C programming. The first defines a function called "sum" that takes no arguments and returns the sum of two numbers input by the user. It demonstrates a function with no arguments but a return value. The second example defines another "sum" function that takes two integer arguments, adds them, and returns the result. It demonstrates a function that takes arguments and returns a value. Both functions are called within main to calculate the sum and print the result.

Uploaded by

Merwyn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Functions Example in C

The document contains two examples of functions in C programming. The first defines a function called "sum" that takes no arguments and returns the sum of two numbers input by the user. It demonstrates a function with no arguments but a return value. The second example defines another "sum" function that takes two integer arguments, adds them, and returns the result. It demonstrates a function that takes arguments and returns a value. Both functions are called within main to calculate the sum and print the result.

Uploaded by

Merwyn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

//Example for Function with no argument and with return value

#include<stdio.h>
#include<conio.h>

int sum();

void main()
{
int result;
printf("\nGoing to calculate the sum of two numbers:");
result = sum();
printf("\nsum=%d",result);
getch();
}

int sum()
{
int a,b;
printf("\nEnter two numbers:\n");
scanf("%d %d",&a,&b);
return a+b;
}

//Example for Function with argument and with return value


#include<stdio.h>
#include<conio.h>
int sum(int, int);
void main()
{
int a,b,result;
printf("\nGoing to calculate the sum of two numbers:");
printf("\nEnter two numbers:\n");
scanf("%d %d",&a,&b);
result = sum(a,b);
printf("\nThe sum is : %d",result);
getch();
}
int sum(int a, int b)
{
return a+b;
}

You might also like