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

Function programs (1)

Uploaded by

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

Function programs (1)

Uploaded by

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

Function programs

1) Function Arguments and Return Values


#include <stdio.h>

#include<conio.h>

void sum(int x, int y)

int c;

c = x + y;

return c;

void main()

int a = 3, b = 2;

int c = sum(a, b);

printf("Sum of %d and %d : %d", a, b, c);

return 0;

getch();

2) Function with No Arguments and No Return Value


#include <stdio.h>
#include<conio.h>
void sum()
{
int x, y;
printf("Enter x and y\n");
scanf("%d %d", &x, &y);
printf("Sum of %d and %d is: %d", x, y, x + y);
}
void main()
{
// function call
sum();
getch();
}
3) Function with No Arguments and With
Return
#include <stdio.h>
#include<conio.h>
void sum()
{
int x, y, s = 0;
printf("Enter x and y\n");
scanf("%d %d", &x, &y);
s = x + y;
return s;
}

int main()
{
// function call
printf("Sum of x and y is %d", sum());

getch();
}
4) Function With Arguments and No Return Value

#include <stdio.h>
#include<conio.h>
void sum (int x, int y)
{
printf("Sum of %d and %d is: %d", x, y, x + y);
}

void main()
{
int x, y;
printf("Enter x and y\n");
scanf("%d %d", &x, &y);

// function call
sum (x, y);

getch();
}

You might also like