fork download
  1. /* Task: CW1PTP1 - A simple C program
  2.   Author: Mohammad Masarwa
  3.   Student ID: M01090613
  4.   This is a comment block, as shown in the Week 1 Lab Sheet.
  5. */
  6.  
  7. // We must include stdio.h to use the printf function
  8. #include <stdio.h>
  9.  
  10. // The main function is the starting point of the program [cite: 1163]
  11. int main(void) {
  12.  
  13. // --- Part 1: Display Personal Information ---
  14. // Using the standard printf function to output text
  15. printf("--- My Details ---\n");
  16. printf("Name: Mohammad Masarwa\n");
  17. printf("Student ID: M01090613\n");
  18. printf("Degree Programme: Cyber Security and Digital Forensics\n");
  19. printf("Reason for studying: Because I love the challenges that keep rising in this industry.\n\n");
  20.  
  21. // --- Part 2: Perform Calculations ---
  22.  
  23. // Declare variables for calculation, similar to Week 1 & 3 labs [cite: 1202, 753]
  24. // Using digits 9 and 6 from Student ID M01090613 for the four operations
  25. double num1 = 9.0;
  26. double num2 = 6.0;
  27.  
  28. // Perform the four arithmetic operations
  29. double sum = num1 + num2;
  30. double difference = num1 - num2;
  31. double product = num1 * num2;
  32. double quotient = num1 / num2;
  33.  
  34. // Display the calculation results using printf with format specifiers
  35. printf("--- Student ID Calculations (using %.0f and %.0f) ---\n", num1, num2);
  36. printf("%.0f + %.0f = %.2f\n", num1, num2, sum); // Addition
  37. printf("%.0f - %.0f = %.2f\n", num1, num2, difference); // Subtraction
  38. printf("%.0f * %.0f = %.2f\n", num1, num2, product); // Multiplication
  39. printf("%.0f / %.0f = %.2f\n", num1, num2, quotient); // Division
  40.  
  41. // Return 0 to indicate successful termination [cite: 1172]
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0.01s 5316KB
stdin
2 2 2 2 2 2 2 2 2
10 90 16 78 1 2 3 100 1000
0 0 0 0 0 0 0 0 0
1 3 3 5 3 3 9 3 3
69 804 872 531 431 698 692 480 859
1 2 3 4 5 6 7 8 9 
1000 200 1500 350 5000 1000 1000 2000 13000 
5 10 5 20 10 5 10 20 10 
60 20 1000 1000 60 20 10000 20 500 
20 1000 50 2000 50 500 1500 20 3000 
20 1000 50 2000 50 5000 1500 20 30
stdout
--- My Details ---
Name: Mohammad Masarwa
Student ID: M01090613
Degree Programme: Cyber Security and Digital Forensics
Reason for studying: Because I love the challenges that keep rising in this industry.

--- Student ID Calculations (using 9 and 6) ---
9 + 6 = 15.00
9 - 6 = 3.00
9 * 6 = 54.00
9 / 6 = 1.50