M4ritimeSeeker

PASS Week 2: C Structure and Syntax

Sep 5th, 2021
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. PROBLEM #1
  2.  
  3. Using the C Program Structure discussed earlier, MATCH EACH LINE OF THE HELLO WORLD PROGRAM WITH
  4. THE CORRECT SECTION. Some of the sections WON'T match up to a line of code, and others may match MULTIPLE LINES.
  5. We cover printf and scanf in greater detail in Canvas Module 3.
  6.  
  7. SECTIONS OF C STRUCTURE:
  8. 1) Local statements/declarations
  9. 2) Preprocessor directives
  10. 3) Global declarations
  11. 4) Other functions
  12. 5) Main function
  13.  
  14.  
  15. PROGRAM:
  16.  
  17. #include <stdio.h>
  18.  
  19. int main(void)
  20. {
  21.  
  22. printf(“Hello World!!\n”);
  23. return 0;
  24.  
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. PROBLEM #2 Error checking and correcting activity
  39.  
  40.  
  41. Copy the source code below exactly into the IDE of your choice (Replit preferred). Attempt to compile it.
  42. Examine the errors and fix them one at a time starting with the first error on top.
  43. Ask me about the scanf() and printf() modifiers if you need help.
  44.  
  45. Broken Program Source Code:
  46.  
  47.  
  48. /**************************************************
  49. * Top comment code is not filled for this example.
  50. * You would put your
  51. * N number here too.
  52. **************************************************
  53. #include <stdioh>
  54.  
  55. int main(int)
  56. {
  57.  
  58. int age_In = 0:
  59. print("Enter in your age please.\n");
  60. scanf("%d", age_in);
  61. printf("You told me your age is: %f\n");
  62. return;
  63.  
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. PROBLEM #3 Commenting your source code properly
  83.  
  84. Using the fixed code from problem #2, add comments to the program.
  85. Use the comments to label each section of code and describe what they do.
  86. Also fill in the top comment with the proper format (Hint: Check the "Comments" Module on Canvas for the format).
  87. Refer to Zybook section 2.8 for help as well.
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. PROBLEM #4: Moving Code around text editors
  104.  
  105. For this problem, completed sample code has been provided below.
  106. The goal of this problem is to copy-paste this program around some text editors until we get it onto the Osprey Server.
  107.  
  108. Take the following code and copy it. Then do the following steps:
  109. -Paste it in replit.
  110. -Copy it again from replit, and then paste it in a blank word document.
  111. -Copy it from the word document, and paste it back into replit.
  112. -Check if any errors have occurred in the program. If none, go to next step.
  113. -Download the program file from Replit.
  114. -Login to the Osprey Server
  115. -Transfer the Program file from your home computer to the Osprey Server
  116. -Compile and run the program on Osprey and make sure it works.
  117.  
  118.  
  119. #include <stdio.h>
  120.  
  121. #define DOLLARS 9999
  122. #define CENTS 99
  123.  
  124. int main()
  125. {
  126. const short int VALUE1 = -32768;
  127. unsigned int value2 = 4294967295;
  128. float moreMoney = 199.955;
  129. printf("The value of Dollars and Cents is: %d.%d\n", DOLLARS, CENTS);
  130. printf("The value of moreMoney is : %lf\n", moreMoney);
  131. printf("The value of the short integer is: %d\n", VALUE1);
  132. printf("The value of the short unsigned integer is: %d\n", value2);
  133. return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment