Starting from:

$34.99

COMP1011 Laboratory 2-Basic Elements of C Solution

Laboratory 2: Basic Elements of C
This lab is designed to get you familiar with some basic elements of C programming. More specifically, you will learn some data types, operators, and a simple branching statement. After this lab, you are expected to be able to solve simple calculation problems and print plain patterns.
Problem: Print “O” or “E”
• Problem description
Write a program to print different patterns according to parity (odd or even). Given two integer numbers a and b. If (a*b) - (a/b) is odd, then print “O”. Otherwise, print “E”.
• Input & output requirements
The two input numbers are separated by a space. Outputs of the program are expected to follow the format as shown in sample results.
• Sample results
Sample 1
Please input two integers: 5 3↲
********
*
*
********
*
*
********
Sample 2
Please input two integers: 5 4↲
******
* *
* *
* *
* *
* *
******
• Tips:
a) 1, 3, 5 … are odd numbers; and 2, 4, 6… are even numbers. If ( n%2 == 1 ), then n is an odd number.
b) Any special cases, e.g., what if b = 0?

More products