M4ritimeSeeker

PASS Week 4/7 Solutions

Apr 5th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. Week 4/7 SOLUTIONS
  2.  
  3. PROBLEM 1
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. int main(void)
  9. {
  10. char ary[] = "2019";
  11. char* str = NULL;
  12. char* str2 = "2021";
  13.  
  14. printf("%s %d\n", ary, (int)strlen(ary));
  15. printf("%s %d\n", str, (int)strlen(str));
  16. printf("%s %d", str2, (int)strlen(str2));
  17.  
  18. return 0;
  19. }
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. PROBLEM 2
  33.  
  34. #include <stdio.h>
  35. #include <string.h>
  36.  
  37. int main(void)
  38. {
  39. char ary[] = "Godzilla is gonna win";
  40. //char* ary = "Godzilla is gonna win";
  41.  
  42. for (int i = strlen(ary); i >= 0; i--){
  43. printf("%c", ary[i]);
  44. }
  45.  
  46. return 0;
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. PROBLEM 2B
  60.  
  61. #include <stdio.h>
  62. #include <string.h>
  63.  
  64. int main(void)
  65. {
  66. char ary[] = "Godzilla is gonna win.";
  67.  
  68. printf("%s", ary);
  69.  
  70. return 0;
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. Problem 3
  91.  
  92. #include <stdio.h>
  93. #include <string.h>
  94.  
  95. int main(void)
  96. {
  97. char str[80] = "";
  98.  
  99. printf("Enter in a sentence up to 80 characters: ");
  100. fgets(str, 80, stdin);
  101. printf("\n");
  102.  
  103. printf("Here is your sentence: %s", str);
  104.  
  105. return 0;
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. Problem 4
  126.  
  127. #include <stdio.h>
  128. #include <string.h>
  129. #include <ctype.h>
  130.  
  131. int main(void)
  132. {
  133. char str[80] = "";
  134.  
  135. printf("Enter in a sentence up to 80 characters: ");
  136. fgets(str, 80, stdin);
  137. printf("\n");
  138.  
  139. printf("Here is your sentence: %s", str);
  140.  
  141. for (int i = 0; i < strlen(str); i++){
  142. if (isupper(str[i])){
  143. printf("%c is Uppercase\n", str[i]);
  144. }
  145. else if (islower(str[i])){
  146. printf("%c is Lowercase\n", str[i]);
  147. }
  148. else{
  149. printf("\n");
  150. }
  151. }
  152. return 0;
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161. Problem 4B
  162.  
  163. [Don't have one lol]
Advertisement
Add Comment
Please, Sign In to add comment