# Thread: Help programs with functions "third year secondary school"

1. ## Help programs with functions "third year secondary school"

Hi, i'm new to this forum.
I attend the third year of secondary school.
today the teacher explained the functions but i didn't understand very well. kindly help me to carry out these programs in c. I use DevC++.

1- Calculate the sum and average of two vectors containing 5 integers. Compare the values ​​of the average viewing an appropriate message.
-Parameters of the average (sum, n_ele)
-Program with refunds

Thanks !

An example of my programs
Code:
```#include <stdio.h>
#include <stdlib.h>
void Doppio (int n);
void Triplo (int n);
int main(void) {
int n;
printf("immetti n ");
scanf("%d",&n);
Doppio(n);
Triplo(n);
system("pause");
}
void Doppio (int n) {
int Doppio;
Doppio=n*2;
printf("Il Doppio e' %d\n", Doppio);
return;
}
void Triplo (int n) {
int Triplo;
Triplo=n*3;
printf("Il Triplo e' %d\n", Triplo);
return;
}```

2. Parameters of the average (sum, n_ele)
Okay, so:

Code:
`int average (int sum, int n);`
Where "sum" is the total of the values in the vector, and n is the number of values in the vector. The function returns an int. The definition is about 2-3 lines at most. I'm sure you've done enough math to figure out what they should be.

3. Thanks for the answer
This is the program, how do you think, it's ok?

Code:
```#include <stdio.h>
#include <stdlib.h>
float media (float s, int n);
float media2 (float s2, int n);
main () {
int n=5, i, v[n], v2[n], st;
float s=0, s2=0;
for(i=0; i<n; i++) {
printf("Enter numbers first vector ");
scanf("%d",&v[i]);
}
for(i=0; i<n; i++) {
printf("Enter numbers second vector ");
scanf("%d",&v2[i]);
}
for(i=0; i<n; i++) {
s=s+v[i];
}
for(i=0; i<n; i++) {
s2=s2+v2[i];
}
st=s+s2;
printf("the sum of two vectors is %d\n",st);
media(s,n);
media2(s2,n);
if(media>media2) {
printf("The average of the first carrier is greater than the average of the second vector\n");
}
else {
printf("The average of the second carrier is greater than the average of the first vector\n");
}
system("pause");
}
float media (float s, int n) {
float media;
media=s/5;
printf("The average of first vector is %.2f\n",media);
return media;
}
float media2 (float s2, int n) {
float media2;
media2=s2/5;
printf("The average of second vector is %.2f\n",media2);
return media2;
}```

Popular pages Recent additions