0% found this document useful (0 votes)
25 views12 pages

ChristopherF SCS 1101 Assignment 1

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)
25 views12 pages

ChristopherF SCS 1101 Assignment 1

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/ 12

CHRITOPHER FUNDIRWA: N02017580H

SCS 1101 INTRO TO C.S. AND PROGRAMMING


ASSIGNMENT

C PROGRAMMING

1. Write a C program that calculates the sum and product of two


matrices.
a)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #define max 3
4 int main()
5 {
6 int a[max][max],b[max][max],c[max][max],i,j,k;
7
8 printf("\nENTER VALUES FOR MATRIX-A\n");
9 for(i=0;i<max;i++)
10 {
11 for(j=0;j<max;j++)
12 {
13 scanf("%d",&a[i][j]);
14 }
15 }
16 printf("\nENTER VALUES FOR MATRIX-B\n");
17 for(i=0;i<max;i++)
18 {
19 for(j=0;j<max;j++)
20 {
21 scanf("%d",&b[i][j]);
22 }
23 }
24 for(i=0;i<max;i++)
25 {
26 for(j=0;j<max;j++)
27 {
28 c[i][j]=0;
29 for(k=0;k<max;k++)
30 {
31 c[i][j]+=a[i][k]*b[k][j];
32 }
33 }
34 }
35 printf("\nVALUES OF MATRIX-A\n");
36 for(i=0;i<max;i++)
37 {
38 for(j=0;j<max;j++)
39 {
40 printf("%d ",a[i][j]);
41 }
42 printf("\n");
43 }
44 printf("\nVALUES OF MATRIX-B\n");
45 for(i=0;i<max;i++)
46 {
47 for(j=0;j<max;j++)
48 {
49 printf("%d ",b[i][j]);
50 }
51 printf("\n");
52 }
53 printf("\nVALUES OF MATRIX-C\n");
54 for(i=0;i<max;i++)
55 {
56 for(j=0;j<max;j++)
57 {
58 printf("%d ",c[i][j]);
59 }
60 printf("\n");
61 }
62 return 0;
63 }
b)Write a C program that implements the quadratic formula in the
form x= −b ± √ b −4 ac
2

2a

1 #include <stdio.h>
2 #include <math.h>
3
4 int main()
5 {
6 float a, b, c, d;
7
8 printf("Enter a:");
9 scanf("%f", &a);
10 printf("Enter b:");
11 scanf("%f", &b);
12 printf("Enter c:");
13 scanf("%f",&c);
14
15 d= (b*b)-(4*a*c);
16 if (d<0){
17 printf("Roots are complex\n");
18 printf(" root 1 is %.3f + %.3fi", (-b/(2*a)), sqrt(-d)/(2*a));
19 printf(" root 2 is %.3f - %.3fi", (-b/(2*a)), sqrt(-d)/(2*a));
20 }
21 else if (d==0){
22 printf ("Roots are identical");
23 printf ("root is %.3f", -b/(2*a));
24 }
25 else {
26 printf("roots are real");
27 printf("root1 is %.3f",(-b/(2*a))+sqrt(d)/(2*a ));
28 printf("root2 is %.3f",(-b/(2*a))-sqrt(d)/(2*a ));
29
30 }
31 return 0;
32 }
c)Write a program thattakes an input of 10 integers into an array
and finds the number of odd numbers, the highest value, mean and
standard deviation.

1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main()
5 {
6 int a[10], i, odd=0, large=0, sum=0;
7 printf("Enter your integers:\n");
8 for(i=0; i<10; i++)
9 scanf("%d", &a[i]);
10
11 for(i=0; i<10; i++){
12 if(a[i]%2 == 0){
13
14 }
15 else {
16 odd++;
17 }
18 }
19 printf("Odd: %d\n", odd);
20
21 large=a[0];
22 for(i=0; i<10; i++){
23 if (a[i]> large){
24 large= a[i];
25 }
26 else {
27
28 }
29
30
31 }
32 sum= a[0];
33 for(i=0; i<10; i++){
34
35 sum+= a[i];
36 }
37
38
39
40 printf("Largest number is %d\n", large);
41 printf("mean is: %d", sum/10);
42 return 0;
43 }
d) Implement a program that checks when a number is a perfect square
1 #include <stdio.h>
2 #include <math.h>
3
4 int main()
5 {
6 int n;
7 double a, b;
8 printf("Enter the number :");
9 scanf("%d", &n);
10 a= sqrt(n);
11 b= (int)(a);
12 if (a==b){
13 printf("%d is a perfect aquare", n);
14
15 }
16 else {
17 printf("%d is not a perfect square", n);
18 }
19
20 return 0;
21 }
e) Explain recursion using an example.
Recursion is a process whereby a function calls itself as it will be coded in itself. The
program keeps calling itself until a particular set condition is met, otherwise it will
continuously call itself until possibly the computer crashes.
Below is a program that implements recursion to calculate the factorial of a number.
1 #include<stdio.h>
2 int fact(int);
3 int main() {
4 int num,f;
5 printf("\nEnter a number: ");
6 scanf("%d",&num);
7 f=fact(num);
8 printf("\nFactorial of %d is: %d",num,f);
9 return 0;
10 }
11 int fact(int n) {
12 if(n==1)
13 return 1; else
14 return(n*fact(n-1));
15 }
COMPUTER SCIENCE THEORY
2.
a) Explain the CIA Triad.
Confidentiality, Integrity and Availability, is a model that guides policies for information
security within organisations.
- Confidentiality is for measures designed to prevent sensitive information from
unauthorised access. It ensures access to information is on a need to know basis.
- Integrity involves ensuring that data is consistent, accurate, and trustworthy over its entire
use. It must not succumb to the broken telephone effect or be altered by unauthorised
persons.
- Availability means information should be readily accessible for authorized persons. This
involves proper maintenance of hardware and systems that store this information.
b) Report
TO : Management
FROM : Christopher Fundirwa
TITLE : Report on the advantages and disadvantages of adopting a wireless network
DATE : 10 April 2021
In light of the recommendation made the new network engineer, I prepared this report to
help you make an informed final decision. As with all systems, wireless systems have their
pros and cons. The pros are:
1. Mobility – the network users are able to access real-time information anywhere at
work.
2. Flexibility – wireless technology allows the network to go where wire cannot go,
even in the loo.
3. Cost of maintenance – the maintenance costs of wireless network are significantly
lower than for wired network.
4. Wireless networks can be easily configured according to the intended topology and
range of users to access and the area over which they will be accessing it.
On the other hand, the cons include:
1. Security – wireless networks are very susceptible to hacking as the network signals
extend beyond company walls.
2. Installation – it is a bit more difficult and costly to setup than wired network
3. Speed – the speed can be 2 – 50 times slower than wired network
4. The network is can be unstable
I believe these to be the major arguments for against wireless networks.

c) Explain any five functions of the Operating System


By definition, the Operating System is a program that acts as an intermediary between the
user and computer hardware. Five of its many functions are:
1. Program execution i.e. it enables the system to load a program into memory and run
it.
2. It computes and keeps record of computer usage statistics
3. File system manipulation i.e. enables the user to read, write, create and delete
system files
4. It detects errors in the CPU, memory, input/output devices operation and user
programs
5. Protection i.e. it ensures that access to system resources is controlled securely.

You might also like