Answer:
Answers are given below with appropriate comments for explanation
Step-by-step explanation:
1)
int min(int first, int second) //function which returns min value of given two values.
{
int answer;
if (first < second)
result = first;
else
result = second;
return result;
}
2)
#include<stdio.h>
void min(int first, int second) //function which returns min value of given two values.
{
int answer;
if (first < second)
result = first;
else
result = second;
printf("Result is = %d",result);
}
void main(){
int a1=5;
int a2=3;
min(a1,a2);//calling void function
}
3)
pass by value...just passing values..it won't reflect actual parameters
#include<stdio.h>
void min(int first, int second) //function which returns min value of given two values.
{
int answer;
if (first < second)
result = first;
else
result = second;
printf("Result is = %d",result);
}
void main(){
int a1=5;
int a2=3;
min(a1,a2);//calling void function
}
-----------------------------
pass by reference
-----------------------------
#include<stdio.h>
void min(int *first, int *second) //function which returns min value of given two values.
{
int answer;
if (first < second)
result = first;
else
result = second;
printf("Result is = %d",result);
}
void main(){
int a1=5;
int a2=3;
min(&a1,&a2);//calling void function
}
-----------------------------------------------------------------------------------------------------------------
4)
function prototype means declaring function declaration without body at top of program...actual function after main declaration.
#include<stdio.h>
void min(int first, int second); //function prototype declaration
void main(){
int a1=5;
int a2=3;
min(a1,a2);//calling void function
}
//actual function declaration
void min(int first, int second) //function which returns min value of given two values.
{
int answer;
if (first < second)
result = first;
else
result = second;
printf("Result is = %d",result);
}
---------------------------------------------------------------------------------
5)
int main(){
int global=5; //global variable
int n=1;
for(i=1;i<=n;i++){
int global =3; //local variable
printf("Local variable scope = %d",global); //it prints 3
}
printf("Global variable scope = %d",global); //it prints 5
}
---------------------------------------------------------------------------
6)
int main(){
int a[5] = {1,2,3,4,5}; //one dimensional array declaration
}
------------------------------------------
7)
int main(){
int array[5];
int i;
printf("Enter array values");
for(i=0;i<5;i++){
scanf("%d",&a[i]); //reading array values from user
}
}
8)
int main(){
int array[5];
int i;
printf("Enter array values");
for(i=0;i<5;i++){
scanf("%d",&array[i]); //reading array values from user
}
printf("Printing data of array entered");
for(i=0;i<5;i++){
printf("%d",array[i]); //Printing array values from user
}
----------------------------------------
9)
#include<stdio.h>
void printArray(int a[]){//array as parameter
int i;
printf("Printing data of array entered");
for(i=0;i<5;i++){ //printing data here
printf("%d",a[i]); //Printing array values from user
}
}
int main(){
int array[5];
int i;
printf("Enter array values");
for(i=0;i<5;i++){
scanf("%d",&array[i]); //reading array values from user
}
printArray(array); //passing array as parameter
}
--------------------------------------------------------------