talkback.c 769 B

12345678910111213141516171819202122232425
  1. // talkback.c -- nosy, informative program
  2. #include <stdio.h>
  3. #include <string.h> // for strlen() prototype
  4. #define DENSITY 62.4 // human density in lbs per cu ft
  5. int main()
  6. {
  7. float weight, volume;
  8. int size, letters;
  9. char name[40]; // name is an array of 40 chars
  10. printf("Hi! What's your first name?\n");
  11. scanf("%s", name);
  12. printf("%s, what's your weight in pounds?\n", name);
  13. scanf("%f", &weight);
  14. size = sizeof name;
  15. letters = strlen(name);
  16. volume = weight / DENSITY;
  17. printf("Well, %s, your volume is %2.2f cubic feet.\n",
  18. name, volume);
  19. printf("Also, your first name has %d letters,\n",
  20. letters);
  21. printf("and we have %d bytes to store it.\n", size);
  22. return 0;
  23. }