Here is the whole program for the removal of Fibonacci numbers, but a problem has arisen that the negative elements are also being output in the array, but I don’t get it .....
#include <vcl.h> #include <iostream.h> #include <stdlib.h> #include <conio.h> char* Rus(const char* text); int fibonacci (int, int [100]); int main(){ srand(time(NULL)); int a[100]; int n,i,j; int fibonacci (int, int [100]); cout <<Rus("Введите количество элементов: ") << endl; cin>>n; cout << Rus("Исходный массив: ")<< endl; for (i=0;i<n;i++) { a[i]=rand()%30+5; rand()%100-rand()%100; cout << a[i]<<" "; } fibonacci (n, a); getch(); } int fibonacci (int n, int a[100]) { int q[100]; int max, g, b,i,j,c; max=a[0]; for (i=1;i<n;i++) { if (max<a[i]) max=a[i]; } g=0; b=1; for (i=0;b<=max;i++) { c=g+b; g=b; b=c; q[i]=b; } cout << endl; cout << endl; cout << Rus("Ряд Фибоначчи: ")<< endl; for (j=0;j<i;j++) cout<< q[j] << " "; for (i=0;i<max;i++) for (j=0;j<n;j++) if (q[i]==a[j]) { for (b=j;b<n-1;b++) a[b]=a[b+1]; n=n-1; j--; } cout << endl; cout << Rus("Новый массив: ")<< endl; for (i=0;i<n;i++) cout<<a[i]<<" "; return 0; } char bufRus[256]; char* Rus(const char* text) { CharToOem(text,bufRus); return bufRus; }