You are on page 1of 4

PART A QUESTION 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

/***********************************************************************
Author
:
Mohammad Aiman Bin Mahmad Suhaimi CE099005
Muhammad Zulhusni Bin Che Razali CE097466
Course
:
CSEB113
Section
:
04B
Date
: 04 DECEMBER 2016
Brief Description
:
Pseudocode :
Test Data
:
************************************************************************/
#include<stdio.h>
void main()
{
int num, firstN, secondN, thirdN, temp;
printf("Number [enter 3 digits] = ");
scanf("%d", &num);
firstN = num / 100;
printf("First Digit = %d\n", firstN);
temp = num % 100;
secondN = temp / 10;
printf("Second Digit = %d\n", secondN);

thirdN = temp % 10;


printf("Third Digit = %d\n\n", thirdN);

PART A QUESTION 2
/***********************************************************************
Author
:
Mohammad Aiman Bin Mahmad Suhaimi CE099005
Muhammad Zulhusni Bin Che Razali CE097466
Course
:
CSEB113
Section
:
04B
Date
: 04 DECEMBER 2016
Brief Description
:
Pseudocode :
Test Data
:
************************************************************************/

1
2
3
4
5
6
7
8
9
10
11 #include <stdio.h>
12
13 void main()
14 {
15
int n, i, flag = 0, repeat;
16
17
do {
18
printf("Enter a number: ");
19
scanf("%d", &n);
20
21
if (n != 0)
22
{
23
24
for (i = 2; i <= n / 2; ++i)
25
{
26
// condition for nonprime number
27
if (n%i == 0)
28
{
29
flag = 1;
30
break;
31
}
32
}
33
34
if (flag == 0)
35
printf("%d is a prime number.\n\n", n);
36
37
else
38
printf("%d is not a prime number.\n\n", n);
39
40
}
41
42
} while (n != 0);
43
44
printf("Bye...!\n\n");
45
46

PART B QUESTION 4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

/***********************************************************************
Author
:
Mohammad Aiman Bin Mahmad Suhaimi CE099005
Muhammad Zulhusni Bin Che Razali CE097466
Course
:
CSEB113
Section
:
04B
Date
: 04 DECEMBER 2016
Brief Description
:
Pseudocode :
Test Data
:
************************************************************************/
#include <stdio.h>
void main()
{
int choice;
do {
printf("Welcome to Mathematical Games!!! This game offered two (2) choices.\n"
"Please choose either 1 or 2 [enter 3 will terminate this game]: ");
scanf("%d", &choice);
if (choice != 3)
{
if (choice == 1)
{
int n, i, sum = 0;
printf("\nEnter the value for n: ");
scanf("%d", &n);
if (n < 0)
printf("\a\a\a\a\aError!!! Only accept a positive value\n\n");
else
{
for (i = 2; i <= n; i += 2)
{
sum = sum + i;
}
printf("The sum of even numbers between 1 to %d is %d\n", n, sum);
sum = sum * 0;
for (i = 1; i <= n; i += 2)
{
sum = sum + i;
}
printf("The sum of odd numbers between 1 to %d is %d\n\n", n, sum);
}

if (choice == 2)
{
float n, min = 0, max = 0, average = 0, sum = 0;
int count = 0;
printf("\n\nPlease enter a number [enter 0 to end]: ");
scanf("%f", &n);

min = n;
max = n;
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

while (n != 0)
{
sum += n;
count++;
printf("Please enter a number [enter 0 to end]: ");
scanf("%f", &n);
if (n > max)
max = n;
if (n < min && n != 0)
min = n;
}

printf("\nThe smallest number is %.2f\n", min);


printf("The largest number is %.2f\n", max);
printf("The average number is %.2f\n\n", sum / count);

}
printf("\a\a\n\n");
} while (choice != 3);
}

You might also like