Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

CO222 Lab 01 - Introduction to C Programming

Uploaded by

e21200
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

CO222 Lab 01 - Introduction to C Programming

Uploaded by

e21200
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Department of Computer Engineering

University of Peradeniya
CO222 Programming Methodology

Lab 01 - Introduction to C programming

December 9, 2024

1 Introduction
The objectives of Lab - 01 are to learn how to:

1. Write your first C program in a GNU/Linux environment and compile it using the
GNU C Compiler (GCC)
2. Perform basic input/output operations using C
3. Perform basic arithmetic operations using C

2 Exercises
1. Print each of the following patterns. Use one printf() statement for each line of
outputs. End each line by printing a new line.

(a) ************
**********
********
******
********
**********
************

(b) *
***
*****
*******
*********
***********

1
(c) *** ***
**** ****
** ** ** **
** **** **
** ** **
** **

(d) ************
************
************
************
************
************

2. Write a program to prompt the user for 2 integers and print their product. Use two
int variables int1 and int2 to store 2 integers and use * for multiplication.

3. Write a program to prompt the user for 2 float numbers and print their sum and
difference.

4. Write a program that calculates the total cost of purchasing a set of items from a
store. The program should prompt the user for the number of items they want to
buy, and ask the user to enter the price of one item(in float numbers with 2 decimal
points). The program should then calculate and print the total cost of all the items.

Sample Output -
Number of items: 5
Price of one item in Rs: 20.00
Total cost in Rs: 100.00

5. Write a program that calculates and prints the surface area and volume of a sphere.
Your program shall prompt the user for the radius of the sphere, in double.

6. Write a program to convert specified days into years, months and days.
1 Year = 365 Days, 1 Month = 30 Days (Note: Ignore leap year.)

Sample Input -
Number of days: 1329
Expected Output -
Years: 3, Months: 7, Days: 24

7. Write a program to convert a Fahrenheit value to Centigrade and print the result
with 4 decimal places. (Note: C = (5/9) * (F - 32))

Sample Output -
Input a temperature (in Fahrenheit): 113
Expected Output -
45.0000 degrees Centigrade.

2
8. Write a program to swap two numbers without using a third variable.

Sample Input - Enter two numbers: 6 8


Expected Output - Numbers after swapping: 8 6

3 Submission
Submit your work to the given submission link in FEeLS according to the following
instructions:

1. Create a folder containing your working codes (one file for each question with the
names Q1 to Q8) and a PDF with screenshots of the outputs

2. Compress your folder to a single ZIP file

3. Rename your folder according to the following pattern, where xxx is your registration
number and submit. Folder naming convention: e21xxxlab01.zip

4 Important
Copying someone else’s codes (including your group mate’s) or showing your source codes
to anyone else will earn you zero marks for the whole lab exercise.

5 Deadline
The deadline for the submission on feels is 15th Dec 2024 (Sunday) at 11:55 PM

6 References
https://www3.ntu.edu.sg/home/ehchua/programming/cpp/c0I ntroduction.html

You might also like