实验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 选择结构程序设计的更多相关文章

  1. 160809209_李梦鑫_C语言程序设计实验2+选择结构程序设计_进阶

    <C语言程序设计>实验报告 学 号 160809209 姓 名 李梦鑫 专业.班 计科16-2班 学    期 2016-2017 第1学期 指导教师 黄俊莲 吴喆 实验地点 C05 机 ...

  2. 160809212田京诚C语言程序设计实验2 选择结构程序设计_进阶

    实验2-6 猜数字游戏 实验要求: 编写一个C程序实现一个[1-100]以内的猜数字游戏. (1)       系统随机产生一个[1-100]之间的随机数. (2)       输入任意一个数字.数字 ...

  3. 160809209_李梦鑫_C语言程序设计实验2 选择结构程序设计

    实验2-1 输入3个数,并按由大到小的顺序输出. 实验要求: 编写一个C程序,输入3个数,并按由大到小的顺序输出. 源码:#include <stdio.h> int main() { i ...

  4. 学号160809224姓名黄家帅c语言程序设计实验2 选择结构程序设计

    实验2-1 输入3个数,并按由大到小的顺序输出. 实验要求: 编写一个C程序,输入3个数,并按由大到小的顺序输出. 源码: #include <stdio.h>void main(){ i ...

  5. 学号160809212姓名田京诚C语言程序设计实验2选择结构程序设计

    编写一个C程序,输入3个数,并按由大到小的顺序输出. 1 #include <stdio.h> void main(){ int a,b,c,t; printf("请输入三个整数 ...

  6. 160809225_叶桦汀_C语言程序设计实验2 选择结构程序设计_进阶

    #include<stdio.h> #include<math.h> int main() { int a,b,c,l,p,s; printf("请输入三个数:&qu ...

  7. 160809209_李梦鑫_C语言程序设计实验3 循环结构程序设计

    <C语言程序设计>实验报告 学 号 160809209 姓 名 李梦鑫 专业.班 计科16-2班 学    期 2016-2017 第1学期 指导教师 黄俊莲 吉吉老师 实验地点 C05 ...

  8. 160809228_符瑞艺_C语言程序设计实验3 循环结构程序设计

      #include <stdio.h> int main(){ //使用for循环完成1+2+......+100 ; ;i<=;i++) sum +=i; //sum = sum ...

  9. 【C语言】第4章 选择结构程序设计

    第4章 选择结构程序设计 C语言有两种选择语句: if 语句,实现两个分支的选择结构 switch 语句,实现多分支的选择结构 输入3个数a,b,c,要求按由小到大的顺序输出. 可以先用伪代码写出算法 ...

随机推荐

  1. 安装vim的ycm

    环境centos 6.7 vim 7.3 安装vundle Vundle(Vim bundle)是一个Vim的插件管理器.它是把git操作整合进去,用户需要做的只是去GitHub上找到自己想要的插件的 ...

  2. re正则表达式7_{}

    curly brackets {} instead of one number, you can specify a range by writing a minimum,a comma,and a ...

  3. HTML5学习预览

    HTML5中,新增了很多input元素的类型 email         email类型用于应该包含 e-mail 地址的输入域. url         url 类型用于应该包含 URL 地址的输入 ...

  4. ubuntu下samba服务器的安装与配置

    参考网址:http://jingyan.baidu.com/album/00a07f38b9194082d028dc08.html?picindex=9 sudo service smbd resta ...

  5. LeetCode —— Invert Binary Tree

    struct TreeNode* invertTree(struct TreeNode* root) { if ( NULL == root ) { return NULL; } if ( NULL ...

  6. Spring的Bean之Bean的基本概念

    从前面我们知道spring其实就是一个大型的工厂,而Spring容器中的Bean就是该工厂的产品.对于Spring容器能够生产那些产品,则取决于配置文件中配置. 对于我们而言,我们使用Spring框架 ...

  7. jQuery 参考手册 - 遍历

    jQuery 参考手册 - 遍历 jQuery Ajax jQuery 数据 jQuery 遍历函数 jQuery 遍历函数包括了用于筛选.查找和串联元素的方法. 函数描述 .add()将元素添加到匹 ...

  8. 用apache-cxf生成webservice客户端的时候报错Parameter: shead already exists for method

    版本apache-cxf-3.1.0 命令如下:wsdl2java -p com.wz.interfaces -d ./src -client ./ws/xxx.wsdl 报错如下: WSDLToJa ...

  9. 跳出iframe

    摘要 有时候需要用到iframe,但里面的单击里面的链接的时候,总是在该iframe中打开. 解决办法 其实解决起来也很简单. 在iframe中的head标签中添加下面的标签即可. <base ...

  10. SQL Server2008窗口计算

    (一) 窗口的定义:指为用户指定的一组行,也称着"分区".如下图所示的窗口分区.每一个班级看作是一个数据窗口,一共有三个窗口 (二)窗口计算的相关方法 1)over()用法  格式 ...