![](/img/trans.png)
[英]main.cpp:22:34: error: ‘xxxxxxx’ was not declared in this > scope
[英]main.cpp|34|error: 'putere' was not declared in this scope| [and also verif_polim (functions)]
好的,这应该找到任何多项式 function 的根,但我得到了这个错误,我不明白为什么。 其他的工作完美。 aflare_radacini将问题分为两种情况。 第一个,如果 x^0*a 是否为 0。 gasire_rad_1用于 a[0] = 0 和div用于 a[0].= 0。
#include <iostream>
using namespace std;
void citire(int a[100], int& n)
{
cin >> n;
for (int i = n; i >= 0; i--) {
cin >> a[i];
}
}
void gasire_rad_1(int nr)
{
for (int d = 1; d <= nr / 2; d++) {
if (nr % d == 0) {
cout << d << " " << -d << " ";
}
}
}
void div(int nr, int n, int a[100])
{
for (int d = 1; d <= 0; d++) {
if (nr % d == 0) {
if (verif_polim(d, n, a) == 0) {
cout << d << " ";
}
if (verif_polim(-d, n, a) == 0) {
cout << -d << " ";
}
}
}
}
int verif_polim(int x, int n, int a[100])
{
int s = a[0];
for (int i = 1; i <= n; i++) {
int p = putere(x, i);
s += p * a[i];
}
}
int putere(int x, int val_putere)
{
int i = 1, b = 1;
while (i <= val_putere) {
b *= x;
i++;
}
return b;
}
void aflare_radacini(int a[100], int n)
{
if (a[0] == 0) {
int i = 1;
while (a[i] == 0) {
i++;
}
cout << 0 << " ";
if (a[i] < 0) {
a[i] *= -1;
}
gasire_rad_1(a[i]);
}
else {
div(a[0], n, a);
}
}
int a[100], n;
int main()
{
citire(a, n);
aflare_radacini(a, n);
return 0;
}
您需要先声明函数,然后才能调用它们,因此将putere
function 首先放在程序中,将verif_polim
function 第二放在程序中。
另请注意:根据声明verif_polim
应该返回一个int
- 但它不返回任何内容,因此您的程序将具有未定义的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.