主页 > 科技生活 >克莱斯勒破产_国二C语言程序设计考试,填空题如果不小心按了一下空格键加了一行会怎样? >

克莱斯勒破产_国二C语言程序设计考试,填空题如果不小心按了一下空格键加了一行会怎样?

国二C语言程序设计考试,填空题如果不小心按了一下空格键加了一行会怎样?
系统应该会自动过滤掉空格的,正常的程序应该是这样的。
我在考国二c语言程序设计的时候,后面编程题都与要求相符,但还是不及格,为什么??? 求大佬帮帮忙
替你考试吗?
国二C语言编程题:输入两个数,求最大公约数。
单式
main()
{
int m, n, i, r;
printf("input two numbers\n");
scanf("%d%d", &m, &n);
if(m < 0) m *= -1;
if(n < 0) n *= -1;
for(i = ((m>n?n:m) - 1); ; i --)
if(m%i == 0 && n % i == 0) break;
printf("the result is %d\n", i);
}// 输入两个数m和n, 求其最大公约数.
// 用辗转相求最大公约数
// 算法描述: m对n求余a, 若a不0 则 m <- n, n <- a, 继续求余
// 否则 n 为最大公约数

#include

int main()
{
int m, n; int m_cup, n_cup, res; /*被除数, 除数, 余数*/
printf("Enter two integer:\n");
scanf("%d %d", &m, &n);
if (m > 0 && n >0)
{
m_cup = m;
n_cup = n;
res = m_cup % n_cup;
while (res != 0)
{
m_cup = n_cup;
n_cup = res;
res = m_cup % n_cup;
}
printf("最大公约数: %d\n", n_cup);
}
else
{
printf("Error!\n");
}
return 0;
}本回答被网友采纳

#include

intmain(){intmain_1(intx,inty,intz);inta,b,min,m;printf("pleaseentertwointegernumbers: ");scanf("%d%d",&a,&b);min=(a>b)?b:a;m=main_1(a,b,min);if(m==0) printf("a,b没有最约数! ");elseprintf("a,b的公约数%d ",m);return0;

}

intmain_1(intx,inty,intz){inti,m=0;for(i=z;i>1;i--){if(x%i==0&&y%i==0) {m=i;break;}}returnm;}

本回答被提问者采纳int main()
{
int a,b;
int i,x,r;
printf("a b :");
scanf("%d%d",&a,&b);
if(aelse x=b;
for(i=1;i<=x;i++)
if(a%i==0&&b%i==0)
r=i;
printf("%d",r);
}来自:求助得到的回答#include

void main()
{

int a,b;
scanf("%d%d",&a,&b);
int i;
i = (afor(;i>0;i--)
{
if((a%i == 0) && (b%i == 0))
{
printf("%d,%d大公是%d\n",a,b,i);
break;
}
}
}
国二C语言编程题:输入a、b的值,若a=123,b=456,则重新组数,c=654321
#include

void main()
{

int a,b;
long c=0;
int i;
scanf("%d%d",&a,&b);
while(b)
{
i = b%10;
c = c*10+i;
b = b/10;
}
while(a)
{
i = a%10;
c = c*10+i;
a = a/10;
}
printf("%ld\n",c);
}#include
#include
#include
#include
void main()
{
char a[10] = {0}, b[10] = {0}, acResult[20] = {0};
int acaNum, acbNum;
cout<<"input a:";
cin>>a;
cout<<"input b:";
cin>>b;
acaNum = strlen(a);
acbNum = strlen(b);
cout<<"a = "< cout<<"b = "< sprintf(acResult, "%s%s",a, b);
int sumLen = strlen(acResult) - 1; // 除去'\0'
for(int i = 0;i <= sumLen/2; i++)
{
char temp = acResult[i];
acResult[i] = acResult[sumLen - i];
acResult[sumLen - i] = temp;
}
cout<<"acResult = "<}#define MAX 100 // 的最大长度
int formatNum(int a, int b)
{
int numC[MAX], result_C = 0;
int maxA = 0, maxB = 0, index = 0;
while(1)
{
if ( a != 0 )
{
numC[index] = a % 10;
a = a / 10;
index ++;
}
if ( b != 0)
{
numC[index] = b % 10;
b = b / 10;
index ++;
}
if ( 0 == a && 0 == b)
{
break;
}
}
int one_index, two_index;
for ( one_index = 0; one_index < index; one_index++ )
{
for ( two_index = one_index + 1; two_index < index; two_index++ )
{
if ( numC[one_index] < numC[two_index] )
{
int mid = numC[one_index];
numC[one_index] = numC[two_index];
numC[two_index] = mid;
}
}
}
int result_index;
for ( result_index = 0; result_index < index; result_index++ )
{
result_C = result_C * 10 + numC[result_index];
}
return result_C;
}
void main()
{
int a, b;
printf("please input first num:\n");
scanf("%d", &a);
printf("please input first num:\n");
scanf("%d", &b);
printf("the result is : %d\n", formatNum(a, b));
}

/* 可接收任意长度的两个大小不限,得到结从大到小得出
比如: 输a 5768输入b 13429得到输出 987654321 */



上一篇: 下一篇: