0% found this document useful (0 votes)
10 views

Ics 2175 Introduction To Computer Programming Assignment I

intro to computer programming

Uploaded by

emmanuelmututa25
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)
10 views

Ics 2175 Introduction To Computer Programming Assignment I

intro to computer programming

Uploaded by

emmanuelmututa25
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
You are on page 1/ 4

ICS 2175 INTRODUCTION TO COMPUTER TO PROGRAMMING

ASSIGNMENT I
ENM 221- 0083/2023

Q1: Comparison of Von Neumann Architecture and Quantum Computers


Von Neumann Architecture:
 Structure: Consists of a CPU, memory, and input/output devices. The CPU includes an
arithmetic logic unit (ALU), control unit, and registers.
 Memory: Uses a single memory space for both instructions and data.
 Programming: Programs are written in classical programming languages like C, Python,
etc. Instructions are executed sequentially.
 Applications: Suitable for general-purpose computing tasks.
Quantum Computers:
 Structure: Utilizes qubits instead of classical bits. Key components include quantum
processors and quantum memory.
 Memory: Quantum memory can store superpositions of states, enabling parallelism.
 Programming: Programs are written using quantum programming languages like Qiskit,
Cirq, or Quipper. Quantum algorithms leverage principles like superposition and
entanglement.
 Applications: Ideal for solving complex problems in cryptography, optimization, and
simulation that are infeasible for classical computers.
Q2: Algorithm and Program for Computing Averages
Algorithm:
1. Initialize an array to store the scores of 50 students for 3 tests.
2. Input the scores for each student.
3. Compute the average score for each student.
4. Display the average scores.
5. Extend the algorithm to handle 6 different units.
C Program:
#include <stdio.h>
#define STUDENTS 50
#define TESTS 3
#define UNITS 6

void inputScores(float scores[STUDENTS][TESTS]) {


for (int i = 0; i < STUDENTS; i++) {
printf("Enter scores for student %d:\n", i + 1);
for (int j = 0; j < TESTS; j++) {
printf("Test %d: ", j + 1);
scanf("%f", &scores[i][j]);
}
}
}

void computeAndDisplayAverages(float scores[STUDENTS][TESTS]) {


for (int i = 0; i < STUDENTS; i++) {
float sum = 0;
for (int j = 0; j < TESTS; j++) {
sum += scores[i][j];
}
float average = sum / TESTS;
printf("Average score for student %d: %.2f\n", i + 1, average);
}
}

void inputUnitScores(float unitScores[UNITS][STUDENTS][TESTS]) {


for (int unit = 0; unit < UNITS; unit++) {
printf("Entering scores for Unit %d\n", unit + 1);
for (int i = 0; i < STUDENTS; i++) {
printf("Enter scores for student %d:\n", i + 1);
for (int j = 0; j < TESTS; j++) {
printf("Test %d: ", j + 1);
scanf("%f", &unitScores[unit][i][j]);
}
}
}
}

void computeAndDisplayUnitAverages(float unitScores[UNITS][STUDENTS][TESTS]) {


for (int unit = 0; unit < UNITS; unit++) {
printf("Averages for Unit %d\n", unit + 1);
for (int i = 0; i < STUDENTS; i++) {
float sum = 0;
for (int j = 0; j < TESTS; j++) {
sum += unitScores[unit][i][j];
}
float average = sum / TESTS;
printf("Average score for student %d in Unit %d: %.2f\n", i + 1, unit + 1, average);
}
}
}

int main() {
float scores[STUDENTS][TESTS];
float unitScores[UNITS][STUDENTS][TESTS];
// Input and compute averages for 3 tests
inputScores(scores);
computeAndDisplayAverages(scores);

// Input and compute averages for 6 units


inputUnitScores(unitScores);
computeAndDisplayUnitAverages(unitScores);

return 0;
}
This C program first handles the scores for three tests and then extends to six different units,
computing and displaying the average scores for each student.

You might also like