A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© brenthe 中级黑马   /  2016-5-16 19:55  /  721 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


7、用户从键盘上输入两个整数,输出他们的余数

#include <stdio.h>

int main(int argc, const char * argv[]) {
   
    //定义两个变量储存数
    int num1,num2;
   
    //打印一句话引导用户输入
    printf("please enter two numbers:\n");
   
    //将用户输入的值存入变量中
    scanf("%d%d",&num1,&num2);
   
   
    //将用户输入的数的余数打印出来
    printf("the remainder which use %d to divide %d is %d.\n",num1,num2,num1%num2);
   
   
    return 0;
}


9. 用户输入矩形的长和宽,求出矩形的面积和周长,并将结果显示在屏幕上.

面积: 长*宽       周长  (长+宽)*2

#include <stdio.h>

int main(int argc, const char * argv[]) {
   
    //定义两个变量存矩形的长和宽
    double length, wide;
   
    //定义两个变量存矩形的面积和周长
    double area, perimeter;
   
    //输出一句话,提示用户输入矩形的长和宽
    printf("please enter the length and wide of a orthogon.\n");
   
    //将用户输入的数据存入变量
    scanf("%lf%lf",&length,&wide);
   
    //计算面积和周长
    area = length * wide;
    perimeter = 2* (length + wide);
   
    //输出计算结果
    printf("the area of the orthogon is %.2lf, the perimeter of the orthogon is %.2lf.\n",area,perimeter);
   
   
    return 0;
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马