Napište v jazyku C funkci double *map(double (*fce)(double), double *vstup, int delka), která na hodnoty pole vstup (definiční obor) aplikuje funkci fce a vrátí pole výsledných hodnot. Velikost definičního oboru je specifikována parametrem delka.
Příklad použití:
double na2(double x){
return x*x;
}
double na3(double x){
return x*x*x;
}
int main(){
...
pole_vysledku_na2 = map(na2, vstup,5)
...
pole_vysledku_na3 = map(na3, vstup,5)
...
}
Příklad výstupu:
Vstupni pole: 1, 2, 3, 4, 5
Druhe mocniny: 1, 4, 9, 16, 25
Treti mocniny: 1, 8, 27, 64, 125
Povolené knihovny: stdio.h, stdlib.h, math.h
Fórum › C / C++
Mapování

A já sem se dostal někam sem, a potřebuju jak zařídit aby to pole co mám naplněné se umocnilo na2. díky za rady.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double na2 (double x){
return x*x;
}
double na3 (double x){
return x*x*x;
}
double *map(double (*fce)(double), double *vstup, int delka)
int main()
{
int i;
int pole[5];
printf("Vstupni pole: ");
for (i=0; i<5; i++){
pole[i]= i+1;
}
for (i=0; i<5; i++){
printf("%i, ", pole[i]);
}
printf("\nDruhe mocniny: ");
printf("\nTreti mocniny: ");
system("PAUSE");
return 0;
}
No, to si sa vlastne nedostal nikam, lebo cieľom je funkcia z ktorej nemáš nič.
Ale je to jednoduché: v tej funkcii budeš mať len cyklus, ktorý preiteruje všetky prvky pola a to takto: vystup[i] = fce(vstup[i]);
Najprv si ale musíš alokovať výstupné pole kde tie výsledky uložíš. To pole potom vrátiš ako výsledok

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 114 hostů
Podobná vlákna
Mapování na přechod — založil Jiří Chytil
Testing mapovani dat na object — založil boom
Moderátoři diskuze