符瑞艺 160809228_C语言程序设计实验2 选择结构程序设计
实验2- 输入3个数,并按由大到小的顺序输出。
实验要求:
编写一个C程序,输入3个数,并按由大到小的顺序输出。
参考: 源码:
#include <stdio.h>
int main(){
int a,b,c,t;
printf("10,20,111;");
scanf("%d%d%d",&a,&b,&c);
if(a<b){
t=a;
a=b;
b=t; }
if(b>c){
printf("%d\t%d\t%d\n",a,b,c); }
else if(c>a){
printf("%d\t%d\t%d\n",c,a,b);
}
else{ printf("%d\t%d\t%d\n",a,c,b); }
return ;
}
运行结果抓图

实验2- 从键盘上输入x的值,并根据计算输出y的值
实验要求:从键盘上输入x的值,并根据计算输出y的值 提示:
. 使用数据函数需要#include <math.h>
. 开方函数:sqrt(x)
. 绝对值函数:fabs(x)
源码
#include <stdio.h>
#include <math.h>
int main(){
float x,y;
printf("请输入一个数");
scanf("%f",&x);
if(x>){
y=sqrt(x-);
printf("%f",y);
}
else if(x<-){
y=fabs(x);
printf("%f",y);
}
else{ y=x+;
printf("%f",y);
}
return ;
} 实验结果:

实验2-3从键盘上输入一个字母,如果是小写字母,将其转换成大写字母并输出。
实验要求:从键盘上输入一个字母,如果是小写字母,将其转换成大写字母并输出。
提示:
. 输入字符给变量c
char c;
方法一:c = getchar ();
方法二:scanf("%c",&c);
. 输出字符变量c
方法一:putchar(c);
方法二:printf("%c",c); 程序源码
#include <stdio.h>
int main()
{
char c;
printf("请输入一个字符:\n");
scanf("%c",&c);
printf("其大写字符是:%c\n",c-);
}
运行结果抓图

实验2-4从键盘上输入x的值,并根据计算输出y的值
实验要求:从键盘上输入x的值,并根据计算输出y的值 程序源码
#include <stdio.h>
int main()
{
int x,y;
printf("请输入一个数\n");
scanf("%d",&x);
if(x<){
y=x;
printf("%d",y);
}
else if(<=x<){
y=*x-;
printf("%d",y);
}
else{
y=*x-;
printf("%d",y);
}
return ;
}

实验心得
通过这次试验,我明白了C语言一些使用技巧,使我朝着C语言这大门又走进了一步,虽然这次实验比上次多了些步骤,但也让我感受到C语言的魅力,这次作业教得晚了,下次作业我会早点交
符瑞艺 160809228_C语言程序设计实验2 选择结构程序设计的更多相关文章
- 160809209_李梦鑫_C语言程序设计实验2+选择结构程序设计_进阶
<C语言程序设计>实验报告 学 号 160809209 姓 名 李梦鑫 专业.班 计科16-2班 学 期 2016-2017 第1学期 指导教师 黄俊莲 吴喆 实验地点 C05 机 ...
- 160809212田京诚C语言程序设计实验2 选择结构程序设计_进阶
实验2-6 猜数字游戏 实验要求: 编写一个C程序实现一个[1-100]以内的猜数字游戏. (1) 系统随机产生一个[1-100]之间的随机数. (2) 输入任意一个数字.数字 ...
- 160809209_李梦鑫_C语言程序设计实验2 选择结构程序设计
实验2-1 输入3个数,并按由大到小的顺序输出. 实验要求: 编写一个C程序,输入3个数,并按由大到小的顺序输出. 源码:#include <stdio.h> int main() { i ...
- 学号160809224姓名黄家帅c语言程序设计实验2 选择结构程序设计
实验2-1 输入3个数,并按由大到小的顺序输出. 实验要求: 编写一个C程序,输入3个数,并按由大到小的顺序输出. 源码: #include <stdio.h>void main(){ i ...
- 学号160809212姓名田京诚C语言程序设计实验2选择结构程序设计
编写一个C程序,输入3个数,并按由大到小的顺序输出. 1 #include <stdio.h> void main(){ int a,b,c,t; printf("请输入三个整数 ...
- 160809225_叶桦汀_C语言程序设计实验2 选择结构程序设计_进阶
#include<stdio.h> #include<math.h> int main() { int a,b,c,l,p,s; printf("请输入三个数:&qu ...
- 160809209_李梦鑫_C语言程序设计实验3 循环结构程序设计
<C语言程序设计>实验报告 学 号 160809209 姓 名 李梦鑫 专业.班 计科16-2班 学 期 2016-2017 第1学期 指导教师 黄俊莲 吉吉老师 实验地点 C05 ...
- 160809228_符瑞艺_C语言程序设计实验3 循环结构程序设计
#include <stdio.h> int main(){ //使用for循环完成1+2+......+100 ; ;i<=;i++) sum +=i; //sum = sum ...
- 【C语言】第4章 选择结构程序设计
第4章 选择结构程序设计 C语言有两种选择语句: if 语句,实现两个分支的选择结构 switch 语句,实现多分支的选择结构 输入3个数a,b,c,要求按由小到大的顺序输出. 可以先用伪代码写出算法 ...
随机推荐
- linq 之 Distinct的使用
public class Product { public string Name { get;set;} public int Code { get; set; } } class ProductC ...
- 创建自己的Activity
创建自己的Activity 1.新建class,继承Activity类 2.重写新建类的onCreate 方法 public class SecondActivity extends Activity ...
- DrawCall
[精]draw call 理解和优化 http://bubuko.com/infodetail-387899.html DrawCall 优化 . http://www.cnblogs.com/sof ...
- WAMPSERVER 64位 win7下 php 5.5.12通过 PECL 安装 zip扩展
通过phpinfo()查看 php5.5.12默认集成了zip模块 不过版本是1.11.0 http://pecl.php.net/package/zip 通过PECL 查看 最新版本是1.12.4 ...
- centos 7.0 安装
最小化安装的 主要查看硬盘使用时间 需要安装 smartmontools 这个 [root@localhost ~]# yum install -y smartmontools 已加载插件:fast ...
- MongoDB创建数据库和集合命令db.createCollection详解(转)
切换/创建数据库 use yourDB; 当创建一个集合(table)的时候会自动创建当前数据库 完整的命令如下:db.createCollection(name, {capped: <Boo ...
- Ubuntu14.04 LTS更新源
Ubuntu14.04 LTS更新源 不同的网络状况连接以下源的速度不同, 建议在添加前手动验证以下源的连接速度(ping下就行),选择最快的源可以节省大批下载时间. 首先备份源列表: sudo cp ...
- json的中括号和大括号的使用?
参考这篇文章: http://www.cnblogs.com/sgdkg/archive/2012/12/03/2799723.html json 变量有两种可能, 可能是一个对象, (类似 类的实例 ...
- -bash: sudo: command not found Error and Solution
文章转自: http://www.cyberciti.biz/faq/debian-ubuntu-rhel-centos-linux-bash-sudo-command-not-found/ 安装su ...
- COCOS2D 释放资源的最佳时机
有场景A跟场景B,场景A是当前场景,场景B是将要替换的新场景. 那么A场景的资源释放最佳时机是在什么时候呢? 这是释放资源的代码(注意要按这个顺序释放): 1 2 3 4 CCAnimationCac ...