Add homework for BUPT Sep 23
This commit is contained in:
parent
8f163af26b
commit
1461008519
10
pset1/1-add.c
Normal file
10
pset1/1-add.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
// initialization
|
||||
int i1, i2;
|
||||
// get input from user
|
||||
scanf("%i %i", &i1, &i2);
|
||||
// print answer!!
|
||||
printf("The sum is %i and the difference is %i.", i1 + i2, i1 - i2);
|
||||
}
|
16
pset1/2-stdio.c
Normal file
16
pset1/2-stdio.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//initialization
|
||||
char sex;
|
||||
int age;
|
||||
float height;
|
||||
|
||||
//get input from stdin
|
||||
scanf("%c %i %f", &sex, &age, &height);
|
||||
|
||||
//print answer to stdout
|
||||
printf("The sex is %c, the age is %i, and the height is %f.", sex, age, height);
|
||||
return 0;
|
||||
}
|
12
pset1/3-math.c
Normal file
12
pset1/3-math.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
// initialization
|
||||
double a, b, c, d;
|
||||
scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
|
||||
|
||||
// print answer
|
||||
printf("%lf", (a + b) * (a - b) + c / d);
|
||||
|
||||
return 0;
|
||||
}
|
15
pset1/4-pi.c
Normal file
15
pset1/4-pi.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
|
||||
const double PI = 3.14159265;
|
||||
|
||||
int main(void) {
|
||||
// initialize values
|
||||
double radius;
|
||||
scanf("%lf", &radius);
|
||||
|
||||
// print answer
|
||||
printf("The perimeter is %.4lf, the area is %.4lf.\n", PI * radius * 2,
|
||||
PI * radius * radius);
|
||||
|
||||
return 0;
|
||||
}
|
27
pset1/5-data-types.c
Normal file
27
pset1/5-data-types.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
//initialize variables
|
||||
char a;
|
||||
short b;
|
||||
int c;
|
||||
long d;
|
||||
long long e;
|
||||
float f;
|
||||
double g;
|
||||
|
||||
//assign values from stdin
|
||||
scanf ("%c %hd %i %ld %lld %f %lf", &a, &b, &c, &d, &e, &f, &g);
|
||||
|
||||
//print answers
|
||||
printf("The 'char' variable is %c, it takes %ld byte.\n", a, sizeof(a));
|
||||
printf("The 'short' variable is %hd, it takes %ld bytes.\n", b, sizeof(b));
|
||||
printf("The 'int' variable is %i, it takes %ld bytes.\n", c, sizeof(c));
|
||||
printf("The 'long' variable is %ld, it takes %ld bytes.\n", d, sizeof(d));
|
||||
printf("The 'long long' variable is %lld, it takes %ld bytes.\n", e, sizeof(e));
|
||||
printf("The 'float' variable is %f, it takes %ld bytes.\n", f, sizeof(f));
|
||||
printf("The 'double' variable is %lf, it takes %ld bytes.\n", g, sizeof(g));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue