C 3位整数程序赢得';不执行

C 3位整数程序赢得';不执行,c,C,是的,这是一个基本的C代码作业问题。不,我不是在找人帮我做。考虑到这是我的第一节编程课,我并不惊讶我不能让它工作,而且我确信它有很多错误。我只是想得到一些帮助,指出我代码中的问题和缺少的东西,这样我就可以自己修复它们了 作业问题: 编写一个只读取一个整数的程序(您的输入必须是 一个3位数字(从100到999),并将一个数字视为 是ABC(其中A、B和C是数字的3位数字)。现在, 将编号改为ABC、BCA和CAB,然后找出 这三个数除以11后的剩余数。 假设余数分别是X、Y和Z,并将它们相加 加起

是的,这是一个基本的C代码作业问题。不,我不是在找人帮我做。考虑到这是我的第一节编程课,我并不惊讶我不能让它工作,而且我确信它有很多错误。我只是想得到一些帮助,指出我代码中的问题和缺少的东西,这样我就可以自己修复它们了

作业问题:

编写一个只读取一个整数的程序(您的输入必须是 一个3位数字(从100到999),并将一个数字视为 是ABC(其中A、B和C是数字的3位数字)。现在, 将编号改为ABC、BCA和CAB,然后找出 这三个数除以11后的剩余数。 假设余数分别是X、Y和Z,并将它们相加 加起来是X+Y,Y+Z,Z+X。现在如果这些总和中的任何一个是奇数 数字,如果总和加11小于20,则增加11, 否则,将总和减少11(此总和运算 必须为正数但小于20)。最后,将每一部分分开 总数的一半。现在,打印出所有结果数字

我的代码:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    //Declare all variables
    int OrigNumber;
    int x, y, z;
    int number;
    number = x, y, z;
    int sum;
    //
    printf("Input a three digit number");
    //
    int c;
    c = OrigNumber %10;
    //
    int b;
    b=((OrigNumber - c) % 100)/10;
    //
    int a;
    a = (OrigNumber - (b + c))/100;
    //
    int abc, bca, cab;
    abc = (a*100) + (10*b) + c;
    bca = (10*b) + c + (a*100);
    cab = c + (a*100) + (10*b);
    //
    if((number % 2) == 1)
        {
            if(number + 11 < 20)
                number += 11;
            else if((100 - 11 > 0) && (100 - 11 < 20))
                number -= 11;
        }
    //
    x = abc/11;
    y = bca/11;
    z = cab/11;
    //
    sum = (x + y),
          (y + z),
          (z + x);
}
#包括
#包括
#包括
int main()
{
//声明所有变量
int-OrigNumber;
int x,y,z;
整数;
数字=x,y,z;
整数和;
//
printf(“输入三位数字”);
//
INTC;
c=原始编号%10;
//
int b;
b=((原编号-c)%100)/10;
//
INTA;
a=(原编号-(b+c))/100;
//
国际abc、bca、cab;
abc=(a*100)+(10*b)+c;
bca=(10*b)+c+(a*100);
cab=c+(a*100)+(10*b);
//
如果((数字%2)=1)
{
如果(数字+11<20)
数字+=11;
如果((100-11>0)和&(100-11<20))
数字-=11;
}
//
x=abc/11;
y=bca/11;
z=cab/11;
//
总和=(x+y),
(y+z),
(z+x);
}

首先,您需要读取输入。从包含回车的提示开始:

printf("Input a three digit number: \n");
由于它是一个三位数的数字,您可以添加以下行来读取输入:

scanf("%3d", &OrigNumber);
下一段代码运行得很好,直到您到达
if(数字%2)
,这是毫无意义的,因为您没有真正定义
number
-是的,您定义了,但是行

number = x, y, z;
不会做你认为它会做的事。如果你加上

printf("So far I have abc=%d, bca=%d, cab=%d\n", abc, bca, cab);
在你第一次读入数字并计算出这三个数字后,你会发现你已经走上了正轨

注意

number = x, y, z;
使用一种称为“逗号运算符”的东西。所有事物(a、b、c)都被“评估”,但它们的值不会返回。无论如何,在你有那条线的地方,你还没有给x,y和z赋值

这足以让你开始吗

更新现在,您有几个小时的时间来仔细考虑这一点,这里还有一些建议

你对abc、cab、bca的计算毫无意义。我将向您展示其中的一个:

cab = c*100 + a*10 + b;
接下来,您需要计算x、y和z。同样,以下是三个选项之一:

y = bca%11;
现在你必须进行求和-我称之为
xy
yz
,和
zx
。就其中一个:

zx = z + x;
接下来,处理指令:“如果这些总和中的任何一个是奇数,如果总和加11小于20,则将其增加11,否则将总和减少11:

if(xy % 2 == 1) {
  if(xy + 11 < 20) xy += 11; else xy -= 11;
}
根据需要重复

最后,打印出结果:

printf("xy: %d, yz: %d, zx: %d\n", xy, yz, zx);
令人惊奇的是,如果你做对了,你会得到原来的数字

您可以通过使用一个值数组并在其中循环,而不是使用不同的变量重复我上面编写的代码片段,从而使代码更加紧凑。但我怀疑这远远超出了您目前希望了解的范围

你能从这里拿走吗

int abc, bca, cab;
abc = (a*100) + (10*b) + c;
bca = (10*b) + c + (a*100);
cab = c + (a*100) + (10*b);
我建议在代码的这一点上打印出数字

printf( "%d %d %d", abc, bca, cab );
我想你会看到你需要解决的问题之一。

\include
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int n, a, b, c, abc, bca, cab, x, y, z, p, q, r;
    scanf("%d", &n);
    c=n%10;
    b=(n/10)%10;
    a=n/100;
    abc=a*100+b*10+c;
    bca=b*100+c*10+a;
    cab=c*100+a*10+b;
    x=abc%11;
    y=bca%11;
    z=cab%11;
    p=x+y;
    q=y+z;
    r=z+x;
    return 0;
}
#包括 使用名称空间std; int main(){ 整数n,a,b,c,abc,bca,cab,x,y,z,p,q,r; scanf(“%d”和“&n”); c=n%10; b=(n/10)%10; a=n/100; abc=a*100+b*10+c; bca=b*100+c*10+a; cab=c*100+a*10+b; x=abc%11; y=bca%11; z=cab%11; p=x+y; q=y+z; r=z+x; 返回0; }
现在,如果这些总和中的任何一个是奇数,如果 总和加11小于20,否则将总和减少 11(此求和运算必须为正数但小于 20) .最后,把每一个总数分成两半。现在,把所有的数字都打印出来 结果数字

我没有拿到最后一部分,你能更清楚地解释一下吗
#include <stdio.h>
int main()
{
    //Declare all variables
    int OrigNumber;
    int a, b, c;
    int abc, bca, cab;
    int x, y, z;
    int xplusy , yplusz, xplusz;

    printf(" A program to read ONLY one integer number.\n Input must be one 3 digit number from 100 to 999 : ");    
    scanf("%d", &OrigNumber);   // Get input from console

    if(OrigNumber > 999 || OrigNumber < 100) {
        printf("Invalid number. Quiting program. This is error handling. Important while learning programming.");   
    return 0;
    }

    c = OrigNumber %10; // digit at unit's place

    b=((OrigNumber) % 100)/10; //digit at the ten's place

    a = (OrigNumber)/100; //digit at the 100's place. Note: 734/100 = 7. NOT 7.34.

    printf("\n Three numbers say A,B, C : %d, %d , %d ", a, b, c);  

    abc = a*100 + 10*b + c;
    bca = 100*b + 10*c + a;
    cab = c*100 + a*10 + b;

    printf("\n Three numbers say ABC, BCA, CAB : %d, %d , %d ", abc, bca, cab);

    x = abc % 11;   // Reminder when divided by 11.
    y = bca % 11;
    z = cab % 11;

    printf("\n Three numbers say X, Y, Z : %d, %d , %d ", x, y, z);

    xplusy = x + y; // Adding reminders two at a time.
    yplusz = y + z;
    xplusz = x + z;

    printf("\n Three numbers  X+Y, Y+Z, X+Z : %d, %d , %d ", xplusy, yplusz, xplusz);

    if((xplusy % 2) == 1) {
        if(xplusy + 11 < 20)
            xplusy += 11;
        else
        xplusy -= 11;
    }

    if((yplusz % 2) == 1) {
        if(yplusz + 11 < 20)
            yplusz += 11;
        else
            yplusz -= 11;
    }

    if((xplusz % 2) == 1) {
        if(xplusz + 11 < 20)
            xplusz += 11;
        else
            xplusz -= 11;
    }

    xplusy /= 2; // Finally, divide each of the sum in half.
    yplusz /= 2;
    xplusz /= 2;

    printf("\n Now print out all the resulting digits :  %d, %d , %d \n", xplusy, yplusz, xplusz);

    return 0;
}
int main() { //声明所有变量 int-OrigNumber; INTA、b、c; 国际abc、bca、cab; int x,y,z; int-xplusy、yplusz、xplusz; printf(“只读取一个整数的程序。\n输入必须是一个从100到999的3位数字:”; scanf(“%d”,&OrigNumber);//从控制台获取输入 如果(起始编号>999 | |起始编号<100){ printf(“无效数字。退出程序。这是错误处理。学习编程时很重要。”); 返回0; } c=原始编号%10;//单位所在位置的数字 b=((原编号)%100)/10;//十位数字 a=(OrigNumber)/100;//100位的数字。注意:734/100=7。不是7.34。 printf(“\n三个数字表示A,B,C:%d,%d,%d”,A,B,C); abc=a*100+10*b+c; bca=100*b+10*c+a; cab=c*100+a*10+b; printf(“\n三个数字表示ABC,BCA,CAB:%d,%d,%d”,ABC,BCA,CAB); x=abc%11;//除以11时提醒。 y=bca%11; z=cab%11; printf(“\n三个数字表示X,Y,Z:%d,%d,%d”,X,Y,Z); xplusy=x+y;//添加提醒
#include <stdio.h>
int main()
{
    //Declare all variables
    int OrigNumber;
    int a, b, c;
    int abc, bca, cab;
    int x, y, z;
    int xplusy , yplusz, xplusz;

    printf(" A program to read ONLY one integer number.\n Input must be one 3 digit number from 100 to 999 : ");    
    scanf("%d", &OrigNumber);   // Get input from console

    if(OrigNumber > 999 || OrigNumber < 100) {
        printf("Invalid number. Quiting program. This is error handling. Important while learning programming.");   
    return 0;
    }

    c = OrigNumber %10; // digit at unit's place

    b=((OrigNumber) % 100)/10; //digit at the ten's place

    a = (OrigNumber)/100; //digit at the 100's place. Note: 734/100 = 7. NOT 7.34.

    printf("\n Three numbers say A,B, C : %d, %d , %d ", a, b, c);  

    abc = a*100 + 10*b + c;
    bca = 100*b + 10*c + a;
    cab = c*100 + a*10 + b;

    printf("\n Three numbers say ABC, BCA, CAB : %d, %d , %d ", abc, bca, cab);

    x = abc % 11;   // Reminder when divided by 11.
    y = bca % 11;
    z = cab % 11;

    printf("\n Three numbers say X, Y, Z : %d, %d , %d ", x, y, z);

    xplusy = x + y; // Adding reminders two at a time.
    yplusz = y + z;
    xplusz = x + z;

    printf("\n Three numbers  X+Y, Y+Z, X+Z : %d, %d , %d ", xplusy, yplusz, xplusz);

    if((xplusy % 2) == 1) {
        if(xplusy + 11 < 20)
            xplusy += 11;
        else
        xplusy -= 11;
    }

    if((yplusz % 2) == 1) {
        if(yplusz + 11 < 20)
            yplusz += 11;
        else
            yplusz -= 11;
    }

    if((xplusz % 2) == 1) {
        if(xplusz + 11 < 20)
            xplusz += 11;
        else
            xplusz -= 11;
    }

    xplusy /= 2; // Finally, divide each of the sum in half.
    yplusz /= 2;
    xplusz /= 2;

    printf("\n Now print out all the resulting digits :  %d, %d , %d \n", xplusy, yplusz, xplusz);

    return 0;
}