W przykładowym kolokwium znalazłem taki program, a raczej funkcję do napisania
Tworzaca nowa tablice (nazwijmy ja np. B) na podstawie tablicy (nazwijmy ja np. A) wg
nastepujacego wzoru:
B[i]=A[0] + A[1]/1 + A[2]/(1-2) + A[3]/(1-2+3)+..A[i]/(1-2+3-..i)
nastepujacego wzoru:
B[i]=A[0] + A[1]/1 + A[2]/(1-2) + A[3]/(1-2+3)+..A[i]/(1-2+3-..i)
Zerknalby ktos gdzie jest błąd?
#include <iostream>
using namespace std;
void newtab(float t1[], float t2[], int ile);
main ()
{
float A[5];
float B[5]={1,2,3,4,5};
newtab(A, B, 5);
for (int i=0; i<5; i++)
{
cout << A[i] << endl;
}
}
void newtab(float tnew[], float told[], int ile)
{
int i;
float wyr=0;
int s=0;
for (i=1; i<ile; i++)
if(i%2==0)
{
s=s-1;
}
else
{
s=s+1;
}
wyr = told[i]/s;
tnew[i] = told[i-1] + wyr;
}
using namespace std;
void newtab(float t1[], float t2[], int ile);
main ()
{
float A[5];
float B[5]={1,2,3,4,5};
newtab(A, B, 5);
for (int i=0; i<5; i++)
{
cout << A[i] << endl;
}
}
void newtab(float tnew[], float told[], int ile)
{
int i;
float wyr=0;
int s=0;
for (i=1; i<ile; i++)
if(i%2==0)
{
s=s-1;
}
else
{
s=s+1;
}
wyr = told[i]/s;
tnew[i] = told[i-1] + wyr;
}
Zakładki