C语言编程练习----山东理工大学ACM平台实验一A--I题解

A第一题输出hello world

Input

本题没有输入数据

Output

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

Sample

Output 

Hello World!
#include<stdio.h>



int main()

{

printf("Hello World!\n");

return 0;

}

B - C语言实验——输出字符串

Description

在屏幕上输出一行信息:This is a C program.

Input

无输入数据。

Output

输出字符串This is a C program.

Sample

Output 

This is a C program.
​
#include<stdio.h>



int main()

{

printf("Hello World!\n");

return 0;

}

​

C - C语言实验——图形输出(字符常量练习)

Description

用基本输出语句打印以下图形:
#
##
###
####
#####
######

Input

本题目没有输入数据

Output

输出图形由6行组成,第1行有1个#号,第i行有连续的i个#号:
#
##
###
####
#####
######

Sample

Output 

#
##
###
####
#####
######
#include<stdio.h>int main(){

printf("#\n##\n###\n####\n#####\n######");

return 0;

}

D - C语言实验——求两个整数之和

Description

求两个整数之和,不从键盘输入数据,直接使用赋值语句(a=123;b=456)输入数据,然后计算两个整数之和输出。

Input

无输入数据。

Output

输出a和b之和。

Sample

Output 

sum is 579

(求两个整数之和--求两个整数之和,不从键盘输入数据,直接使用赋值语句(a=123;b=456)输入数据,然后计算两个整数之和输出。)

#include<stdio.h>

int main()

{

int a=123,b=456;

printf("sum is %d\n",a+b);

return 0;

}

E - A+B Problem

Description

Calculate a + ba+b

Input

Two integer a, ba,b (0 \le a, b \le 10)(0≤a,b≤10)

Output

Output a + b.

Sample

Input 

1 2

Output 

3

( A+B problem(要求终端输入用scanf)

法一---引入变量

#include<stdio.h>

int main()

{

int a,b;
scanf("%d %d",&a,&b);
int c=a+b;
printf("%d\n",c);
return 0;
}
法二---直接写
#include<stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
printf("%d\n",a+b);
return 0;
}

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

Description

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

Input

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

Output

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

Sample

Input 

4 6

Output 

6 4

交换两个变量--交换两个变量的值,由终端输入两个整数给变量x、y,然后交换x和y的值后,输出x和y。(其实说的就是用scanf输入)

法一----三个变量
#include<stdio.h>
int main()
{
int x, y, temp;
scanf("%d %d", &x, &y);
temp = y;
y = x;
x = temp;
printf("%d %d", x, y);
return 0;
}
法二---两个变量解决 
#include<stdio.h>
int main()
{
int x, y;
scanf("%d %d", &x, &y);
x=y-x;       // 自己定义X;
y=y-x;       // 利用表达式表达出y=x,因为此时y=y-(y-x)=x;从而实现y与x的互换。
x=y+x;       // 目的再让x=y实现x与y的互换;即x=y+x=x+(y-x)=y;
printf("%d %d", x, y);
return 0;
}
或者x=x+y;  y=x-y;   x=x-y;
或者x=x-y;  y=x+y;   x=y-x;

  

G - C语言实验——逆置正整数

Description

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

Input

3位正整数。

Output

逆置后的正整数。

Sample

Input 

123

Output 

321

Hint

注意130逆置后是31

#include<stdio.h>
int main()
{
	int x;
	scanf("%d", &x);
	int dight;//定义一个变量为下面X计算做存储
	int ret = 0;
	while (x > 0) {
		dight = x % 10;//x取余之后只剩下他的个位数了
		ret = ret * 10 + dight;
		x /= 10;
	}
	printf("%d", ret);
	return 0;
}

H - C语言实验——买糖果

Description

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

Input

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

Output

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

Sample

Input 

2

Output 

6 2
#include<stdio.h>
int main()
{
	int n=0;//n为爸爸给孩子最初的总钱数元
	scanf("%d", &n);//终端格式化输入总钱数
	int a;//角
	a = n * 10;//单位转化全是角
	int i ;//购买次数=糖块数
	i = a / 3;//因为a和i是整数型变量所以i的结果还是整数即次数也就是糖果数
	int y ;//找回的钱
	y = a - i * 3;
	printf("%d %d\n", i, y);
	return 0;

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

Description

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

Input

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

Output

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

Sample

Input 

2 3 3

Output 

8 18 2.67
#include<stdio.h>
int main()
{
	int a = 0; int b = 0; int c = 0;
	scanf("%d %d %d", &a, &b, &c);
	int x; x = a + b + c;
	int y; y = a * b * c;
	double z; z = (a + b + c) / 3.0;//double后面一定要对应数字跟上.0
		printf("%d %d %.2f", x, y, z);//控制浮点位数就要用这种格式,小数点后两位就是%.2f
	return 0;}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

恰逢*

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值