呵呵,我的题目啊...我刚学C语言。。很多都不会。。5楼的太厉害我看不懂
我也尝试用C语言,请各位多多指点~~!!
数字的规律我用2个自定义的函数搞定,主函数输出格式
左图:
#include <stdio.h>
int num;
long i,j ;
long fun1(long x) ;
long fun2(long m,long n) ;
void main()
{ printf("please enter a number:");
scanf("%d",&num);
for(i=0;i<num;i++)
{
for(j=0;j<i+1;j++)
printf("%ld%c",fun2(i,j),' ');
printf("\n") ;
}
}
long fun1(long x)
{long f ;
if(x==1||x==0)
f=1;
else
f=fun1(x-1)*x;
return(f);
}
long fun2(long m,long n)
{
long c;
if(m<0||n<0)
printf("Error!Please enter again!");
else
c=fun1(m)/(fun1(n)*fun1(m-n));
return(c);
}
右图:(在左图基础上写的,貌似有问题,但我不知道哪里出问题)
#include <stdio.h>
int num;
long i,j,k ;
long fun1(long x) ;
long fun2(long m,long n) ;
void main()
{ printf("please enter a number:");
scanf("%d",&num);
for(i=0;i<num;i++)
{
for(j=0;j<i+1;j++)
{ for(k=0;k<num-1-i;k++)
printf(" ") ;
printf("%ld ",fun2(i,j));
}
printf("\n") ;
}
}
long fun1(long x)
{long f ;
if(x==1||x==0)
f=1;
else
f=fun1(x-1)*x;
return(f);
}
long fun2(long m,long n)
{
long c;
if(m<0||n<0)
printf("Error!Please enter again!");
else
c=fun1(m)/(fun1(n)*fun1(m-n));
return(c);
}
|