Function Examples(Pass and No Return)

PASS AND NO RETURN

In Pass and no return, value(s) are passed from the calling function to the called function but no value is returned back from the called function to the calling function.

Question:1
Write a function C language to calculate and print square of a number?
Sol:

#include <stdio.h>

//function definition
void square(int n)
{
int s;
s=n*n;
printf("square = %d",s);
}
int main()
{
int a;
printf("Enter any no ");
scanf("%d",&a);
square(a);
return 0;
}

Question:2
Write a function C language to take input for 2 nos calculate and print their sum?
Sol:

#include <stdio.h>

//function definition
void sum(int n1,int n2)
{
int s;
s=n1+n2;
printf("sum = %d",s);
}
int main()
{
int a,b;
printf("Enter 2 nos ");
scanf("%d %d",&a,&b);
sum(a,b);
return 0;
}

C Language Programming Tutorial

C Language Tutorial Home     Introduction to C Language     Tokens     If Condition      goto statement and Labelname     Switch Statements     For loop     While Loop     Do while loop     break and continue     Functions     Recursion     Inbuild Functions     Storage Classes     Preprocessor     Arrays     Pointers     Structures and Unions     File Handling     Projects