我如何得到jmoisjdg09sjfepokf09serkperklf-ekf [英] How do I get that jmoisjdg09sjfepokf09serkperklf-ekf
问题描述
#include < iostream >
使用 命名空间标准;
int fact( int );
int main()
{
int a = 5 ,b;
b =事实(a);
cout<< b;
return 0 ;
}
int fact( int );
{
int a = 6 ,b;
b =事实(a);
cout<< b;
return 0 ;
}
int fact( int n)
{
int i = 1 ,j = 1 跨度>;
while (i< = n)
{
j = j * i;
i = i + 1;
}
return j;
}
我的尝试:
它在{标记之前显示预期的非限定标识
{
Quote:int fact(int);
{
int a = 6,b;
b =事实(a);
cout<< b;
返回0;
}
在这么多层上这是完全错误的...
如果删除它,你的代码虽然没有美观,但也能正常工作。
您正在声明一个名为fact
的前向引用函数:
< span class =code-keyword> int fact( int );
你不能给那个身体,或者它不会是一个前向引用!
删除正文(以及前面的引用,因为你有两次),然后你的代码将被编译:
#include < iostream >
使用 namespace std;
int fact( int );
int main()
{
int a = 5 ,b;
b =事实(a);
cout<< b;
return 0 ;
}
int fact( int n)
{
int i = 1 ,j = 1 跨度>;
while (i< = n)
{
j = j * i;
i = i + 1 ;
}
return j;
}
但是,我用替换
:而
循环forint fact(int n)
{
int j = 1;
for(int i = 1; i< = n; i ++)
{
j = j * i;
}
返回j;
}
#include<iostream>
using namespace std;
int fact(int);
int main()
{
int a=5,b;
b=fact(a);
cout<<b;
return 0;
}
int fact(int);
{
int a=6,b;
b=fact(a);
cout<<b;
return 0;
}
int fact(int n)
{
int i=1,j=1;
while(i<=n)
{
j=j*i;
i=i+1;
}
return j;
}
What I have tried:
it showing expected unqualified-id before ‘{’ token
{
Quote:int fact(int);
{
int a=6,b;
b=fact(a);
cout<<b;
return 0;
}
That is completely wrong on so many layers...
If you remove that, your code, though no beautiful, will work.
You are declaring a "forward reference" function calledfact
:
int fact (int);You can't give that a body, or it wouldn't be a forward reference!
Remove the body (and the foreward reference, since you have it twice), and your code will then compile:
#include<iostream> using namespace std; int fact (int); int main () { int a = 5, b; b = fact (a); cout << b; return 0; } int fact (int n) { int i = 1, j = 1; while (i <= n) { j = j * i; i = i + 1; } return j; }
But, I'd replace thewhile
loop with afor
:int fact (int n) { int j = 1; for (int i = 1; i <= n; i++) { j = j * i; } return j; }
这篇关于我如何得到jmoisjdg09sjfepokf09serkperklf-ekf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!