C语言程序设计基础OJ练习题(实验一顺序结构)

一、C语言实验——Hello World!(printf练习)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

很高兴你能上机实践所学的C语言知识!
编程不是在课本上的几页纸就能学会的,你必须多思考、多上机才能真正学会一门编程语言,这也是我们出这些题目的初衷。
这些题目都是课本上的基本题目,主要目的是让大家巩固课堂上所学到的,希望大家能够认真对待!
为了便于调试题目,做这些题目时可以先在CodeBlocks、DevC++或Microsoft VC++6.0中调试成功后再提交。
下面我们就开始吧:

利用C语言基本格式显示以下内容: Hello World!

Input

本题没有输入数据

Output

输出字符串Hello World!输出后需要换行。

Sample Input

 

Sample Output

Hello World!

#include <stdio.h>
int main()
{
    printf("Hello World!\n");
}

 

二、C语言实验——计算A+B(顺序结构)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

这是一道在各个ACM训练网站上最基本的题目,一般都是他们的第一道题,来让大家熟悉在线评测系统的环境!
从键盘上输入两个整数,然后计算他们的和,并把他们的和打印出来。

Input

从键盘上输入两个整数,这两个整数在同一行上!

Output

在这两个整数的下面一行是输出这两个整数的和!

Sample Input

2 3

Sample Output

5

#include <stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d\n",a+b);
}

 

三、C语言实验——交换两个整数的值(顺序结构)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

交换两个变量的值,由终端输入两个整数给变量x、y,然后交换x和y的值后,输出x和y。

Input

从键盘输入两个整数变量x和y;

Output

在交换x、y的值后将x和y输出!

Sample Input

4 6

Sample Output

6 4

#include <stdio.h>
int main()
{
    int a,b,x;
    scanf("%d %d",&a,&b);
    x = a ;
    a = b ;
    b = x ;
    printf("%d %d\n",a,b);
}

 

四、C语言实验——逆置正整数

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

输入一个三位正整数,将它反向输出。

Input

3位正整数。

Output

逆置后的正整数。

Sample Input

123

Sample Output

321

Hint

注意130逆置后是31

#include <stdio.h>
int main()
{
    int a,b,c,x;
    scanf("%d",&x);
    a = x/100;
    b = (x/10)%10;
    c = x%10;
    printf("%d\n",a+b*10+c*100);
}

 

五、C语言实验——买糖果

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

小瑜是个爱吃糖果的馋鬼,天天嚷着要爸爸买糖果,可是爸爸很忙,哪有时间啊,于是就让小瑜自己去了,糖果3角钱一块,爸爸给小瑜n元钱,请你告诉小瑜最多能买几块糖,还剩几角钱?

Input

输入爸爸给小瑜的钱n元,n为整数。

Output

小瑜最多能买回的糖块数以及剩下的钱(单位为:角),用空格分隔。

Sample Input

2

Sample Output

6 2

#include <stdio.h>
int main()
{
    int a,b,x;
    scanf("%d",&x);
    a = x*10/3;
    b = x*10-a*3;
    printf("%d %d\n",a,b);
}

 

六、C语言实验——三个整数和、积与平均值

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

给出三个整数,请你设计一个程序,求出这三个数的和、乘积和平均数。

Input

输入只有三个正整数a、b、c。

Output

输出一行,包括三个的和、乘积、平均数。 数据之间用一个空格隔开,其中平均数保留小数后面两位。

Sample Input

2 3 3

Sample Output

8 18 2.67

#include <stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    printf("%d %d %.2lf\n",a+b+c,a*b*c,(a+b+c)/3.0);
}

 

七、C语言实验——格式化输出(常量练习)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

用c语言的基本输出格式打印下列内容:
100
A
3.140000

Input

本题目没有输入数据

Output

输出三行数据:
100
A
3.140000

Sample Input

 

Sample Output

100
A
3.140000

#include <stdio.h>
int main()
{
    printf("100\nA\n3.140000\n");
}

八、C语言实验——圆柱体计算

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

已知圆柱体的底面半径r和高h,计算圆柱体底面周长和面积、圆柱体侧面积以及圆柱体体积。其中圆周率定义为3.1415926。

Input

输入数据有一行,包括2个正实数r和h,以空格分隔。

Output

输出数据一行,包括圆柱体底面周长和面积、圆柱体侧面积以及圆柱体体积,以空格分开,所有数据均保留2位小数。

Sample Input

1 2

Sample Output

6.28 3.14 12.57 6.28

#include <stdio.h>
#define PI 3.1415926
int main()
{
    int r,h;
    double l,s,S,v;
    scanf("%d%d",&r,&h);
    l = 2*PI*r;
    s = PI*r*r;
    S = l*h;
    v = s*h;
    printf("%.2lf %.2lf %.2lf %.2lf\n",l,s,S,v);
}

 

九、C语言实验——温度转换

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

输入一个华氏温度,输出摄氏温度,其转换公式为:C=5(F-32)/9。

Input

输入数据只有一个实数,即华氏温度。

Output

输出数据只有一个,即摄氏温度,保留2位小数。

Sample Input

32.0

Sample Output

0.00

#include <stdio.h>
int main()
{
    double f,c;
    scanf("%lf",&f);
    c = 5*(f-32)/9;
    printf("%.2lf\n",c);
}


 

十、C语言实验——单个字符输入和输出(顺序结构)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

用getchar()从键盘上输入一个字符,用putchar()打印出来!

Input

从键盘上输入一个字符!

Output

把刚刚输入的字符打印出来!

Sample Input

A

Sample Output

A

#include <stdio.h>
int main()
{
    char a;
    a = getchar();
    putchar(a);
}


 

十一、C语言实验——转换字母(顺序结构)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

从键盘上输入一个小写字母,然后将小写字母装换成大写字母输出!

Input

从键盘上输入一个小写字母。

Output

小写字母装换成大写字母输出。

Sample Input

a

Sample Output

A

#include <stdio.h>
int main()
{
    char a;
    a = getchar();
    a = a-32;
    putchar(a);
}


 

猜你喜欢

转载自blog.csdn.net/qq_38074938/article/details/86522353