C 语言 homework(2)

《C语言程序设计》实验报告
学  号	160809215	姓  名	韩笑	专业、班	计科16-2班
学    期	2016-2017 第1学期	指导教师	黄俊莲 吴喆
实验地点	C区二层机房	机 器 号
上课时间	2016年 9 月 22 日    2 周 周四  1-4 节
截止时间	2016年 9 月 28 日    3 周 周三 12:00
实验任务清单	1.	实验2-1 输入3个数,并按由大到小的顺序输出。
2.	实验2-2 从键盘上输入x的值,并根据计算输出y的值

3.	实验2-3从键盘上输入一个字母,如果是小写字母,将其转换成大写字母并输出。
4.	实验2-4从键盘上输入x的值,并根据计算输出y的值

5.	实验2-5 给出一个百分制的成绩,要求出成绩等级’A’、’B’、’C’、’D’、’E’,其中90分以上输出’A’,80~89输出’B’,70~79输出’C’,60~69输出’D’,60分以下输出’E’。
教师评语
	成绩

实验2  选择结构程序设计

实验2-1 输入3个数,并按由大到小的顺序输出。
实验要求:
编写一个C程序,输入3个数,并按由大到小的顺序输出。
参考:

源码:
#include <stdio.h>
int main(){
   int a,b,c,t;
printf("212,219,208;");
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 0;
}
运行结果抓图

实验2-2 从键盘上输入x的值,并根据计算输出y的值
实验要求:从键盘上输入x的值,并根据计算输出y的值

提示:
1.	使用数据函数需要#include <math.h>
2.	开方函数:sqrt(x)
3.	绝对值函数:fabs(x)
源码
include <stdio.h>
#include <math.h>
    int  main(){
    float x,y;
    printf("请输入一个数");
        scanf("%f",&x);
        if(x>4){
        y=sqrt(x-4);
        printf("%f",y);
     }
        else if(x<-5){
        y=fabs(x);
         printf("%f",y);
     }
        else{
        y=x+3;
        printf("%f",y);
    }
    return 0;
}
实验结果:

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

2.#include <stdio.h>
int main()
{
    printf("请输入一个字母:");
    char c;
    c=getchar();
    if(c<=‘z‘ && c>=‘a‘)
    c=c-32;
    putchar(c);
}
运行结果抓图

实验2-4从键盘上输入x的值,并根据计算输出y的值
实验要求:从键盘上输入x的值,并根据计算输出y的值

程序源码
#include <math.h>
#include <stdio.h>
int main(){
int x,y;
printf("输入X:");
scanf("%d",&x);
if(x<1){
  y=x;
 printf("%d\n",y);
}
else if(1<=x<10){
y=(2*x-1);
printf("%d\n",y);
}
  else{
y=(3*x-11);
  printf("%d\n",y);
}运行结果抓图


实验2-5 给出一个百分制的成绩,要求出成绩等级’A’、’B’、’C’、’D’、’E’,其中90分以上输出’A’,80~89输出’B’,70~79输出’C’,60~69输出’D’,60分以下输出’E’。
实验要求:
给出一个百分制的成绩,要求出成绩等级’A’、’B’、’C’、’D’、’E’,其中90分以上输出’A’,80~89输出’B’,70~79输出’C’,60~69输出’D’,60分以下输出’E’。
提示:
本实验要求同学们采用两种方法来完成:
方法一:使用if语句完成
方法二:使用switch语句完成。
程序源码
# include <stdio.h>
int main(){
  int a;
  printf("请输入成绩;");
  while(scanf("%d",&a)   &&  a >= 0  &&  a <= 100)
  if(a>=90)
     {printf("A");}
  else if(a<=89&a>=80){
     printf("B");}
  else if(a<=79&a>=70)
     {printf("C");}
  else if(a<=69&a>=60){
    printf("D");
      }
   else if(a<60){
     printf("E");
      }
}
运行结果抓图 


实验心得
感觉制作起来脑子里有点乱 有时候还是会忽略一些细节 比如一个字母一个标点等等 就是每个程序都有个固定的模板 然后按照模板慢慢运用 还是熟练度的问题 多思考多实践 应该会操作的越来越熟练吧!

  

时间: 2024-08-01 23:03:32

C 语言 homework(2)的相关文章

C语言 homework(4)

#include <stdio.h> int main(){ int i,sum=0; i=1; while(i<=100) { sum+=i; i++; } printf("sum=%d\n",sum); return 0; } #include <stdio.h> int main(){ int i,sum=0; i=1; sum=0; do{ sum+=i; i++; }while(i<=100); printf("sum=%d\n&

UVa 12412 A Typical Homework(学生信息管理系统)

A Typical Homework(a.k.a Shi Xiong Bang Bang Mang) Hi, I am an undergraduate student in institute of foreign languages. As you know, C programming is a required course in our university, even if his/her major is far from computer science. I don't lik

C语言 cgi(2)

1Columbia Universitycs3157 – Advanced ProgrammingSummer 2014, Lab #3, 40 pointsJune 10, 2014This lab is due June 23rd 11:59 pm.• lab in C. We will be using Makefiles.• Don’t forget to FREE up any memory you request!!• Make sure you complete the relev

C语言 cgi(3)

1cs3157 – Advanced ProgrammingSummer 2014, Project 1, 150 pointsJune 17, 2014Follow these step-by-step instructions. This homework must be submitted electronically bySunday night July 6th, 11pm. Please start early, so we can help if you get stuck.In

C语言cgi(1)

1Columbia Universitycs3157 – Advanced ProgrammingSummer 2014, Lab #2, 60ish pointsJune 9, 2014Follow these step-by-step instructions. This lab must be submitted electronically by Monday June16th, 11:55 pm.The point of the labs is to teach and reinfor

C语言程序代写(qq:928900200)

1cs3157 – Advanced ProgrammingSummer 2014, Project 1, 150 pointsJune 17, 2014Follow these step-by-step instructions. This homework must be submitted electronically bySunday night July 6th, 11pm. Please start early, so we can help if you get stuck.In

TCP 、UDP网络编程作业代写、代写C 语言 TCP程序 Network Programming using C

TCP .UDP网络编程作业代写.代写C 语言 TCP程序Network Programming using COverview? This homework is due by 11:59:59 PM on Thursday, April 26, 2018.? This homework will count as 8% of your final course grade.? This homework is to be completed individually. Do not shar

hOmewOrk 第三单元 总结

hOmewOrk 第三单元 总结 JML理论基础梳理 JML是用于对Java程序进行规格化设计的一种表示语言. 1. 注释结构 JML表示规格的内容包含在注释之中.可以使用行注释和块注释.行注释的表示方式为 //@annotation ,块注释的方式为 /* @ annotation @*/ . 2. JML表达式 JML表达式是在基于JAVA语法基础上,新增了一些操作符和和原子表达式组成的. 2.1 原子表达式 \result表达式:表示方法执行后的返回值. \old( expr )表达式:用

ECON 331 - Homework

ECON 331 - Homework #1due in class October 2nd at 2.30pmLate homework will not be considered. Show detailed calculations and/or provide detailedexplanations to get full credit. Partial credit may be given.• Exercise 1. Show by recurrence that the fol