算法竞赛入门经典_2_变量及其输入

代码:

//2017-6-19 变量及其输入
#include <stdio.h>
#include <math.h>
 
void AAndB();
void CircleZtArea();

int main()
{
    AAndB();
    CircleZtArea();
    return 0;
}
void AAndB()
{
    int a, b;
    scanf("%d%d", &a, &b);
    //scanf("%d", a);//错误,漏了&
    printf("%d
", a+b);
}
void CircleZtArea()
{
    const double pi = acos(-1.0);
    double r, h , s1, s2, s;
    scanf("%1f%1f", &r, &h);//double类型变量要使用lf双精度浮点数
    s1 = pi*r*r;
    s2 = 2*pi*h*r;
    s = s1*2.0 + s2;
    printf("Area = %.3f
", s);
}

运行效果:

 


注:  

  在算法竞赛中

不要有"友好提示",因为选手程序是自动完成的,没有人工干预

不要有getch(), getche(), getchar(), clrscr(), gotoxy(), (conio.h)

不要有system("pause");


  在算法竞赛中,每行开始不应有空格,输出均已回车符结束,包括最后一行

此外,输出的每两个数或字符串之间应以单个空格隔开.


  尽量使用const 关键字来声明常数如

const double pi = acos(-1.0);

要么创新,要么灭亡

动手编码之前,你需要对要编码实现的解决方案有一个正式的或粗略的设计。永远不要在没有任何设计的前提下就开始编码,除非所编代码不重要。

原文地址:https://www.cnblogs.com/ncgds/p/7050597.html