The programming summary (Eighth week)

题目1 混合类型数据格式化输入

(1)实验代码

#include <stdio.h>

int main()
{
    int a;
    double b,c;
    char d;
    scanf("%lf %d %c %lf",&b,&a,&d,&c);
    printf("%c %d %.2lf %.2lf",d,a,b,c);
    return 0;
}

(2)设计思路

第一步:定义变量

第二步:输入变量

第三步:输出结果

(3)本题调试过程碰到问题及解决办法(3)本题调试过程碰到问题及解决办法

注意字符输入时空字符的占位问题

(4)运行结果截图

(考试时间已到,无法获得截图)

题目2 计算符号函数的值

(1)实验代码

#include <stdio.h>
int main(void)
{
    int n, a;

    scanf("%d", &n);
    if (n < 0)
        a = -1;
    else if (n > 0)
        a = 1;
    else
        a = 0;
    printf("sign(%d) = %d\n", n, a);

    return 0;
}

(2)设计思路

第一步:定义变量

第二步:输入变量

第三步:if-else判断条件

第四步:输出结果

(3)本题调试过程碰到问题及解决办法

本题无错误,一次性通过

(4)运行结果截图

(考试时间已到,无法获得截图)

题目3 计算个人所得税

(1)实验代码

#include <iostream>
#include <stdio.h>
using namespace std;
int main(void)
{
    int money;
    cin >> money;
    if (money <= 1600)
        printf("0.00");
    else if (money <= 2500)
        printf("%.2f", 0.05 * (money - 1600));
    else if (money <= 3500)
        printf("%.2f", 0.10 * (money - 1600));
    else if (money <= 4500)
        printf("%.2f", 0.15 * (money - 1600));
    else
        printf("%.2f", 0.20 * (money - 1600));

    return 0;
}

(2)设计思路

第一步:定义变量

第二步:输入变量

第三步:if-else判断条件

第四步:输出结果

(3)本题调试过程碰到问题及解决办法

可在printf函数中直接输出表达式

(4)运行结果截图

(考试时间已到,无法获得截图)

题目4 比较大小

(1)实验代码

#include <iostream>
#include <stdio.h>
using namespace std;
int main(void)
{
    int a, b, c, change = 0;;
    cin >> a >> b >> c;
    while (a > b || b > c)
    {
        if (a > b)
        {
            change = a;
            a = b;
            b = change;
        }
        if (b > c)
        {
            change = b;
            b = c;
            c = change;
        }
    }

    printf("%d->%d->%d", a, b, c);

    return 0;
}

(2)设计思路

第一步:定义变量,输入变量

第二步:定义while循环反复判断

第三步:if判断条件,进行数字间的交换

第四步:输出结果

(3)本题调试过程碰到问题及解决办法

本题就一些细节问题,不断调试后解决了

(4)运行结果截图

(考试时间已到,无法获得截图)

题目5 到底是不是太胖了

(1)实验代码

#include<stdio.h>
#include<math.h>
int main()
{
  int h,w;
  int N;
  int z;
  int l,h1;
  scanf("%d",&N);
  for(int i=1;i<=N;i++)
  {
    scanf("%d %d",&h,&w);
    z=(h-100)*2*9*1000/10;
    l=z*9/10;
    h1=z*11/10;
    w=w*1000;
    if(w>l&&w<h1)
    printf("You are wan mei!\n");
    if(w<=l)
    printf("You are tai shou le!\n");
    if(w>=h1)
    printf("You are tai pang le!\n");
    }
  return 0;
}

(2)设计思路

第一步:定义变量

第二步:输入变量

第三步:if-else判断条件

第四步:输出结果

(3)本题调试过程碰到问题及解决办法

判断的时候注意上界和下界的取值

(4)运行结果截图

(考试时间已到,无法获得截图)

题目6 高速公路超速处罚

(1)实验代码

#include<stdio.h>
int main(void)
{
    float speed, limit;
    scanf("%f %f", &speed, &limit);
    if (speed >= limit * 15 / 10)
    {
        printf("Exceed %.0f%%. License Revoked\n", (speed - limit) / limit * 100);
    }
    else {
        if (speed >= limit * 11 / 10)
        {
            printf("Exceed %.0f%%. Ticket 200\n", (speed - limit) / limit * 100);
        }
        else
        {
            printf("OK\n");
        }
    }
    return 0;
}

(2)设计思路

第一步:定义变量

第二步:输入变量

第三步:if-else判断条件

第四步:输出结果

(3)本题调试过程碰到问题及解决办法

注意if-else语句的嵌套使用

(4)运行结果截图

(考试时间已到,无法获得截图)

题目7 统计字符

(1)实验代码

#include<stdio.h>
int main(void)
{
    char c;
    int letter, blank, digital, other, i, n;

    letter=0, blank=0, digital=0, other=0, n=0;
    for(i=0; i<10; i++)
    {
        c = getchar();
        if((c>=‘a‘&&c<=‘z‘)||(c>=‘A‘&&c<=‘Z‘))
            letter++;
        else if(c == ‘ ‘||c == ‘\n‘)
            blank++;
        else if( c>=‘0‘&&c<=‘9‘)
            digital++;
        else
            other++;
    }
    printf("letter = %d, blank = %d, digit = %d, other = %d\n", letter, blank, digital, other);

    return 0;
} 

(2)设计思路

第一步:定义变量,输入变量

第二步:定义for循环反复输入

第三步:if判断条件,判断字符应储存在哪个地方

第四步:输出结果

(3)本题调试过程碰到问题及解决办法

字符的判断条件

(4)运行结果截图

(考试时间已到,无法获得截图)

题目8 统计学生平均成绩与及格人数

(1)实验代码

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

int main(void)
{
    double n, number;
    int count = 0;
    double sum = 0.0, average = 0.0;

    scanf("%lf", &n);

    for (int i = 0; i < n; i++)
    {
        scanf("%lf", &number);
        sum = sum + number;
        if (number >= 60)
            count += 1;
    }

    if (n != 0)
        average = sum / n;
    else
        average = 0;

    printf("average = %.1lf\n", average);
    printf("count = %d", count);

    return 0;
}

(2)设计思路

第一步:定义变量,输入变量

第二步:定义for循环反复输入

第三步:if判断条件

第四步:输出结果

(3)本题调试过程碰到问题及解决办法

average条件判断

(4)运行结果截图

(考试时间已到,无法获得截图)

题目9 输出闰年

(1)实验代码

#include<stdio.h>
int main()
{
    int year, i, count=0;

    scanf("%d", &year);

    if(year<=2000||year>2100)
        printf("Invalid year!\n");
    else
    {
        for(i=2001; i<=year; i++)
        {
            if(i%4==0&&i%100!=0||i%400==0)
            {
                printf("%d\n", i);
                count++;
            }
        }
        if(count==0)
            printf("None\n");
    }
    return 0;
}

(2)设计思路

第一步:判断闰年的取值范围

第二步:定义for循环遍历年份

第三步:闰年语句判断年份

第四步:输出结果

(3)本题调试过程碰到问题及解决办法

本题无错误,一次性通过

(4)运行结果截图

(考试时间已到,无法获得截图)

原文地址:https://www.cnblogs.com/JingWenxing/p/9945622.html

时间: 2024-07-31 11:07:50

The programming summary (Eighth week)的相关文章

The programming summary (Seventh week)

题目1 生成3的乘方表 (1)实验代码 #include <stdio.h> int main(void) { int n; int i; int result; scanf("%d",&n); i=0; for (i;i<=n;i++) { result=pow(3,i); printf("pow(3,%d) = %d\n",i,result); } return 0; } (2)设计思路 第一步:定义变量 第二步:输入变量,赋初值 第三

VsSharp:一个VS扩展开发框架(上)

上篇:设计 一.引子 自2008年起开发SSMS插件SqlSharp(er)的过程中,有一天发现多数代码都大同小异,就像这样. Commands2 commands = (Commands2)_applicationObject.Commands; string toolsMenuName = "Tools"; //Place the command on the tools menu. //Find the MenuBar command bar, which is the top-

使你的C/C++代码支持Unicode(CRT字符串处理的所有API列表,甚至有WEOF字符存在)

悉Microsoft支持Unicode的方式. 它的主要目的是方便你查询相关的数据类型和函数,以及修正相应的拼写错误. I18nGuy 主页 XenCraft (Unicode 咨询公司) English My thanks to Yaker Gong for the translation to Chinese. Xie Xie! 使你的C/C++代码支持Unicode的第一步 定义宏 _UNICODE, 如果定义了宏 _MBCS 则取消它的定义(undefine). 在字符串前添加 L 标记

OOP 面向对象

我们是怎么思考和解决上面的问题的呢? 答案是:我们自己的思维一直按照步骤来处理这个问题,这是我们常规思维,这就是所谓的面向过程POP编程 二.面向过程POP为什么转换为面向对象OOP 面向过程想的思想步骤越多,变化越多,是无法掌控的,所以有时候非常复杂,就比如我们拿起来手机玩游戏如果按照POP编程则代码如下: namespace OOP { /// <summary> /// OOP 面向对象编程 Object Oriented Programming /// </summary>

[leetcode summary] Dynamic Programming

套路: 一般有两个string的时候 都建二维的数组来存. int[][] dp =new int[len+1][len+1]; 初始情况已设立 dp[0][0] = 1; 递归循环 for() dp[i][j] = dp [i-1][j]; 交答案 dp[len][len]

Java Object Oriented Programming concepts

Introduction This tutorial will help you to understand about Java OOP'S concepts with examples. Let's discuss about what are the features of Object Oriented Programming. Writing object-oriented programs involves creating classes, creating objects fro

Unity基于响应式编程(Reactive programming)入门

系列目录 [Unity3D基础]让物体动起来①--基于UGUI的鼠标点击移动 [Unity3D基础]让物体动起来②--UGUI鼠标点击逐帧移动 时光煮雨 Unity3D让物体动起来③—UGUI DoTween&Unity Native2D实现 时光煮雨 Unity3D实现2D人物动画① UGUI&Native2D序列帧动画 时光煮雨 Unity3D实现2D人物动画② Unity2D 动画系统&资源效率 背景 前有慕容小匹夫的一篇<解构C#游戏框架uFrame兼谈游戏架构设计&

Async/Await - Best Practices in Asynchronous Programming

https://msdn.microsoft.com/en-us/magazine/jj991977.aspx Figure 1 Summary of Asynchronous Programming Guidelines Name Description Exceptions Avoid async void Prefer async Task methods over async void methods Event handlers Async all the way Don’t mix

Questions that are independent of programming language. These questions are typically more abstract than other categories.

Questions that are independent of programming language.  These questions are typically more abstract than other categories. Free Language Agnostic Programming Books 97 Things Every Programmer Should Know Algorithms and Data-Structures (PDF) Algorithm