解题思路:
还是for循环和标志变量的使用
注意事项:
参考代码:
要善于调适
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,c,d;
int sum;
int n;
int arr[100];
int temp;
int temp1,temp2,temp3;
int i;
while(~scanf("%d %d",&a,&b))
{
//下
sum=0;
n=1;
temp=1;
while(a!=0)
{
if(a>=b)
{
temp2=b;
while(temp2!=0)
{
sum=sum+2+(n-1)*2;
temp2--;
n++;
}
arr[temp]=sum/b;
temp++;
sum=0;
a=a-b;
}
else
{
temp1=a%b;
temp3=temp1;
// printf("!!!!!!!!!!!!!!!!!!!!!!!!!\n");
while(0!=temp1)
{
sum=sum+2+(n-1)*2;
temp1--;
n++;
}
arr[temp]=sum/temp3;
temp++;
sum=0;
a=0;
}
}
// printf("!!!!!!!!!!!!!!!!!!!!!!!!!\n");
for( i=1;i<temp;i++)
{
if(i==temp-1)
{
printf("%d\n",arr[i]);
}
else {
printf("%d ",arr[i]);
}
}
}
return 0;
}
0.0分
0 人评分
C语言训练-舍罕王的失算 (C++代码)(都给答案了还算什么)浏览:992 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:399 |
简单的a+b (C语言代码)浏览:747 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:723 |
回文数字 (C语言代码)浏览:2536 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:561 |
陶陶摘苹果2 (C语言代码)浏览:649 |
A+B for Input-Output Practice (I) (C语言代码)浏览:449 |
简单的a+b (C语言代码)浏览:614 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:813 |