The first four classes of 03 jobs

A, PTA operations summary

Third operation: 7-5 discount

When going to the mall Amoy discount merchandise, calculated after the discount price is a brain consuming thing. Original ¥ 988, for example, indicate the fight off 7, the discount price should be ¥ 988 x 70% = ¥ 691.60. This question will ask you to write a program for the customer to calculate the discount rate.

Input formats:

List input is given in one row of goods (not to exceed 1 million positive integer) and discounts ([1, 9] integer in the interval), separated by a space therebetween.

Output formats:

Output of goods in a row discounted price, retain two decimal places.

Sample input:

988 7

Sample output:

691.60

1. experiment code

#include<stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    double c=a*1.0*b*0.1;
    printf("%.2f",c);
}

2 design ideas

The first step: define the variable a: b Price: Discount
Step 2: Ask the user input variables a and b
of the third step: Define floating point variable c: After the discount price and the calculated value of c
Step four: output value of c

flow chart:

3. This question debugging process encountered problems and solutions

no



Fifth operation: sign function value calculating 7-2

对于任一整数n,符号函数sign(n)的定义如下:

请编写程序计算该函数对任一输入整数的值。

输入格式:

输入在一行中给出整数n。

输出格式:

在一行中按照格式“sign(n) = 函数值”输出该整数n对应的函数值。

输入样例1:

10

输出样例1:

sign(10) = 1

输入样例2:

0

输出样例2:

sign(0) = 0

输入样例3:

-98

输出样例3:

sign(-98) = -1

1.实验代码

#include <stdio.h>
int main(){
    int n,sign;
    scanf("%d",&n);
    if (n<0){
        sign=-1;
    }
    else if(n>0){
        sign=1;
    }
    else{
        sign=0;
        
    }
    printf("sign(%d) = %d",n,sign);
    return 0;
}

 

2 设计思路

第一步:定义变量 n , sign
第二步:让用户输入变量 n
第三步:判断 n是否小于0 若结果为是 则sign赋值为-1 结束判断

              若结果为否 判断 n是否大于0 若结果为是 则sign赋值为1 结束判断

              若结果为否 则sign赋值为0 结束判断
第四步:输出函数sign的表达式和n,sign的值

流程图:

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


二、总结和学习进度条

1、这几周学了表达式,比较,条件判断,循环等内容,基本没有遇到什么问题。

2、点评点评完再加进来

 

Guess you like

Origin www.cnblogs.com/dogend/p/10993082.html