ChristopherF SCS 1101 Assignment 1
ChristopherF SCS 1101 Assignment 1
C PROGRAMMING
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.