C语言编程题,高分求解。
题目链接:http://wenku.baidu.com/view/c166d7070740be1e650e9a68.html#include<stdio.h>intfou...
题目链接: http://wenku.baidu.com/view/c166d7070740be1e650e9a68.html
#include<stdio.h>
int found(int a[][30],int n)
{
int i,j,sum,k,count=0;
for(i=1;i<=n;i++)
{
sum=0;
for(j=i;(sum<n)&&(j<=n);j++)
sum+=j;
if(sum==n)
{
for(k=0;k<=j-i;k++)
a[count][k]=i++;
count++;
}
return count;
}
}
void main()
{
int a[10][30],n,k,i,j;
FILE *fp;
fp=fopen("myf2.out","w");
if(fp==NULL)
{
printf("Cannot open the file.\n");
exit(0);
}
scanf("%d",&n);
k=found(a,n);
for(i=0;i<k;i++)
for(j=0;j!='\0';j++)
{
printf("%d ",a[i][j]);
fprintf(fp,"%d ",a[i][j]);
printf("\n");
fprintf(fp,"\n");
}
fprintf(fp,"\nmy exam number is: \n");
} 展开
#include<stdio.h>
int found(int a[][30],int n)
{
int i,j,sum,k,count=0;
for(i=1;i<=n;i++)
{
sum=0;
for(j=i;(sum<n)&&(j<=n);j++)
sum+=j;
if(sum==n)
{
for(k=0;k<=j-i;k++)
a[count][k]=i++;
count++;
}
return count;
}
}
void main()
{
int a[10][30],n,k,i,j;
FILE *fp;
fp=fopen("myf2.out","w");
if(fp==NULL)
{
printf("Cannot open the file.\n");
exit(0);
}
scanf("%d",&n);
k=found(a,n);
for(i=0;i<k;i++)
for(j=0;j!='\0';j++)
{
printf("%d ",a[i][j]);
fprintf(fp,"%d ",a[i][j]);
printf("\n");
fprintf(fp,"\n");
}
fprintf(fp,"\nmy exam number is: \n");
} 展开
展开全部
#include<stdio.h>
int found(int a[][30],int n)
{
int i,j,sum,k,x,y,count=0;
for(x=2*n;x>0;x--)
{
if(2*n%x)continue;
else y=(2*n/x+1-x);
if((y%2)||(y<=0))continue;
for(i=0,y/=2;i<x;i++)a[count][i]=y+i;
count++;
}
return count;
}
int main()
{
int a[10][30]={0},n,k,i,j;
FILE *fp;
fp=fopen("myf2.out","w");
if(fp==NULL)
{
printf("Cannot open the file.\n");
return 0;
}
printf("m=");
scanf("%d",&n);
k=found(a,n);
for(i=0;i<k;i++)
{
for(j=0;a[i][j]!=0;j++)
{
printf("%d ",a[i][j]);
fprintf(fp,"%d ",a[i][j]);
}
printf("\n");fprintf(fp,"\n");
}
printf("my number is: 11234567\n");
fprintf(fp,"my number is: 11234567\n");
fclose(fp);
}
主要是根据等差数列的计算公式处理的,不多解释了,求赏金
int found(int a[][30],int n)
{
int i,j,sum,k,x,y,count=0;
for(x=2*n;x>0;x--)
{
if(2*n%x)continue;
else y=(2*n/x+1-x);
if((y%2)||(y<=0))continue;
for(i=0,y/=2;i<x;i++)a[count][i]=y+i;
count++;
}
return count;
}
int main()
{
int a[10][30]={0},n,k,i,j;
FILE *fp;
fp=fopen("myf2.out","w");
if(fp==NULL)
{
printf("Cannot open the file.\n");
return 0;
}
printf("m=");
scanf("%d",&n);
k=found(a,n);
for(i=0;i<k;i++)
{
for(j=0;a[i][j]!=0;j++)
{
printf("%d ",a[i][j]);
fprintf(fp,"%d ",a[i][j]);
}
printf("\n");fprintf(fp,"\n");
}
printf("my number is: 11234567\n");
fprintf(fp,"my number is: 11234567\n");
fclose(fp);
}
主要是根据等差数列的计算公式处理的,不多解释了,求赏金
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询