Guião laboratorial n.º 0 – exercício 1
“Desenvolva uma função que encontre o maior elemento armazenado num vetor de inteiros. A
função recebe como argumentos o nome e a dimensão do vetor. Devolve como resultado o maior
valor existente no vetor.”
#include <stdio.h> #include <stdlib.h> #define TAM 10 int funcao1(int v[TAM], int t){ int maior=v[0]; int i; for(i=0; i<t; i++){ if(v[i]>maior) { maior=v[i]; } } return maior; } int main() { int vector[TAM]={0,1,20,3,4,5,6,7,8,9}; printf("o maior vem: %d", funcao1(vector, TAM)); return 0; }
Tags : Learn C, possível solução
0 thoughts on “Guião laboratorial n.º 0 – exercício 1”