Browse Source

Add more prog exercices of chapter 04

master
T. Meissner 9 years ago
parent
commit
3d82fabc96
4 changed files with 78 additions and 0 deletions
  1. +17
    -0
      c_primer_plus/chapter04/03.c
  2. +19
    -0
      c_primer_plus/chapter04/04.c
  3. +20
    -0
      c_primer_plus/chapter04/05.c
  4. +22
    -0
      c_primer_plus/chapter04/06.c

+ 17
- 0
c_primer_plus/chapter04/03.c View File

@ -0,0 +1,17 @@
#include <stdio.h>
#include <string.h>
int main (void) {
float number;
printf("Give a float number: ");
scanf("%g", &number);
printf("The input is %.1f or %.1e\n", number, number);
printf("The input is %+.3f or %.3e\n", number, number);
return 0;
}

+ 19
- 0
c_primer_plus/chapter04/04.c View File

@ -0,0 +1,19 @@
#include <stdio.h>
#include <string.h>
int main (void) {
float height;
char name[21];
printf("Give your heigth in cm: ");
scanf("%f", &height);
printf("Give your name: ");
scanf("%20s", name);
printf("%s, you are %.3f m tall\n", name, height/100);
return 0;
}

+ 20
- 0
c_primer_plus/chapter04/05.c View File

@ -0,0 +1,20 @@
#include <stdio.h>
#include <string.h>
int main (void) {
float speed;
float size;
printf("Give download speed in Mbit/s: ");
scanf("%f", &speed);
printf("Give file size in Mbytes: ");
scanf("%f", &size);
printf("At %.2f megaits per second, a file of %.2f megabytes\n", speed, size);
printf("downloads in %.2f seconds\n", size*8/speed);
return 0;
}

+ 22
- 0
c_primer_plus/chapter04/06.c View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <string.h>
int main (void) {
char first_name[21];
char last_name[21];
printf("Give your first name: ");
scanf("%20s", first_name);
printf("Give your last name: ");
scanf("%20s", last_name);
printf("%s %s\n", first_name, last_name);
printf("%*lu %*lu\n", (int)strlen(first_name), strlen(first_name), (int)strlen(last_name), strlen(last_name));
printf("%s %s\n", first_name, last_name);
printf("%-*lu %-*lu\n", (int)strlen(first_name), strlen(first_name), (int)strlen(last_name), strlen(last_name));
return 0;
}

Loading…
Cancel
Save