[Noi the arithmetic expression and sequential execution of]1.3 Programming foundation of the Test Bank (I.)

Source: Internet
Author: User

The problem of A+b

The classic a+b problem--the first question on the big questions. Read into $a,b$, output $a+b$.

#include <iostream>usingnamespace  std; int Main () {    int A, b;    CIN>>a>>b;    cout<<a+b<<Endl;     return 0 ;}
01.cpp 02 Calculation (A+B) value of *c

Read into $a,b,c$, output $c (a+b) $.

#include <iostream>usingnamespace  std; int Main () {    int  a,b,c;    CIN>>a>>b>>C;    cout<< (a+b) *c<<Endl;     return 0 ;}
02.cpp 03 calculation (A+B)/C value

Read in $a,b,c$, output $\lfloor \dfrac{a+b}{c} \rfloor$. In fact, if operators are integers, the division sign "/" in C + + can be rounded up.

#include <iostream>usingnamespace  std; int Main () {    int  a,b,c;    CIN>>a>>b>>C;    cout<< (a+b)/c<<Endl;     return 0 ;}
03.cpp 04 with remainder Division

Elementary school arithmetic, set to read in is $a,b$, then the two number of the request is a/ b and a%b .

#include <iostream>usingnamespace  std; int Main () {    int A, b;    CIN>>a>>b;    cout<<a/b<<""<<a%b<<Endl;     return 0 ;}
04.cpp 05 floating-point values for the calculation of fractions

      with  double The   type stores and divides operations, noting that output is formatted as a format. Of course you can also use  1.0 *a/b   Such statements get the result of the real number except.

#include <cstdio>usingnamespace  std; int Main () {    int A, b;    scanf ("%d%d",&a,&b);    printf ("%.9f\n",1.0*a/b);     return 0 ;}
05.cpp 06 Swine Flu Epidemic mortality

      awesome backgrounds ... In fact, it is the division of two numbers, resulting in a percentage output. The output statement can be written as  printf ( %.3f%%\n , 100 *x);  ,x is a calculated quotient.

 #include <cstdio>using  namespace   Std;  int   Main () { int      b; scanf (  %d%d   ", &a,&b);    b  =b*100    %.3f%%\n   ", 1.0  *b/a);  return  0  ;}  
06.cpp 07 Calculating the value of a polynomial

This problem can be directly calculated, but there is a better way, is the law of Horner:

\[f (x) =ax^3+bx^2+cx+d= ((ax+b) x+c) x+d\]

This can reduce the number of operations.

#include <cstdio>usingnamespace  std; int Main () {    double  x,a,b,c,d;    scanf ("%lf%lf%lf%lf%lf",&x,&a,&b,&c,&D);    printf ("%.7f\n", ((* (* (x) +b) *x) +c) *x+D)    ; return 0 ;}
07.cpp 08 Temperature Expression Conversion

      give $f$, $c=\dfrac{5}{9} (F-32) $,.

 #include <cstdio>using  namespace   Std;  int   Main () { double   F,c; scanf (  %lf     , &f); C  =5  * (F-32 )/9  ; printf (  %.5f\n   " ,c);  return  0  ;}  
08.cpp 09 calculations related to the circle

Give $r$, Beg $c=2\pi R $ and $s=\pi r^2$.

 #include <cstdio> #define  PI 3.14159 namespace   Std;  int   Main () { double   R; scanf (  %lf     , &r); printf (  %.4f%.4f%.4f\n   ", 2  *r,2  *pi*r,pi*r*R);  return  0  ;}  
09.cpp 10 calculating the resistance of the shunt resistor

Give a $r_1,r_2$, beg

\[r=\frac{1}{\frac{1}{r_1}+\frac{1}{r_2}}\]

 #include <cstdio>using  namespace   Std;  int   Main () { float      R,R1,R2; scanf (  %f%f   ", &r1,&R2); R  =1.0 /(1 /r1+1 /R2); printf (  %.2f\n   " ,r);  return  0  ;}  
10.cpp

[Noi the arithmetic expression and sequential execution of]1.3 Programming foundation of the Test Bank (I.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.