杭电ACM2032帮忙看下,WA啊wa
#include<stdio.h>intmain(void){intfactorial(int);intn,i,j,temp;while(scanf("%d",&n)!=...
# include <stdio.h>
int main(void)
{
int factorial(int);
int n,i,j,temp;
while(scanf("%d",&n) != EOF&&n>=1&&n <= 30)
{
for(i = 1;i <= n;i ++)
for(j = 1;j <=i;j ++)
{
temp = factorial(i-1)/(factorial(i - j)*factorial(j-1));
j != i?printf("%d ",temp):printf("%d\n",temp);
}
putchar('\n');
}
return 0;
}
int factorial(int n)
{
int i,temp;
if (n == 0) temp == 1;
for(i = 1,temp = 1;i <= n;i ++)
temp*=i;
return temp;
} 展开
int main(void)
{
int factorial(int);
int n,i,j,temp;
while(scanf("%d",&n) != EOF&&n>=1&&n <= 30)
{
for(i = 1;i <= n;i ++)
for(j = 1;j <=i;j ++)
{
temp = factorial(i-1)/(factorial(i - j)*factorial(j-1));
j != i?printf("%d ",temp):printf("%d\n",temp);
}
putchar('\n');
}
return 0;
}
int factorial(int n)
{
int i,temp;
if (n == 0) temp == 1;
for(i = 1,temp = 1;i <= n;i ++)
temp*=i;
return temp;
} 展开
1个回答
展开全部
兄弟,你的程序有的数据越界了!
我给你一个代码吧
#include<iostream>
using namespace std;
int main()
{
int a[30][100]={0},n,i,j;
a[0][1]=1;
for(i=1;i<30;i++)
for(j=1;j<=i+1;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
while(cin>>n)
{
for(i=0;i<n;i++)
{
for(j=1;j<=i+1;j++)
{
cout<<a[i][j];
if(j!=i+1)
cout<<" ";
}
cout<<endl;
}
cout<<endl;
}
}
我给你一个代码吧
#include<iostream>
using namespace std;
int main()
{
int a[30][100]={0},n,i,j;
a[0][1]=1;
for(i=1;i<30;i++)
for(j=1;j<=i+1;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
while(cin>>n)
{
for(i=0;i<n;i++)
{
for(j=1;j<=i+1;j++)
{
cout<<a[i][j];
if(j!=i+1)
cout<<" ";
}
cout<<endl;
}
cout<<endl;
}
}
追问
越界?练数组都没有,怎么越界?
还有我用的是C语言
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询