-
/* utilize a biblioteca matemática para obter essas fcs */
double sin (double a);
double pow (double m, double n);
double foo (float a[], int tam, int pot) {
double res = 0.0;
int i;
for (i=0;i<tam;i++)
res += pow (sin(a[i]), pot);
return res;
}
-
struct arv {
int val;
struct arv * fe;
struct arv * fd;
};
int somaval (struct arv *a) {
if (a == NULL)
return 0;
else
return somaval(a->fe)+somaval(a->fd)+a->val;
}
se quiser, use o seguinte programa principal bobo para testar essa função:
int main (void) {
struct arv a1, a2, a3, a4, a5, a6;
a1.fe = &a2; a1.fd = &a3; a2.fe = NULL; a2.fd = &a5; a3.fe = &a4; a3.fd = NULL;
a4.fe = &a6; a4.fd = NULL; a5.fe= NULL; a5.fd = NULL; a6.fe = NULL; a6.fd = NULL;
a1.val = a2.val = a3.val = a4.val = a5.val = a6.val = 1;
printf ("%d\n", somaval (&a1));
return 0;
}
-
#include <stdio.h>
#include <stdlib.h>
#define MAX 30
int crivoprimos (int n) {
int primos[MAX];
int qtos, div, cand, e_primo, soma;
qtos = 0; soma = 0;
for (cand = 2; cand<=n; cand++) {
e_primo = 1;
for (div=0; div<qtos; div++) {
if (cand % primos[div]==0) {
e_primo = 0;
break;
}
}
if (e_primo) {
primos[qtos] = cand;
soma += cand;
qtos++;
}
}
return soma;
}
int main (int argc, char* argv[]) {
printf("%d\n", crivoprimos(atoi(argv[1])));
return 0;
}