Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views3 pages

CHAN Lab9

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

Intro to C Programming & Unix

Lab 9 (100 Points)


Mohamed Almukhtar
Due: November 20th, 2023, 11:59PM
(Total 2 pages)

Instructions:
 Please answer each question in this document separately.
 Rename the submission file to Lab#_<lastname>. Replace # with the lab
number and <lastname> with your last name (e.g., Lab9_Almukhtar).

Exercise 1: (Total 50 points) Write a C program that performs the following


tasks. Submit the c file and add a screenshot of the terminal results to this
document.

 Include the C file header (template is below) and add your information. (5
Points)
 Declare a 1-D array of size 6 and initialize its values to [6, 8, 4, 2, 7, 9]. (5
Points)
 Declare an int variable named sum and prompt the user to enter the target
sum and store it in sum. (5 Points)
 Print the array on the terminal. (5 Points)
 Find the first pair of numbers in the array that add up to the value of sum.
And print their indexes If no pair is found, print an appropriate message. (30
Points)

Note: More than one pair might sum up to the target, but we are only interested in the first.

Expected output Exercise 1:

Please enter the target: 15

Array: [6, 8, 4, 2, 7, 9]

First matching pair index: (0, 5)


Exercise 2: (Total 50 points) Write a C program that performs the following
tasks. Submit the c file and add a screenshot of the terminal results to this
document.

 Include the C file header (template is below) and add your information. (5
Points)
 Declare a 2-D array of integers with dimensions 4x4 and initialize it
with any values of your choice. (5 Points)
 Print the array on the terminal. (5 Points)
 Calculates the sum of the primary diagonal elements of the array (from
top left to bottom right). (15 Points)
 Find the largest element in the whole array. (15 Points)
 Print the sum of the diagonal elements and the largest element on the
terminal. (5 Points)

Expected output Exercise 2:


Array:
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1

Diagonal sum: 34
Largest element in the array: 16

C File header:

/* Filename: <FileName>

* Author: <YourName>

* Description: <Description>
*/

You might also like