Lab6_2025
Lab6_2025
Printing text using user defined function: Passing argument and printing its value:
#include<stdio.h> #include<stdio.h>
void Display(); void printValue(int n);
int main() int main()
{
{
printValue(100);
Display(); printValue(25);
return 0; return 0;
} }
void Display() void printValue(int n)
{ {
printf("Hello Wolrd!\n"); printf("The number is %d\n", n);
}
}
#include<stdio.h> #include<stdio.h>
int main() int main()
{ {
int n; int n,sum=0;
printf("Enter the length of Array:"); printf("Enter the length of Array:");
scanf("%d",&n); scanf("%d",&n);
int a[n]; int a[n];
for(int i=0;i<n;i++) for(int i=0;i<n;i++)
{ {
scanf("%d",&a[i]); scanf("%d",&a[i]);
} }
for(int i=0;i<n;i++) for(int i=0;i<n;i++)
{ {
printf("a[%d]= %d\n",i,a[i]); sum=sum+a[i];
} }
return 0; printf("The sum is: %d",sum);
} return 0;
}
Passing arrays as function arguments:
2. Write the function int computeAverage(int a, int b) which takes 2 integers as input and return
their average. Call the function from main, store the average returned by the function and print it.
3. Write a program that takes 5 integers as input, stores them in an array and prints them in the
reverse order of the input.
Sample Output:
4. Write a program that takes 5 integers as input, stores them in an array and finds the highest number in
the array.
Sample Output: