I'm trying to solve this task: "Write a bool sparse function (polynomial p) that takes polynomial p and returns true if 50% or more of the coefficients of polynomial p equals 0."
I use header file from my university.
#include <iostream>
#include "polinomATP.h" // header file
using namespace std;
bool sparse(polinom p);
int main(){
polinom p;
int d;
cout << "Upisi najveci stupanj polinoma: "<<endl; // enter poly degree
cin>>d;
for(int i=0; i<=d; i++){
cout<<"Upisi " << i <<". koeficijent: "<<endl; //enter coef.
int k;
cin>>k;
Attach(&p, i, k);
}
cout<<sparse(p);
system("pause");
}
bool sparse(polinom p){
int sum=0;
for(int i=0; i<=Degree(p); i++){
if(Coef(p, i)==0){
sum++;
}
}
if(sum>Degree(p)/2){
cout<<"yes";
return true;
}
}
I'm not really good with bool functions so I guess I'm doing something wrong there. Thank you!