0% found this document useful (0 votes)
14 views4 pages

C Program for Student Grades and Matrix Sum

The document contains two C programming tasks. The first task involves inputting a student ID and grade, then outputting the corresponding result based on the grade. The second task involves inputting elements of a 3x3 matrix and calculating the sum of its main diagonal elements.

Uploaded by

daliaabusamra125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

C Program for Student Grades and Matrix Sum

The document contains two C programming tasks. The first task involves inputting a student ID and grade, then outputting the corresponding result based on the grade. The second task involves inputting elements of a 3x3 matrix and calculating the sum of its main diagonal elements.

Uploaded by

daliaabusamra125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

:‫السؤال األول‬

>include <stdio.h#

{ )(int main

;int studentID

;char grade

;printf("Enter Student ID: ")

;scanf("%d", &studentID)

;printf("Enter Grade (A, B, C, ...): ")

;scanf(" %c", &grade)

;printf("\nStudent ID: %d\n", studentID)

;printf("Final Result: ")

{ switch (grade)

:'case 'A

:'case 'a

;printf("Excellent\n")

;break

:'case 'B

:'case 'b

;printf("Very Good\n")

;break

:'case 'C

:'case 'c

;printf("Good\n")

;break

:default

;printf("Fail\n")

}
;return 0

:‫إدخال‬ •

Enter Student ID: 12345

Enter Grade (A, B, C, ...): A

:‫إخراج‬

Student ID: 12345

Final Result: Excellent

:‫إدخال‬ •

Enter Student ID: 54321

Enter Grade (A, B, C, ...): F

:‫إخراج‬

Student ID: 54321

Final Result: Fail

:‫السؤال الثاني‬
>include <stdio.h#
{ )(int main

;int matrix[3][3]

;int sum = 0

;printf("Enter the elements of the 3x3 matrix:\n")

{ for (int i = 0; i < 3; i++)

{ for (int j = 0; j < 3; j++)

;printf("Element [%d][%d]: ", i + 1, j + 1)

;scanf("%d", &matrix[i][j])

}
}

{ for (int i = 0; i < 3; i++)

;sum += matrix[i][i]

;printf("\nSum of the main diagonal elements: %d\n", sum)

;return 0

:‫اإلدخال‬ •

Element [1][1]: 1

Element [1][2]: 2

Element [1][3]: 3

Element [2][1]: 4

Element [2][2]: 5

Element [2][3]: 6

Element [3][1]: 7
Element [3][2]: 8

Element [3][3]: 9

:‫اإلخراج‬ •

Sum of the main diagonal elements: 15

You might also like