cyg41223103 cp2023

  • Home
    • SMap
    • reveal
    • blog
  • About
  • Brython
  • w15
    • Q2
    • Q1
  • 作業內容
    • W3
    • W4
    • w5
    • w6
      • 台灣國旗
      • 日本國旗
      • 美國國旗
      • 英國國旗
      • 韓國國旗
      • 中國國旗
    • W7
    • W10
    • W13
  • ANSI C
    • c1.
    • c2.
    • c3.
    • c4.
    • c5.
    • c6.
    • c7.
    • c8.
    • c9.
    • c10.
  • C_EX
    • ex1.
    • ex2.
    • ex3.
    • ex4.
    • ex5.
    • ex6.
    • ex7.
    • ex8.
    • ex9.
    • ex10.
  • NOTE
    • ssh
c9. << Previous Next >> C_EX

c10.

寫一個 C 程序,接受使用者提供的兩個整數併計算這兩個整數的和。

#include <stdio.h>

int main() {
    int x, y;
    int result1, result2; // 用于存储 scanf 的返回值

    // 获取第一个整数
    printf("Input the first integer: ");
    result1 = scanf("%d", &x);
    if (result1 != 1) {
        printf("Error: Please enter an integer.\n");
        return 1;
    }

    // 获取第二个整数
    printf("Input the second integer: ");
    result2 = scanf("%d", &y);
    if (result2 != 1) {
        printf("Error: Please enter an integer.\n");
        return 1;
    }

    // 计算并输出它们的和
    printf("Sum of the two integers = %d\n", x + y);

    return 0;
}


c9. << Previous Next >> C_EX

Copyright © All rights reserved | This template is made with by Colorlib