adding cs142 code
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
CPPFLAGS=-Wall -g -std=c++0x
|
||||
|
||||
all: main
|
||||
|
||||
test: all
|
||||
./main
|
||||
|
||||
clean:
|
||||
@rm -rfv main.o main
|
||||
@@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
float a = 12.123456;
|
||||
float b = 12.125100;
|
||||
|
||||
cout << a << " " << b << " " << endl;
|
||||
cout << setiosflags(ios::fixed) << setprecision(2) << a << " " << b << " " << endl;
|
||||
|
||||
printf("%0.2f %0.2f\n", a, b);
|
||||
fprintf(stdout, "%0.2f %0.2f\n", a, b);
|
||||
fprintf(stderr, "%0.2f %0.2f\n", a, b);
|
||||
|
||||
double input;
|
||||
cin >> input;
|
||||
double intpart = 0;
|
||||
double fracpart = modf(input, &intpart);
|
||||
printf("%f %f\n", intpart, fracpart);
|
||||
|
||||
if (fracpart == 0.5) {
|
||||
cout << "exactly 0.5" << endl;
|
||||
}
|
||||
else {
|
||||
cout << "not exactly 0.5" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user