fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.  
  5.  
  6. // Ask the user to enter his/her name
  7. char name[10];
  8. printf("Enter your name: ");
  9. fgets(name, 10, stdin);
  10. printf("Hello %s! \n", name);
  11.  
  12. // Ask the user to enter his/her age
  13. int age;
  14. printf("Enter your age: ");
  15. scanf("%d", &age);
  16. printf("You are %d \n", age);
  17.  
  18. if (age <= 20) {
  19. printf("You're a youngster!");
  20. }
  21.  
  22. // If the user is over 20, but under 61, display the name and age, and tell the user he/she is an adult.
  23. if (age < 20 ) {
  24. printf("You're an adult!");
  25. }
  26. if (age > 61) {
  27. printf("You're an adult!");
  28. }
  29.  
  30. // If the user is over 60, display the name and age, and tell the user he/she is getting on in years.
  31. if (age > 60 ) {
  32. printf("You're getting on in years!");
  33. }
  34.  
  35. else {
  36. printf("Sorry! There is no way to determine how old you are! \n");
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 4476KB
stdin
Name: Mark
Age: 18
Because Mark's age is under 20, he will view an output stating "You're a youngster."
stdout
Enter your name: Hello Name: Mar! 
Enter your age: You are 528880064 
You're an adult!You're getting on in years!