請問有人會用c++寫這個程式嗎?幫幫忙

ex8.c 請寫出“讓使用者輸入長方形的兩邊長, 計算面積與週長後將結果輸出”的 C 語言程式碼

2 Answers

Rating
  • 冠豪
    Lv 4
    1 decade ago
    Favorite Answer

    # include<stdio.h>

    int main()

    {

    int area,circumference,length ,wide;

    printf("請輸入長方形的長: ");

    scanf("%d", &length);

    printf("請輸入長方形的寬: ");

    scanf("%d", &wide);

    while (length < 0 || wide < 0)

    if (length < 0)

    {

    printf("請輸入長方形的長: ");

    scanf("%d", &length);

    } // end if

    else

    {

    printf("請輸入長方形的寬: ");

    scanf("%d", &wide);

    } // end else

    area = length * wide;

    circumference = 2 * (length wide);

    printf("所得的面積為%d,所得的周長為%d \n", area,circumference);

    return 0;

    } // main

  • 1 decade ago

    #include<iostream.h>

    void main()

    {

    int a,b,A,S; //a,b分別為長方形的兩邊長 A為面積S為週長

    cout<<"please input two integer"<<endl;

    cin>>a>>b;

    A=a*b;

    S=2*(a+b);

    cout<<"A is"<<A<<endl<<"S is"<<B<<endl;

    }

    Source(s): me
Still have questions? Get your answers by asking now.