Experiment 2-1Enter 3 numbers and output in order from large to small. Experimental requirements: Write a C program, enter 3 numbers, and output in order from large to small. Reference: Source: #include<stdio.h>intMain () {inta,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 0; Run result screenshot
Experiment 2-2enter the value of x from the keyboard, and according to the value of the computed output Y experiment requires: Enter the value of x from the keyboard and prompt according to the value of the computed output y:1. Using data functions requires # include <math.h>2. Root function: sqrt (x)3. Absolute value function: Fabs (x) source # include<stdio.h>#include<math.h>intMain () {floatx, y; printf ("Please enter a number"); scanf ("%f",&x); if(x>4) {y=SQRT (x4); printf ("%f", y); } Else if(x<-5) {y=fabs (x); printf ("%f", y); } Else{y=x+3; printf ("%f", y); } return 0; } Experimental Results:
Experiment 2-3 Enter a letter from the keyboard, if it is a lowercase letter, convert it to uppercase and output. Experimental requirements: Enter a letter from the keyboard, if it is a lowercase letter, convert it to uppercase and output. Tips:1. Input character to variable CCharC; method one: C=GetChar (); method two: scanf ("%c",&c);2. Output character variable C method one: Putchar (c); method two: printf ("%c", c); Program Source # include<stdio.h>intMain () {CharC; printf ("Please enter a character: \ n"); scanf ("%c",&c); printf ("its uppercase characters are:%c\n", C- +);} Run result capture
Experiment 2-4 Enter the value of x from the keyboard and calculate the value of the output y according to the experiment requirements: Enter the value of x from the keyboard and calculate the value of the output y according to the program source # # #<stdio.h>intMain () {intx, y; printf ("Please enter a number \ n"); scanf ("%d",&x); if(x<1) {y=x; printf ("%d", y); } Else if(1<=x<Ten) {y=2*x-1; printf ("%d", y); } Else{y=3*x- One; printf ("%d", y); } return 0; }
Experimental experience through this experiment, I understand the C language some of the use of skills, so I move towards the C language this door again into a step, although this experiment than last time a few more steps, but also let me feel the charm of C language, this homework taught late, next homework I will pay early
Friei 160809228_c Language Programming experiment 2 selecting structure programming