├── .github └── workflows │ └── main.yml ├── .gitignore ├── 2021 Feb Lab Sheets └── Lab Sheet 11 │ ├── Lab Sheet 11 - Léo │ ├── Exercise 1 - Léo.c │ ├── Exercise 2 - Léo.c │ ├── Exercise 3 - Léo.c │ ├── Exercise 4 - Léo.c │ └── Exercise 5 - Léo.c │ ├── Lab sheet 11 - Randula │ ├── Excercise 1 - Randula.c │ ├── Excercise 2 - Randula.c │ ├── Excercise 3 - Randula.c │ ├── Excercise 4 - Randula.c │ └── Excercise 5 - Randula.c │ └── Lab sheet 11.pdf ├── 2021 Feb Tutorials ├── TUTORIAL 03 │ ├── Exercise 1.c │ ├── Exercise 2.c │ └── Tutorial3.pdf ├── TUTORIAL 04 │ ├── Exercise 1.c │ ├── Exercise 2.c │ ├── Exercise 3.c │ ├── Exercise 4.c │ ├── Exercise 4.exe │ └── Tutorial4.pdf ├── TUTORIAL 05 │ ├── Exercise 1 A.c │ ├── Exercise 1 B.c │ ├── Exercise 1 C.c │ ├── Exercise 1 C.exe │ ├── Exercise 3 A.c │ ├── Exercise 3 B.c │ ├── Exercise 3 C.c │ ├── Exercise 4.c │ └── Tutorial5.pdf ├── TUTORIAL 06 │ ├── EX 1 │ │ ├── Exercise 1 Practice to use math library functions 1.c │ │ ├── Exercise 1 Practice to use math library functions 2.c │ │ ├── Exercise 1 Practice to use math library functions 3.c │ │ ├── Exercise 1 Practice to use math library functions 4.c │ │ └── Exercise 1 Practice to use math library functions 5.c │ ├── Exercise 1.c │ ├── Exercise 2.c │ ├── Exercise 3.c │ └── Tutorial6.pdf ├── TUTORIAL 07 │ ├── Exercise 1.c │ ├── Exercise 2.c │ ├── Exercise 3.c │ └── Tutorial7.pdf ├── TUTORIAL 08 │ ├── Exercise 1 A.c │ ├── Exercise 1 B.c │ ├── Exercise 1 C.c │ ├── Exercise 2.c │ ├── Exercise 3.c │ ├── Exercise 3.exe │ ├── Exercise 4.c │ └── Tutorial8.pdf ├── TUTORIAL 09 │ ├── Exercise 1.c │ ├── Exercise 2.c │ ├── Exercise 3.c │ └── Tutorial9.pdf └── TUTORIAL 10 │ ├── Q1 │ ├── number.txt │ └── tutorial 1.c │ └── Q2 │ └── wx2.c ├── LICENSE ├── Lab Sheets ├── Lab Sheet 3 │ ├── LabSheet3.pdf │ ├── Question1-Anjana.c │ ├── Question2-Anjana.c │ └── Question3-Anjana.c ├── Lab Sheet 4 │ ├── LabSheet4.pdf │ └── Question1-Anjana.c ├── Lab Sheet 5 │ ├── LabSheet5.pdf │ ├── Question1-Anjana.c │ ├── Question2-Anjana.c │ └── Question3-Anjana.c ├── Lab Sheet 6 │ ├── LabSheet6.pdf │ ├── Question 1-Anjana.c │ ├── Question 2-Anjana.c │ └── Question 3-Anjana.c └── Lab Sheet 7 │ ├── LabSheet7.pdf │ ├── Question 1-Anjana.c │ ├── Question 2-Anjana.c │ └── Student.dat ├── MID ├── Introduction to Programming_Model Paper.pdf ├── Questions │ ├── Answers.docx │ ├── IMG-20201221-WA0000.jpg │ ├── IMG-20201221-WA0001.jpg │ ├── IMG-20201221-WA0002.jpg │ ├── IMG-20201221-WA0003.jpg │ ├── IMG-20201221-WA0004.jpg │ ├── IMG-20201221-WA0005.jpg │ ├── IMG-20201221-WA0006.jpg │ ├── IMG-20201221-WA0007.jpg │ ├── IMG-20201221-WA0008.jpg │ ├── IMG-20201221-WA0009.jpg │ ├── IMG-20201221-WA0010.jpg │ ├── IMG-20201221-WA0011.jpg │ ├── IMG-20201221-WA0012.jpg │ ├── IMG-20201221-WA0013.jpg │ ├── IMG-20201221-WA0014.jpg │ ├── IMG-20201221-WA0015.jpg │ ├── IMG-20201221-WA0016.jpg │ ├── IMG-20201221-WA0017.jpg │ ├── IMG-20201221-WA0018.jpg │ ├── IMG-20201221-WA0019.jpg │ ├── IMG-20201221-WA0020.jpg │ ├── IMG-20201221-WA0021.jpg │ ├── IMG-20201221-WA0022.jpg │ ├── IMG-20201221-WA0023.jpg │ ├── IMG-20201221-WA0024.jpg │ ├── IMG-20201221-WA0025.jpg │ ├── IMG-20201221-WA0026.jpg │ ├── IMG-20201221-WA0027.jpg │ ├── IMG-20201221-WA0028.jpg │ ├── IMG-20201221-WA0029.jpg │ ├── IMG-20201221-WA0030.jpg │ ├── IMG-20201221-WA0031.jpg │ ├── IMG-20201221-WA0032.jpg │ ├── IMG-20201221-WA0033.jpg │ ├── IMG-20201221-WA0034.jpg │ ├── IMG-20201221-WA0035.jpg │ ├── IMG-20201221-WA0036.jpg │ ├── IMG-20201221-WA0037.jpg │ ├── IMG-20201221-WA0038.jpg │ ├── IMG-20201221-WA0039.jpg │ ├── IMG-20201221-WA0040.jpg │ ├── IMG-20201221-WA0041.jpg │ ├── IMG-20201221-WA0042.jpg │ ├── IMG-20201221-WA0043.jpg │ ├── IMG-20201221-WA0044.jpg │ ├── IMG-20201221-WA0045.jpg │ ├── IMG-20201221-WA0046.jpg │ ├── IMG-20201221-WA0047.jpg │ ├── IMG-20201221-WA0048.jpg │ ├── IMG-20201221-WA0049.jpg │ ├── IMG-20201221-WA0050.jpg │ ├── IMG-20201221-WA0051.jpg │ ├── IMG-20201221-WA0052.jpg │ ├── IMG-20201221-WA0053.jpg │ ├── IMG-20201221-WA0054.jpg │ ├── IMG-20201221-WA0055.jpg │ ├── IMG-20201221-WA0056.jpg │ ├── IMG-20201221-WA0057.jpg │ ├── IMG-20201221-WA0058.jpg │ ├── IMG-20201221-WA0059.jpg │ ├── IMG-20201221-WA0060.jpg │ ├── IMG-20201221-WA0061.jpg │ ├── IMG-20201221-WA0062.jpg │ ├── IMG-20201221-WA0063.jpg │ ├── IMG-20201221-WA0064.jpg │ ├── IMG-20201221-WA0065.jpg │ ├── IMG-20201221-WA0066.jpg │ ├── IMG-20201221-WA0067.jpg │ ├── IMG-20201221-WA0068.jpg │ ├── IMG-20201221-WA0069.jpg │ ├── IMG-20201221-WA0070.jpg │ ├── IMG-20201221-WA0071.jpg │ ├── IMG-20201221-WA0072.jpg │ ├── IMG-20201221-WA0073.jpg │ ├── IMG-20201221-WA0074.jpg │ ├── IMG-20201221-WA0075.jpg │ ├── IMG-20201221-WA0076.jpg │ ├── IMG-20201221-WA0077.jpg │ ├── IMG-20201221-WA0078.jpg │ ├── IMG-20201221-WA0079.jpg │ ├── IMG-20201221-WA0080.jpg │ ├── IMG-20201221-WA0081.jpg │ ├── IMG-20201221-WA0082.jpg │ ├── IMG-20201221-WA0083.jpg │ ├── IMG-20201221-WA0084.jpg │ ├── IMG-20201221-WA0085.jpg │ ├── IMG-20201221-WA0086.jpg │ ├── IMG-20201221-WA0087.jpg │ ├── IMG-20201221-WA0088.jpg │ └── june │ │ ├── WhatsApp Image 2020-12-14 at 12.57.54 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.30.29 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.30.59 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.31.21 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.31.55 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.31.56 AM (1).jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.31.56 AM (2).jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.31.56 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.32.23 AM (1).jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.32.23 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.32.37 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.34.23 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.39.38 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.41.31 AM.jpeg │ │ ├── WhatsApp Image 2020-12-22 at 12.57.11 AM.jpeg │ │ └── WhatsApp Image 2020-12-22 at 12.57.27 AM.jpeg └── Sample_MID_Exam_Questions.pdf ├── Other Questions ├── Question 1 │ ├── Answers - Randula │ │ ├── Q1 Answer - Randula.c │ │ └── Q2 Answer - Randula.c │ ├── Q1-Thushara.c │ ├── Q1.jpeg │ └── Q2 - sahan.c ├── Question 2 │ ├── O2-VB-Randula.c │ ├── O2-VB-Thushara.c │ └── Online2VersionB.jpeg ├── Question 3 │ ├── Answers - Randula │ │ ├── Q3 Part 1 - Randula.c │ │ └── Q3 Part 2 - Randula.c │ ├── Q3-Ex1-Thushara.c │ ├── Q3-Ex2-Thushara.c │ └── Q3.jpeg ├── Question 4 (ATM Question) │ ├── ATM Question - Answer - Randula.c │ └── ATM Question.pdf └── Question 5 │ ├── File Handling Assignment Sahan Punchihewa .c │ └── File Handling Assignment.jpeg ├── Past Papers ├── 2017 │ └── Final Exam │ │ ├── Answers - Sahan │ │ └── Q1 - Sahan.c │ │ ├── Answers-Léo │ │ └── Answer-Léo.c │ │ └── Introduction to Programming (N102).pdf ├── 2019 │ └── Final Exam │ │ └── Paper 1A │ │ ├── 1AQ3-Thushara.c │ │ ├── Answers - Randula │ │ ├── 1 - Randula.c │ │ ├── 2A - Randula.c │ │ ├── 2B - Randula.c │ │ ├── 3 - Randula.c │ │ ├── 4 - Randula.c │ │ └── loyalty.dat │ │ ├── Answers - Sahan │ │ ├── 1AQ1-sahan.c │ │ ├── 1AQ2a-sahan.c │ │ ├── 1AQ2b-sahan.c │ │ ├── 1AQ3-sahan.c │ │ ├── 1AQ4-sahan.c │ │ └── loyalty.dat │ │ ├── Answers-Léo │ │ ├── 1AQ1-Léo.c │ │ ├── 1AQ2a-Léo.c │ │ ├── 1AQ2b-Léo.c │ │ ├── 1AQ3-Leo.c │ │ ├── 1AQ4-Léo.c │ │ └── loyalty.dat │ │ └── IT1010_FInalPaper_2019.pdf ├── 2020 │ ├── June │ │ └── Online Exam 3 │ │ │ ├── VersionA │ │ │ ├── 2020 June Online 3 Version A - Randula.c │ │ │ ├── 2020juneO3VA-Thushara.c │ │ │ └── Version A.pdf │ │ │ ├── VersionB │ │ │ ├── 2020 June Online 3 Version B - Randula.c │ │ │ ├── 2020juneO3VB-Thushara.c │ │ │ └── Version B.pdf │ │ │ ├── VersionC │ │ │ ├── 2020 June Online 3 Version C - Randula.c │ │ │ ├── 2020juneO3VC-Thushara.c │ │ │ └── Version C.pdf │ │ │ ├── VersionD │ │ │ ├── 2020 June Online 3 Version D - Randula.c │ │ │ ├── 2020juneO3VD-Thushara.c │ │ │ └── Version D.pdf │ │ │ └── VersionE │ │ │ ├── 2020 June Online 3 Version E - Randula.c │ │ │ ├── 2020juneO3VE-Thushara.c │ │ │ └── Version E.pdf │ └── September │ │ ├── Online Exam 1 │ │ ├── VersionA │ │ │ ├── Version A - Randula.c │ │ │ ├── VersionA.pdf │ │ │ └── versionA-Ashen.c │ │ ├── VersionB │ │ │ ├── Version B - Randula.c │ │ │ ├── VersionB.pdf │ │ │ └── versionB-Hirusha.c │ │ ├── VersionC │ │ │ ├── Version C - Randula.c │ │ │ ├── VersionC.pdf │ │ │ ├── versionC-Ashen.c │ │ │ └── versionC-Thushara.c │ │ ├── VersionD │ │ │ ├── Version D - Randula.c │ │ │ ├── VersionD.pdf │ │ │ └── versionD-Hirusha.c │ │ └── VersionE │ │ │ ├── Version E - Randula.c │ │ │ ├── VersionE.pdf │ │ │ └── versionE-Hirusha.c │ │ ├── Online Exam 2 - resit │ │ ├── Online 2 - resit - Randula.c │ │ ├── Online2-resit-Thushara.c │ │ └── Online2-resit.pdf │ │ ├── Online Exam 2 │ │ ├── VersionA │ │ │ ├── Version A - Randula │ │ │ │ ├── Q1 - Randula.c │ │ │ │ └── Q2 - Randula.c │ │ │ ├── VersionA.pdf │ │ │ ├── versionA-a-Sasitha.c │ │ │ └── versionA-b-Sasitha.c │ │ ├── VersionB │ │ │ ├── Version B - Randula │ │ │ │ ├── Q1 - Randula.c │ │ │ │ └── Q2 - Randula.c │ │ │ ├── VersionB.pdf │ │ │ ├── versionB-a-Thushara.c │ │ │ └── versionB-b-Thushara.c │ │ ├── VersionC │ │ │ ├── Version C - Randula │ │ │ │ ├── Q1 - Randula.c │ │ │ │ └── Q2 - Randula.c │ │ │ ├── VersionC.pdf │ │ │ ├── versionC-a-Thushara.c │ │ │ └── versionC-b-Thushara.c │ │ ├── VersionD │ │ │ ├── Version D - Randula │ │ │ │ ├── Q1 - Randula.c │ │ │ │ └── Q2 - Randula.c │ │ │ └── VersionD.pdf │ │ └── VersionE │ │ │ ├── Version E - Randula │ │ │ ├── Q1 - Randula.c │ │ │ └── Q2 - Randula.c │ │ │ ├── VersionE.pdf │ │ │ ├── versionE-a-Lakshan.c │ │ │ └── versionE-b-Lakshan.c │ │ └── Online Exam 3 │ │ ├── VersionA │ │ ├── Version A - Online Test 03.pdf │ │ └── Version A - Randula.c │ │ ├── VersionB │ │ ├── Version B - Online Test 03.pdf │ │ └── Version B - Randula.c │ │ ├── VersionC │ │ ├── Version C - Online Test 03.pdf │ │ ├── Version C - Randula.c │ │ └── versionC-Thushara.c │ │ ├── VersionD │ │ ├── Version D - Online Test 03.pdf │ │ └── Version D - Randula.c │ │ └── VersionE │ │ ├── Due to an error of the question here gives the two possibilities.txt │ │ ├── Version E - Online Test 03.pdf │ │ ├── Version E - Randula (Ascending).c │ │ └── Version E - Randula (Deascending).c ├── 2017 Jan │ └── Final Exam │ │ ├── Answers - Léo │ │ └── Answer-Leo(1).c │ │ ├── Answers - Sahan │ │ └── Q1 - Sahan.c │ │ └── Introduction to Programming (CC++) (N102).pdf ├── 2018 Jan │ └── Final Exam │ │ ├── Answers - Sahan │ │ └── Q1 - Sahan.c │ │ ├── Answers- Léo │ │ └── Answer-Léo.c │ │ └── Introduction to Programming C (IT1103).pdf ├── 2018 June │ ├── Final Exam │ │ └── Paper 1A │ │ │ ├── 1AQ1-Thushara.c │ │ │ ├── 1AQ2a-Thushara.c │ │ │ ├── 1AQ2b-Thushara.c │ │ │ ├── 1AQ3-Thushara.c │ │ │ ├── 1AQ4a-Thushara.c │ │ │ ├── 1AQ4b-Thushara.c │ │ │ ├── 2018 - Randula │ │ │ ├── 1 - Randula.c │ │ │ ├── 2A - Randula.c │ │ │ ├── 2B - Randula.c │ │ │ ├── 3 - Randula.c │ │ │ ├── 4A - Randula.c │ │ │ ├── 4B - Randula.c │ │ │ └── attendance.dat │ │ │ ├── Answers - Sahan │ │ │ ├── 1AJune1 - Sahan.c │ │ │ ├── 1AJune2a - Sahan.c │ │ │ ├── 1AJune2b - Sahan.c │ │ │ ├── 1AJune3 - Sahan.c │ │ │ ├── 1AJune4a - Sahan.c │ │ │ └── 1AJune4b - Sahan.c │ │ │ ├── Answers- Léo │ │ │ ├── 1AJune1.c │ │ │ ├── 1AJune2a.c │ │ │ ├── 1AJune2b.c │ │ │ ├── 1AJune3.c │ │ │ ├── 1AJune4a.c │ │ │ └── 1AJune4b.c │ │ │ ├── Final Examination Past Paper_2018.pdf │ │ │ └── attendance.dat │ └── Online Exam 1 │ │ └── VersionB │ │ ├── 2018juneO1VB-Thushara.c │ │ └── 2018juneO1VB.jpeg ├── 2021 Feb │ ├── Online Exam 2 │ │ ├── Version 1 - (pizzaOutlet) │ │ │ ├── V 1 - (pizzaOutlet) - Randula.c │ │ │ ├── V1-(pizzaOutlet) - Thushara.c │ │ │ └── Version 1 - (pizzaOutlet).png │ │ ├── Version 2 - (purchasedItem) │ │ │ ├── V 2 - (purchasedItem) - Randula.c │ │ │ └── Version 2 - (purchasedItem).jpeg │ │ ├── Version 3 - (bowlingGame) │ │ │ ├── V 3 - (bowlingGame) - Randula.c │ │ │ └── Version 3 - (bowlingGame).jpeg │ │ ├── Version 4 - (burgerOutlet) │ │ │ ├── V 4 - (burgerOutlet) - Randula.c │ │ │ └── Version 4 - (burgerOutlet).jpeg │ │ └── Version 5 - (stationaryShop) │ │ │ ├── V 5 - (stationaryShop) - Randula.c │ │ │ └── Version 5 - (stationaryShop).jpeg │ ├── Online Exam 5 │ │ ├── Version 1 - (chocolate) │ │ │ ├── V1-(chocolate) - Randula.c │ │ │ ├── V1-(chocolate) - Thushara.c │ │ │ └── Version 1 - (chocolate).jpg │ │ ├── Version 2 - (Student's Final Mark) │ │ │ ├── Version 2(Student's Final Mark) - Randula.c │ │ │ └── Version 2(Student's Final Mark).png │ │ ├── Version 3 - (Boxes) │ │ │ ├── Version3 (Boxes) - JananiM.c │ │ │ ├── Version3 (Boxes) - Randula.c │ │ │ ├── Version3 (Boxes)- Leo.c │ │ │ └── Version3 (Boxes).jpg │ │ ├── Version 4 - (Rainfall) │ │ │ ├── Version4 (Rainfall) - Randula.c │ │ │ ├── Version4(Rainfall) - Sahan.c │ │ │ └── Version4(Rainfall) - Sahan.png │ │ ├── Version 5 - (temperature) │ │ │ ├── V5-(temperature) - Randula.c │ │ │ ├── V5-(temperature) - Thushara.c │ │ │ └── Version 5 - (temperature).jpeg │ │ └── Version 6 - (Rainfall in colombo and kandy) │ │ │ ├── V 6 - (Rainfall in colombo and kandy) - Randula.c │ │ │ └── V 6 - (Rainfall in colombo and kandy).jpeg │ └── Online Exam 6 │ │ ├── Version 1 - Product │ │ ├── Version 1 - Product (Randula).c │ │ └── Version 1 - Product.jpeg │ │ ├── Version 2 - Employee │ │ ├── Version 2 - Employee - Randula.c │ │ └── Version 2 - Employee.jpeg │ │ └── Version 3 - Book │ │ ├── Version 3 - Book - Randula.c │ │ └── Version 3 - Book.jpeg └── 2021 May │ └── Online Test 1 │ ├── Version 1 (advertisement) │ ├── Version 1 - Randula.c │ ├── Version 1 - radser2001.c │ ├── Version 1_(advertisement).jpeg │ └── Version1 - radser2001.c │ ├── Version 2 (restaurant) │ ├── Version 2 - Randula.c │ ├── Version 2 - radser2001.c │ ├── Version 2_ (restaurant).jpeg │ └── Version2-radser2001.c │ ├── Version 3 (bank) │ ├── Version 3 (Bank).jpeg │ ├── Version 3 - Randula.c │ ├── Version 3 - radser2001.c │ └── Version3 - radser2001.c │ ├── Version 4 (partyPackage) │ ├── Version 4 (partyPackage).jpeg │ ├── Version 4 - Randula.c │ └── Version 4 - radser2001.c │ └── Version 5 (salary) │ ├── Version 5 - Randula.c │ ├── Version 5 - radser2001.c │ ├── Version 5_salary.jpeg │ └── Version5 - radser2001.c ├── README.md ├── Small C Excersices ├── Answers - Randula │ ├── Excercise 1.c │ ├── Excercise 2.c │ ├── Excercise 3.c │ └── Excercise 4.c └── Pactice C Language.pdf └── Tutorials ├── Tutorial 10 ├── Additional Exercises │ ├── Question1-Anjana.c │ ├── Question1-Thushara.c │ ├── Question2-Anjana.c │ └── Question2-Thushara.c ├── Question1-Anjana.c ├── Question1-full-Thushara.c ├── Question2-Thushara.c ├── Question3-Anjana.c ├── Question3-Thushara.c └── Tutorial 10.pdf ├── Tutorial 11 ├── Additional Exercises │ ├── Question1(a,b)-Anjana.c │ ├── Question1(c)-Anjana.c │ └── Question1-full-Thushara.c ├── Question1-Anjana.c ├── Question1-Thushara.c ├── Question2-Anjana.c ├── Question2-Thushara.c ├── Question3-Anjana.c └── Question3-Thushara.c ├── Tutorial 12 ├── Question1.(c)-Anjana.c ├── Question1.(d)-Anjana.c ├── Question2(a,b)-Anjana.c ├── Question2.(c)-Anjana.c ├── Tutorial 12.pdf ├── appointment.dat └── number.dat ├── Tutorial 4 ├── Question1-i-Thushara.c ├── Question1-ii-Thushara.c ├── Question2-Anjana.c ├── Question3-Thushara.c ├── Question4-Thushara.c └── Tutorial 4.pdf ├── Tutorial 5 ├── Additional Exercises │ ├── Question2-Anjana.c │ ├── Question3-Anjana.c │ ├── Question4-Anjana.c │ ├── Question5-Anjana.c │ └── Question6-Anjana.c ├── Question3-Anjana.c ├── Question4-Anjana.c └── Tutorial 5.pdf ├── Tutorial 6 ├── Question1-Anjana.c ├── Question2-Anjana.c ├── Question3-Anjana.c ├── Question4-Anjana.c ├── Question5-Anjana.c ├── Question6-Anjana.c ├── Question7-Anjana.c └── Tutorial 6.pdf ├── Tutorial 7 ├── Additional Exercises │ ├── Question1-Anjana.c │ └── Question2-Anjana.c ├── Question2-Anjana.c ├── Question3-Anjana.c └── Tutorial 7.pdf ├── Tutorial 8 ├── Additional Exercises │ ├── Question1-Anjana.c │ ├── Question1-i-Thushara.c │ ├── Question1-ii-Thushara.c │ ├── Question2-Anjana.c │ ├── Question3-Anjana.c │ └── Question3-full-Thushara.c ├── Question2-Anjana.c ├── Question3-Anjana.c └── Tutorial 8.pdf └── Tutorial 9 ├── Additional Exercises └── Question3-Thushara.c ├── Question1-Thushara.c ├── Question2-Thushara.c └── Tutorial 9.pdf /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | jobs: 4 | contrib-readme-job: 5 | runs-on: ubuntu-latest 6 | name: A job to automate contrib in readme 7 | steps: 8 | - name: Contribute List 9 | uses: akhilmhdh/contributors-readme-action@v2.2.1 10 | with: 11 | image_size: 100(px) 12 | columns_per_row: 3 13 | committer_username: ThusharaX 14 | commit_message: Contributors list updated 15 | env: 16 | GITHUB_TOKEN: ${{ secrets.CON_TOKEN }} 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py 2 | 3 | # Prerequisites 4 | *.d 5 | 6 | # Object files 7 | *.o 8 | *.ko 9 | *.obj 10 | *.elf 11 | 12 | # Linker output 13 | *.ilk 14 | *.map 15 | *.exp 16 | 17 | # Precompiled Headers 18 | *.gch 19 | *.pch 20 | 21 | # Libraries 22 | *.lib 23 | *.a 24 | *.la 25 | *.lo 26 | 27 | # Shared objects (inc. Windows DLLs) 28 | *.dll 29 | *.so 30 | *.so.* 31 | *.dylib 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app 37 | *.i*86 38 | *.x86_64 39 | *.hex 40 | 41 | # Debug files 42 | *.dSYM/ 43 | *.su 44 | *.idb 45 | *.pdb 46 | 47 | # Kernel Module Compile Results 48 | *.mod* 49 | *.cmd 50 | .tmp_versions/ 51 | modules.order 52 | Module.symvers 53 | Mkfile.old 54 | dkms.conf -------------------------------------------------------------------------------- /2021 Feb Lab Sheets/Lab Sheet 11/Lab Sheet 11 - Léo/Exercise 1 - Léo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x,facto=1; 6 | 7 | printf("Enter Number: "); 8 | scanf("%d",&x); 9 | 10 | printf("Factorial of %d is: ",x); 11 | 12 | while(x!=0) 13 | { 14 | facto *= x; 15 | x--; 16 | } 17 | 18 | printf("%d",facto); 19 | } 20 | -------------------------------------------------------------------------------- /2021 Feb Lab Sheets/Lab Sheet 11/Lab Sheet 11 - Léo/Exercise 2 - Léo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int sal[9]={0},i,salary; 6 | 7 | printf("Enter Salary: "); 8 | scanf("%d",&salary); 9 | 10 | while(salary !=-1) 11 | { 12 | if(salary>=200 && salary<=299) 13 | { 14 | sal[0]+=1; 15 | } 16 | else if (salary<=399) 17 | { 18 | sal[1]+=1; 19 | } 20 | else if (salary<=499) 21 | { 22 | sal[2]+=1; 23 | } 24 | else if (salary<=599) 25 | { 26 | sal[3]+=1; 27 | } 28 | else if (salary<=699) 29 | { 30 | sal[4]+=1; 31 | } 32 | else if (salary<=799) 33 | { 34 | sal[5]+=1; 35 | } 36 | else if (salary<=899) 37 | { 38 | sal[6]+=1; 39 | } 40 | else if (salary<=999) 41 | { 42 | sal[7]+=1; 43 | } 44 | else if(salary>1000 &&salary<=1500) 45 | { 46 | sal[8]+=1; 47 | } 48 | 49 | printf("Enter Salary: "); 50 | scanf("%d",&salary); 51 | 52 | } 53 | int bam = 200,boozle=299; 54 | for(i=0;i<=7;i++) 55 | { 56 | printf("Employees who gets a salary between %d - %d are :%d\n",bam,boozle,sal[i]); 57 | bam+=100; 58 | boozle+=100; 59 | } 60 | printf("Employees who gets a salary between %d and above are : %d\n",1000,sal[8]); 61 | } 62 | -------------------------------------------------------------------------------- /2021 Feb Lab Sheets/Lab Sheet 11/Lab Sheet 11 - Léo/Exercise 3 - Léo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int A[5]={10,20,30,40,50}; 6 | int B[5]={34,67,12,89,12}; 7 | int C[5],i; 8 | 9 | for(i=0;i<=4;i++) 10 | { 11 | C[i]=((A[i])*(B[i])); 12 | } 13 | 14 | printf("\nArray C= "); 15 | printf("{"); 16 | for(i=0;i<=4;i++) 17 | { 18 | printf("%d",C[i]); 19 | if(i==4) 20 | { 21 | break; 22 | } 23 | printf(","); 24 | } 25 | printf("}\n"); 26 | } 27 | -------------------------------------------------------------------------------- /2021 Feb Lab Sheets/Lab Sheet 11/Lab Sheet 11 - Léo/Exercise 4 - Léo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | char name[20]; 6 | int len,i; 7 | 8 | printf("Enter the name: "); 9 | scanf("%s",name); 10 | len = strlen(name); 11 | 12 | printf("\nName in backwards: "); 13 | for(i=0;i<=len-1;i++) 14 | { 15 | printf("%c",name[(len-1)-i]); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /2021 Feb Lab Sheets/Lab Sheet 11/Lab Sheet 11 - Léo/Exercise 5 - Léo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void convertToUpperCase( char a[], int size); 5 | 6 | int main() 7 | { 8 | char address[150]; 9 | char string[] = "SLIIT,New Kandy Road, Malabe"; 10 | int len; 11 | 12 | 13 | 14 | strcpy( address, string); 15 | len = strlen(address); 16 | 17 | convertToUpperCase( address, len); 18 | 19 | return 0; 20 | } 21 | 22 | void convertToUpperCase( char a[], int size) 23 | { 24 | int i; 25 | 26 | for( i = 0 ; i < size ; i++){ 27 | 28 | if( a[i] >= 97 && a[i] <= 122){ 29 | a[i] -=32; 30 | printf( "%c", a[i] ); 31 | } 32 | else if( a[i] >= 65 && a[i] <= 122 ){ 33 | printf( "%c", a[i]); 34 | } 35 | else{ 36 | printf("%c",a[i]); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /2021 Feb Lab Sheets/Lab Sheet 11/Lab sheet 11 - Randula/Excercise 1 - Randula.c: -------------------------------------------------------------------------------- 1 | //importing libraries 2 | #include 3 | 4 | int main(void) 5 | { 6 | //declare variables 7 | int input = -1 , answer = 1; 8 | int reduce = 0 , count; 9 | 10 | //entering the loop 11 | while(1) 12 | { 13 | //taking user inputs 14 | printf("Enter a Positive Number : "); 15 | scanf("%d" , &input); 16 | 17 | if (input >= 0) 18 | { 19 | while (reduce < input) 20 | { 21 | answer *= (input - reduce); //do the calculation 22 | reduce++; 23 | } 24 | printf("The Factorial of %d is : %d\n" , input , answer); 25 | break; 26 | } 27 | else 28 | { 29 | printf("You have entered a Negative Number!!\n"); //get another chance if user enters a negative number 30 | } 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /2021 Feb Lab Sheets/Lab Sheet 11/Lab sheet 11 - Randula/Excercise 3 - Randula.c: -------------------------------------------------------------------------------- 1 | //importing libraries 2 | #include 3 | 4 | int main(void) 5 | { 6 | //define array 7 | int A[5] = {10 , 20 , 30 , 40 , 50}; 8 | int B[5] = {34 , 67 , 12 , 89 , 12}; 9 | int C[5] = {0}; 10 | //define variable 11 | int i; 12 | 13 | //calculate the multiplication of the array A and B and assign the answers to array C 14 | for (i = 0 ; i < 5 ; i++) 15 | { 16 | C[i] = A[i] * B[i]; 17 | } 18 | 19 | //printf the array A 20 | printf("A = { "); 21 | for (i = 0 ; i < 5 ; i++) 22 | { 23 | printf("%d " , A[i]); 24 | } 25 | printf("}\n"); 26 | 27 | //print the array B 28 | printf("B = { "); 29 | for (i = 0 ; i < 5 ; i++) 30 | { 31 | printf("%d " , B[i]); 32 | } 33 | printf("}\n"); 34 | 35 | //print the array C 36 | printf("C = { "); 37 | for (i = 0 ; i < 5 ; i++) 38 | { 39 | printf("%d " , C[i]); 40 | } 41 | printf("}\n"); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /2021 Feb Lab Sheets/Lab Sheet 11/Lab sheet 11 - Randula/Excercise 4 - Randula.c: -------------------------------------------------------------------------------- 1 | //importing libraries 2 | #include 3 | #include 4 | 5 | int main (void) 6 | { 7 | char input[20]; 8 | int i , length; 9 | 10 | printf("Enter a Name : "); //prompt 11 | scanf("%s" , input); //assign the type string to the variable 12 | 13 | 14 | length = strlen(input); //get the charator amount of the user entered string 15 | 16 | //check whether the length in less than 20 or not 17 | if (length > 20) 18 | { 19 | printf("Error!!\n"); 20 | } 21 | else 22 | { 23 | //printng the string backwords 24 | for (i = 0 ; i <= length ; i++) 25 | { 26 | printf("%c" , input[length - i]); 27 | } 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /2021 Feb Lab Sheets/Lab Sheet 11/Lab sheet 11 - Randula/Excercise 5 - Randula.c: -------------------------------------------------------------------------------- 1 | //importing libraries 2 | #include 3 | #include 4 | 5 | //define calling function 6 | void convertToUpperCase (char a[ ], int size ); 7 | 8 | int main (void) 9 | { 10 | //define variables 11 | char address[100]; 12 | int length; 13 | 14 | strcpy(address , "SLIIT, New Kandy Road, Malabe"); //assigning the string by strcpy 15 | 16 | printf("Initiate - %s\n" , address); 17 | 18 | length = strlen(address); //getting the charactor amount by using strlen 19 | 20 | convertToUpperCase (address, length ); //call the function 21 | 22 | 23 | return 0; 24 | } 25 | 26 | //define called function 27 | void convertToUpperCase (char a[ ], int size ) 28 | { 29 | int i; 30 | //modify the string the to convert lower case letters to upper case letters 31 | printf("After Modifing - " ); 32 | for (i = 0 ; i < size ; i++) 33 | { 34 | if (a[i] >= 97) 35 | { 36 | printf("%c" , a[i] - 32); 37 | } 38 | else 39 | { 40 | printf("%c" , a[i]); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /2021 Feb Lab Sheets/Lab Sheet 11/Lab sheet 11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Lab Sheets/Lab Sheet 11/Lab sheet 11.pdf -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 03/Exercise 2.c: -------------------------------------------------------------------------------- 1 | /*Exercise 2: Practice arithmetic operators in C 2 | Write a program that inputs one five-digit number, separates the number into its individual 3 | digits and prints the digits separated from one another. 4 | Ex: if user types, 42139, the program should print 4 2 1 3 9 */ 5 | 6 | #include 7 | int main (void) 8 | { 9 | int number, number2, number3, number4, digit1, digit2, digit3, digit4, digit5; 10 | 11 | 12 | printf("Enter five digit Number and this programe separate the Number into individual digits\n"); //title 13 | printf("....................................................................................\n"); 14 | printf("Enter Five-digit Number : "); 15 | scanf("%d",&number); //get input number 16 | 17 | digit1= number/10000; //identifying digit1 18 | number2= number%10000; 19 | 20 | digit2=number2/1000; //identifying digit2 21 | number3=number2%1000; 22 | 23 | digit3=number3/100; //identifying digit3 24 | number4=number3%100; 25 | 26 | digit4=number4/10; //identifying digit4 27 | 28 | digit5=number4%10; //identifying digit5 29 | 30 | printf("%d\t%d\t%d\t%d\t%d",digit1,digit2,digit3,digit4,digit5); 31 | 32 | return 0; 33 | } // end of the main function 34 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 03/Tutorial3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 03/Tutorial3.pdf -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 04/Exercise 1.c: -------------------------------------------------------------------------------- 1 | /*Write a C program to input an integer from the keyboard and convert the number into a positive 2 | number, if the user input is a negative value*/ 3 | 4 | #include 5 | int main(void) 6 | { 7 | int n; 8 | 9 | printf("Enter an integer : "); 10 | scanf("%d",&n);//get input for n 11 | 12 | if (n<0) 13 | 14 | { 15 | n=-n;//calculation 16 | } 17 | 18 | printf("%d",n);//show answer 19 | 20 | return 0; 21 | }// end of main function 22 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 04/Exercise 3.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 04/Exercise 3.c -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 04/Exercise 4.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 04/Exercise 4.exe -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 04/Tutorial4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 04/Tutorial4.pdf -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 05/Exercise 1 A.c: -------------------------------------------------------------------------------- 1 | //Exercise 1: Practice to write while loops 2 | 3 | #include 4 | int main(void) 5 | {//function main begins 6 | int counter=10;// initialization 7 | while (counter<=20){//repetition condition 8 | 9 | printf("%d\n",counter);// display counter 10 | ++counter;// increment 11 | 12 | }//end while 13 | 14 | 15 | return 0; 16 | 17 | }//end main of the function 18 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 05/Exercise 1 B.c: -------------------------------------------------------------------------------- 1 | //Prompt the user to enter series of numbers from the keyboard and display the numbers. If user enters a negative number stop reading the numbers. 2 | 3 | #include 4 | int main(void) 5 | { 6 | int no; 7 | 8 | printf("Input Numbers\n\n"); 9 | 10 | printf("Input Number : "); 11 | scanf("%d",&no);//get no 12 | 13 | while (no>=0){//repetition condition 14 | printf("Output %d\n\n",no);//show no 15 | 16 | printf("Input Number : "); 17 | scanf("%d",&no);//get no 18 | 19 | }//end of the while function 20 | 21 | printf("\n"); 22 | printf("End Of Reading...."); 23 | 24 | return 0; 25 | 26 | }//end of main function 27 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 05/Exercise 1 C.c: -------------------------------------------------------------------------------- 1 | /*iii) Modify the program written in ii) above display the sum and average of the 2 | positive numbers entered.*/ 3 | 4 | #include 5 | int main(void) 6 | {//function main begins 7 | int count=0; 8 | float no,avg=0,sum=0; 9 | 10 | printf("Input Positive Numbers and This will show Sum and Average of It\n"); 11 | 12 | printf("Input Number : "); 13 | scanf("%f",&no);//get no 14 | 15 | 16 | while (no>=0){//repetition condition 17 | 18 | ++count; 19 | 20 | sum=sum+no;//sum calculation 21 | 22 | avg=sum/count;//avgcalculation 23 | 24 | printf("Sum = %.2f\n",sum); 25 | printf("Count = %d\n",count); 26 | 27 | //show sum,count 28 | 29 | printf("\nInput Number : "); 30 | scanf("%f",&no);//get no 31 | 32 | 33 | 34 | }//end of the while function 35 | 36 | printf("\n\nAverage = %.2f\n",avg);//print average 37 | 38 | printf("\n"); 39 | printf("End Of Reading...."); 40 | 41 | return 0; 42 | 43 | }//end of main function 44 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 05/Exercise 1 C.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 05/Exercise 1 C.exe -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 05/Exercise 3 A.c: -------------------------------------------------------------------------------- 1 | /* Exercise 3: Practice to use loops (Use while loop) 2 | i) Write a C program to enter 4 module marks of a student from the keyboard and 3 | display the total of all four module marks. */ 4 | 5 | #include 6 | int main( void ) 7 | {// function main begins program execution 8 | int marks,total=0,counter = 1; 9 | 10 | printf( "INPUT YOUR 4 MODULE MARKS AND THIS WILL GIVE YOU TOTAL OF ALL MODULE MARK\n" ); 11 | printf( "\n" ); // prompt 12 | 13 | while( counter <= 4 ){ // loop 4 times 14 | printf( "Input Module %d Marks : ",counter ); 15 | scanf( "%d",&marks ); // read marks from user 16 | 17 | total = total + marks; // calculate total 18 | counter++; // increment counter 19 | } // end of while 20 | 21 | printf( "\nTOTAL OF 4 MODULE MARKS : %d \n",total ); // show total 22 | 23 | return 0; 24 | } // end of the mein function 25 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 05/Exercise 3 B.c: -------------------------------------------------------------------------------- 1 | /* Exercise 3: Practice to use loops (Use while loop) 2 | ii) Modify the program written in i) above to enter 4 module marks of 3 students and 3 | display their total marks. */ 4 | 5 | #include 6 | int main( void ) 7 | {// function main begins program execution 8 | int marks, total, student = 1, counter = 1; 9 | 10 | printf( "INPUT 3 STUDENTS 4 MODULE MARKS \n AND THIS WILL GIVE YOU TOTAL OF ALL MODULE MARK\n" ); 11 | printf( "\n" ); // prompt 12 | 13 | while( student <= 3 ){ // loop 3 times 14 | 15 | printf( "\n" ); 16 | printf( "Input Student %d Marks \n",student ); 17 | printf( "\n" ); 18 | 19 | while( counter <= 4 ){ // loop 4 times 20 | printf( "Input Module %d Marks : ",counter ); 21 | scanf( "%d",&marks ); // read marks from user 22 | 23 | total = total + marks; // calculate total 24 | counter++; // increment counter 25 | } // end of while 26 | 27 | printf( "TOTAL OF 4 MODULE MARKS(STUDENT %d ): %d \n",student,total ); // show total 28 | 29 | total = 0; // get total to 0 30 | counter = 1; // get counter to 0 31 | 32 | student++; // increment student 33 | 34 | } // end of while 35 | 36 | return 0; 37 | } // end of the mein function 38 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 05/Exercise 4.c: -------------------------------------------------------------------------------- 1 | //Exercise 4: Practice to write nested loops 2 | 3 | #include 4 | int main( void ) 5 | {// function main begins 6 | int i,counter; 7 | 8 | for( i = 1; i <= 7 ; i++){ //1st for loop begins 9 | 10 | for( counter = 1; counter <= i ; counter++){ //2nd for loop begins 11 | printf( "*"); 12 | } //2nd for loop end 13 | printf( "\n"); 14 | 15 | } //1st for loop ends 16 | 17 | for( i = 7; i >=1 ; i-=2){ //3rd for loop begins 18 | 19 | for( counter = 1; counter <= i ; counter++ ){ //4th for loop begins 20 | printf( "*"); 21 | } //4th for loop ends 22 | printf("\n"); 23 | } //3rd for loop ends 24 | 25 | return 0; 26 | } //end of the main function 27 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 05/Tutorial5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 05/Tutorial5.pdf -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 06/EX 1/Exercise 1 Practice to use math library functions 1.c: -------------------------------------------------------------------------------- 1 | /*Exercise 1 Practice to use math library functions 2 | Show the value of x after each of the following statements is performed: 3 | i. x = floor(7.5) 4 | ii. x = ceil (0.0) 5 | iii. x = ceil (-6.4) 6 | iv. x = log10(100.0) 7 | v. x = ceil (floor (-5.5)) */ 8 | 9 | #include 10 | #include 11 | int main(void) 12 | { 13 | printf("%.2f",floor(7.5)); 14 | 15 | return 0; 16 | }//end of the main function 17 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 06/EX 1/Exercise 1 Practice to use math library functions 2.c: -------------------------------------------------------------------------------- 1 | /*Exercise 1 Practice to use math library functions 2 | Show the value of x after each of the following statements is performed: 3 | i. x = floor(7.5) 4 | ii. x = ceil (0.0) 5 | iii. x = ceil (-6.4) 6 | iv. x = log10(100.0) 7 | v. x = ceil (floor (-5.5)) */ 8 | 9 | #include 10 | #include 11 | int main(void) 12 | { 13 | printf("%.2f",ceil (0.0)); 14 | 15 | return 0; 16 | }//end of the main function 17 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 06/EX 1/Exercise 1 Practice to use math library functions 3.c: -------------------------------------------------------------------------------- 1 | /*Exercise 1 Practice to use math library functions 2 | Show the value of x after each of the following statements is performed: 3 | i. x = floor(7.5) 4 | ii. x = ceil (0.0) 5 | iii. x = ceil (-6.4) 6 | iv. x = log10(100.0) 7 | v. x = ceil (floor (-5.5)) */ 8 | 9 | #include 10 | #include 11 | int main(void) 12 | { 13 | printf("%.2f",ceil (-6.4)); 14 | 15 | return 0; 16 | }//end of the main function 17 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 06/EX 1/Exercise 1 Practice to use math library functions 4.c: -------------------------------------------------------------------------------- 1 | /*Exercise 1 Practice to use math library functions 2 | Show the value of x after each of the following statements is performed: 3 | i. x = floor(7.5) 4 | ii. x = ceil (0.0) 5 | iii. x = ceil (-6.4) 6 | iv. x = log10(100.0) 7 | v. x = ceil (floor (-5.5)) */ 8 | 9 | #include 10 | #include 11 | int main(void) 12 | { 13 | printf("%.2f",log10(100.0)); 14 | 15 | return 0; 16 | }//end of the main function 17 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 06/EX 1/Exercise 1 Practice to use math library functions 5.c: -------------------------------------------------------------------------------- 1 | /*Exercise 1 Practice to use math library functions 2 | Show the value of x after each of the following statements is performed: 3 | i. x = floor(7.5) 4 | ii. x = ceil (0.0) 5 | iii. x = ceil (-6.4) 6 | iv. x = log10(100.0) 7 | v. x = ceil (floor (-5.5)) */ 8 | 9 | #include 10 | #include 11 | int main(void) 12 | { 13 | printf("%.2f",ceil (floor (-5.5))); 14 | 15 | return 0; 16 | }//end of the main function 17 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 06/Exercise 1.c: -------------------------------------------------------------------------------- 1 | /*Exercise 1 Practice to use math library functions 2 | Show the value of x after each of the following statements is performed: 3 | i. x = floor(7.5) 4 | ii. x = ceil (0.0) 5 | iii. x = ceil (-6.4) 6 | iv. x = log10(100.0) 7 | v. x = ceil (floor (-5.5)) */ 8 | 9 | #include 10 | #include 11 | int main(void) 12 | { 13 | printf("%.2f\n",floor(7.5)); //i 14 | printf("%.2f\n",ceil (0.0)); //ii 15 | printf("%.2f\n",ceil (-6.4)); //iii 16 | printf("%.2f\n",log10(100.0)); //iv 17 | printf("%.2f\n",ceil (floor (-5.5))); //v 18 | 19 | return 0; 20 | }//end of the main function 21 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 06/Exercise 2.c: -------------------------------------------------------------------------------- 1 | /*Exercise 2 : Practice to write a simple function 2 | Write a function called circleArea() that take the radius of a circle as an argument and 3 | calculate and return the area. In the main program read the radius value from the user, call 4 | circleArea() and display the result. */ 5 | 6 | #include 7 | float circleArea(float radius); 8 | int main(void) 9 | { 10 | float r; 11 | printf("Enter Radius : "); 12 | scanf("%f",&r);//input radius 13 | printf("Area = %.2f",circleArea(r));//print aria 14 | } 15 | float circleArea(float radius) 16 | { 17 | return (22/7.0)*radius*radius; 18 | }//end of main function 19 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 06/Exercise 3.c: -------------------------------------------------------------------------------- 1 | /*Exercise 3: Practice to write functions and use those functions to solve a problem 2 | 3 | Write three functions do the following 4 | add - add two integers pass as parameters and return the result 5 | multiply - multiply two integers pass as parameters and return the result 6 | square - receive an integer as a parameter and return the result after multiplying the number by itself. 7 | Use these functions in the main program to calculate the result of the following mathematical expression. 8 | (3*4 + 5*7) 2 */ 9 | 10 | #include 11 | int add(int a,int b); 12 | int multiply(int a, int b); 13 | int square(int x);//declaring function 14 | int main()//function main begins 15 | { 16 | int ans; 17 | ans=square(add(multiply(3,4),multiply(5,7)));//calculation 18 | printf("Answer : %d", ans);//display answer 19 | 20 | return 0; 21 | 22 | } 23 | int add(int a, int b) 24 | { 25 | return a+b; 26 | } 27 | int multiply(int a,int b) 28 | { 29 | return a*b; 30 | } 31 | int square(int a) 32 | { 33 | return a*a; 34 | }//end of main function 35 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 06/Tutorial6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 06/Tutorial6.pdf -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 07/Exercise 1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 07/Exercise 1.c -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 07/Tutorial7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 07/Tutorial7.pdf -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 08/Exercise 1 A.c: -------------------------------------------------------------------------------- 1 | /*Exercise 1: Practice to store and print data in an array 2 | ex a */ 3 | 4 | #include 5 | int main( void ) 6 | {//function main begins 7 | int counter; 8 | float marks[10]; 9 | 10 | 11 | for( counter = 0 ; counter < 10 ; ++counter ){ 12 | 13 | printf( "Input Mark %d : ", counter );//prompt 14 | scanf("%f", &marks[counter]);//read marks from user 15 | 16 | } 17 | 18 | return 0; 19 | }// end of the main function 20 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 08/Exercise 1 B.c: -------------------------------------------------------------------------------- 1 | /*Exercise 1: Practice to store and print data in an array 2 | ex b */ 3 | 4 | #include 5 | int main( void ) 6 | {//function main begins 7 | int counter; 8 | float marks[10], check_marks; 9 | 10 | 11 | for( counter = 0 ; counter < 10 ; ++counter ){ 12 | 13 | printf( "Input Mark %d : ", counter );//prompt 14 | scanf("%f", &check_marks);//read marks from user 15 | 16 | if( check_marks >= 0 && check_marks <=20 ){// checking condition 17 | 18 | marks[counter] = check_marks; 19 | 20 | } 21 | 22 | else { 23 | 24 | printf( "\n:: Invalid marks :: \n");//prompt 25 | counter = counter - 1 ; // get counter to back 26 | 27 | } 28 | 29 | } 30 | 31 | return 0; 32 | }// end of the main function 33 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 08/Exercise 1 C.c: -------------------------------------------------------------------------------- 1 | /*Exercise 1: Practice to store and print data in an array 2 | ex b C */ 3 | #include 4 | int main( void ) 5 | {//function main begins 6 | int counter; 7 | float marks[10], check_marks; 8 | 9 | for( counter = 1 ; counter <= 10 ; ++counter ){ 10 | 11 | printf( "Input Mark %d : ", counter );//prompt 12 | scanf("%f", &check_marks);//read marks from user 13 | 14 | if( check_marks >= 0 && check_marks <=20 ){// checking condition 15 | 16 | marks[counter] = check_marks; 17 | 18 | } 19 | 20 | else { 21 | 22 | printf( "\n:: Invalid marks :: \n");//prompt 23 | counter = counter - 1 ; // get counter to back 24 | 25 | } 26 | 27 | } 28 | 29 | printf( "\n__________________________________\n" ); 30 | printf( "%s%10s\n","Student","Marks");// make a table 31 | 32 | for ( counter =0; counter < 10; ++counter){//printing for loop begins 33 | 34 | printf( "Student %d%8.2f\n", counter, marks[counter]); 35 | 36 | }// printing for loop ends 37 | 38 | return 0; 39 | }// end of the main function 40 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 08/Exercise 3.c: -------------------------------------------------------------------------------- 1 | /* Exercise 3: Practice to manipulate data in arrays 2 | Write a C program to create an integer array called Motion of size 5. Ask the user to enter 3 | values to the array from the keyboard. Rotate the values of the array by one position in the 4 | forward direction and display the values. */ 5 | 6 | #include 7 | int main (void) 8 | { //function main begins 9 | int no[5], counter, temp; 10 | 11 | for ( counter =0 ; counter < 5; ++counter ){ //for loop for get input begins 12 | 13 | printf( "Input Number %d : ", counter + 1);//prompt 14 | scanf( "%d", &no[counter]);//read inputs from user 15 | 16 | }//for loop ends 17 | 18 | printf( "Initial values : %d\t %d\t %d\t %d\t %d\n", no[0], no[1], no[2], no[3], no[4]);// print initioal value 19 | 20 | temp = no[0];// use temp 21 | 22 | for( counter =0 ; counter < 4; ++counter){//rotating for loop begins 23 | 24 | no[counter] = no[counter + 1]; 25 | 26 | } 27 | 28 | no[4] = temp; 29 | 30 | printf( "After rotating : %d\t %d\t %d\t %d\t %d\n", no[0], no[1], no[2], no[3], no[4]); 31 | return 0; 32 | }//end of the main function 33 | 34 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 08/Exercise 3.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 08/Exercise 3.exe -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 08/Exercise 4.c: -------------------------------------------------------------------------------- 1 | /*Write a C program that read numbers from an integer array and graph the information in the 2 | form of bar chat. Sample output is given below.*/ 3 | 4 | #include 5 | int main( void ) 6 | {//function main begins 7 | int no[10], counter, i; 8 | 9 | for( counter = 0 ; counter < 10 ; ++counter ){ 10 | 11 | printf( "Input Element %d for array : ", counter ); 12 | scanf( "%d", &no[counter]); 13 | 14 | } 15 | 16 | printf( "Element\tValue\tHistogram\n" ); 17 | 18 | for( counter=0 ; counter < 10 ; ++counter ){ 19 | 20 | printf( "%d\t%d\t ", counter, no[counter] ); 21 | 22 | for( i = 1; i <= no[counter] ; ++i ){ 23 | 24 | printf( "*" ); 25 | } 26 | printf( "\n" ); 27 | 28 | } 29 | 30 | return 0; 31 | }//function main ends 32 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 08/Tutorial8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 08/Tutorial8.pdf -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 09/Exercise 1.c: -------------------------------------------------------------------------------- 1 | //Exercise 1 : Practice to manipulate character array 2 | 3 | #include 4 | #include 5 | #define size 20 6 | int main( void ) 7 | {//function main begins 8 | int i, len;//declaring variables 9 | char fdarray[size], bkarray[size]; 10 | 11 | printf( "Input Word : " );//prompt 12 | scanf( "%20s", fdarray );//get inputs 13 | 14 | len = strlen(fdarray);//find length 15 | 16 | for( i =0; i < (len/2) ; ++i ){ 17 | 18 | if( fdarray[i] != fdarray[len -1]){ 19 | 20 | printf( "\nIt is Not a Palindrome\n" ); 21 | return -1; 22 | } 23 | } 24 | printf( "\nIt is a Palindrome\n"); 25 | 26 | }//function main ends 27 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 09/Exercise 2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main( void ) 3 | {//function main begins 4 | int Mat1[4][4], Mat2[4][4], Sum[4][4], i, j;//declaring variables 5 | 6 | printf("\nInput values for Matrix 1 : \n"); 7 | 8 | for(i=0;i<4;i++){//matrix 1 9 | for(j=0;j<4;j++){ 10 | scanf("%d", &Mat1[i][j]); 11 | } 12 | } 13 | 14 | printf("\nInput values for Matrix 2 : \n"); 15 | 16 | for(i=0;i<4;i++){//matrix 2 17 | for(j=0;j<4;j++){ 18 | scanf("%d", &Mat2[i][j]); 19 | } 20 | } 21 | 22 | for(i=0;i<4;i++){//calculation 23 | for(j=0;j<4;j++){ 24 | Sum[i][j] = Mat1[i][j] + Mat2[i][j]; 25 | } 26 | } 27 | 28 | printf("\n:: Sum of the matrix ::\n"); 29 | 30 | for(i=0;i<4;i++){ 31 | for(j=0;j<4;j++){ 32 | printf("%d",Sum[i][j]); 33 | } 34 | printf("\n"); 35 | } 36 | 37 | }//function main ends 38 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 09/Exercise 3.c: -------------------------------------------------------------------------------- 1 | //Exercise 3 2 | #include 3 | int main( void ) 4 | {//function main begings 5 | int s, p; //declaring variables 6 | double sales[4][5]; //declaring 2d array 7 | double total[5] = {0,0,0,0,0};//declaring 1d array 8 | 9 | for( s = 0 ; s < 4 ; ++s ){//for loop for get inputs begings 10 | 11 | printf( "Sales Person %d \n", s+1 ); 12 | 13 | for( p = 0 ; p < 5 ; ++p ){ 14 | 15 | printf( "Product Number %d\n", p+1 ); 16 | printf( "Input total dollar value of that product sold that day : "); 17 | scanf( "%lf", &sales[s][p]); 18 | 19 | 20 | } 21 | printf( "\n" ); 22 | }//for loop for get inputs ends 23 | 24 | for( p =0 ; p<5 ; ++p ){//for loop for cal total begings 25 | 26 | for( s=0 ; s<4 ; ++s ){ 27 | 28 | total[p] = total[p] + sales[s][p]; 29 | 30 | } 31 | 32 | printf( "Product %d Total sales : %.2f", p+1, total[p]); 33 | printf("\n" ); 34 | }//for loop for cal total ends 35 | 36 | 37 | return 0; 38 | }//end of the main function 39 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 09/Tutorial9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/2021 Feb Tutorials/TUTORIAL 09/Tutorial9.pdf -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 10/Q1/number.txt: -------------------------------------------------------------------------------- 1 | 21 43 76 98 40 -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 10/Q1/tutorial 1.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | {//function main begins 4 | int number,test;//declaring variables 5 | 6 | FILE *nfptr; 7 | 8 | nfptr = fopen("number.txt","a+");//open file in append plus mode 9 | 10 | if( nfptr == NULL ){ 11 | 12 | printf( "File cannot open\n"); 13 | return -1; 14 | 15 | } 16 | 17 | printf( "Input Number : " ); 18 | scanf( "%d", &number); 19 | 20 | fscanf(nfptr,"%d", &test); 21 | while(!feof(nfptr)){ 22 | 23 | if( test == number ){ 24 | 25 | printf( "\n::Number already in number.dat::\n" ); 26 | return -1; 27 | } 28 | 29 | else{ 30 | 31 | fscanf(nfptr, "%d", &test); 32 | 33 | } 34 | } 35 | 36 | fprintf( nfptr,"%d\t", number); 37 | fclose(nfptr);//close file 38 | 39 | nfptr = fopen("number.txt","r");//open file in reading mode 40 | 41 | fscanf(nfptr, "%d", &number); 42 | 43 | while( !feof(nfptr)){ 44 | 45 | printf("%d\t", number); 46 | fscanf(nfptr, "%d", &number); 47 | 48 | } 49 | fclose(nfptr);//close file 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /2021 Feb Tutorials/TUTORIAL 10/Q2/wx2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char name[20],type; 5 | int i ,countS=0 , countC=0 ,countT=0; 6 | 7 | FILE *cPtr; 8 | cPtr = fopen("appoinment.dat","w"); 9 | 10 | if(cPtr==NULL) 11 | { 12 | printf("Can't open file"); 13 | return -1; 14 | } 15 | 16 | for(i=1; i<=5; i++) 17 | { 18 | printf("Enter patient name and appoinment type :"); 19 | scanf("%s %c",name,type); 20 | 21 | fprintf(cPtr, "%s\t%c\n",name,type); 22 | } 23 | 24 | fclose(cPtr); 25 | 26 | cPtr=fopen("appoinment.dat","r"); 27 | 28 | if(cPtr==NULL) 29 | { 30 | printf("Can't open file"); 31 | return -1; 32 | } 33 | 34 | fscanf(cPtr, "%s %c",name,&type); 35 | 36 | while(!feof(cPtr)) 37 | { 38 | if(type== 'S') 39 | countS++; 40 | else if(type == 'C') 41 | countC++; 42 | else if(type=='T') 43 | countT++; 44 | 45 | fscanf(cPtr, "%s %c",name,&type); 46 | } 47 | 48 | printf("Appoinment Type\t\tNumber of patients\n"); 49 | 50 | printf("Consulting\t\t%d\n",countC); 51 | printf("Scanning\t\t%d\n",countS); 52 | printf("Testing\t\t%d\n",countT); 53 | 54 | fclose(cPtr); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Thushara Thiwanka 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 3/LabSheet3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Lab Sheets/Lab Sheet 3/LabSheet3.pdf -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 3/Question1-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | printf("N\t10*N\t100*N\t1000*N\n"); 7 | 8 | for(int i=0;i<10;i++){ 9 | a=i+1; 10 | printf("%d\t%d\t%d\t%d\n",a,a*10,a*100,a*1000); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 3/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n,s=1; 6 | printf("Enter n: "); 7 | scanf("%d",&n); 8 | 9 | while(n>0){ 10 | s*=n; 11 | n--; 12 | } 13 | 14 | printf("%d",s); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 3/Question3-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char a='*'; 6 | 7 | ///(a) 8 | for(int i=0;i<10;i++){ 9 | for(int j=i+1;j>0;j--) 10 | printf("%c",a); 11 | printf("\n"); 12 | } 13 | 14 | printf("\n"); 15 | 16 | ///(b) 17 | for(int i=0;i<10;i++){ 18 | for(int j=10-i;j>0;j--) 19 | printf("%c",a); 20 | printf("\n"); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 4/LabSheet4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Lab Sheets/Lab Sheet 4/LabSheet4.pdf -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 5/LabSheet5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Lab Sheets/Lab Sheet 5/LabSheet5.pdf -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 5/Question1-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a[]={25, 32, 45, 2, 13, 9, 6, 10, 17, 4}; 6 | int b; 7 | int c=0; 8 | printf("Enter Number: "); 9 | scanf("%d",&b); 10 | 11 | for(int i=0;i<10;i++){ 12 | if(a[i]==b){ 13 | c=i; 14 | break; 15 | } 16 | } 17 | 18 | c>0 ? printf("Location in array: %d",c):printf("Value not found"); 19 | 20 | return 0; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 5/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int A[]={10, 20, 30, 40, 50}; 6 | int B[]= {34, 67, 12, 89, 12}; 7 | int C[5]; 8 | 9 | for(int i=0;i<5;i++){ 10 | C[i]=A[i]*B[i]; 11 | } 12 | 13 | return 0; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 5/Question3-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int b[9]={0}; 6 | int s=0; 7 | int c; 8 | 9 | while(s!=(-1)){ 10 | printf("Enter Salary: "); 11 | scanf("%d",&s); 12 | 13 | if(s==(-1)) 14 | break; 15 | 16 | if(s>1000) 17 | b[8]+=1; 18 | else{ 19 | c=((s/100)-2); 20 | b[c]+=1; 21 | } 22 | } 23 | 24 | for(int i=0;i<9;i++)//jsut printing the array 25 | printf("%c) %d\n",(97+i),b[i]); 26 | 27 | return 0; 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 6/LabSheet6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Lab Sheets/Lab Sheet 6/LabSheet6.pdf -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 6/Question 1-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int c=20; 6 | char n[20]={0}; 7 | scanf("%s",&n); 8 | 9 | while(c>=0){ 10 | if(n[c]!='\0'){//ignore zero null values in array 11 | printf("%c",n[c]); 12 | } 13 | c--; 14 | } 15 | 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 6/Question 2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a=0,b; 6 | char c[100]; 7 | scanf("%s",&c); 8 | 9 | while(c[a]!='\0'){//only work for a single word, stop when meets a null value or a space 10 | b=c[a]; 11 | printf("%c",b-32); 12 | a++; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 6/Question 3-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a=0; 6 | int arr1[3][3]; 7 | int arr2[3][3]; 8 | 9 | for(int i=0;i<3;i++){//storing to arr1 10 | for(int j=0;j<3;j++){ 11 | scanf("%d",&arr1[i][j]); 12 | arr2[j][i]= arr1[i][j];//storing the transpose of arr1 to arr2 13 | } 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 7/LabSheet7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Lab Sheets/Lab Sheet 7/LabSheet7.pdf -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 7/Question 1-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char name[20],clas; 6 | int year; 7 | float GPA; 8 | 9 | FILE *fptr; 10 | fptr = fopen("Student.dat","w"); 11 | 12 | fprintf(fptr,"Name\tClass\tYear\tGPA\n"); 13 | 14 | for(int i=0;i<5;i++){ 15 | scanf("%s %c %d %f", &name, &clas, &year, &GPA); 16 | fprintf(fptr, "%s\t%c\t%d\t%.1f \n", name, clas, year, GPA); 17 | } 18 | 19 | fclose(fptr); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 7/Question 2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int y; 6 | char name[20],clas; 7 | int year; 8 | float GPA; 9 | int c=1; 10 | 11 | FILE *fptr; 12 | fptr = fopen("Student.dat","r"); 13 | 14 | printf("Enter Year: "); 15 | scanf("%d",&y); 16 | 17 | //ignore the first line 18 | fscanf(fptr,"%s %s %s %s", &name, &clas, &year, &GPA); 19 | 20 | while(!feof(fptr)){ 21 | fscanf(fptr,"%s %c %d %f", &name, &clas, &year, &GPA); 22 | 23 | if(year==y){ 24 | printf("Name: %s GPA: %.1f",name,GPA); 25 | break; 26 | } 27 | } 28 | 29 | fclose(fptr); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Lab Sheets/Lab Sheet 7/Student.dat: -------------------------------------------------------------------------------- 1 | Name Class Year GPA 2 | Nimal 1 1 3.7 3 | Sunil 1 2 4.0 4 | Kamal 3 3 2.7 5 | Mihiri 2 1 1.7 6 | Mala 2 4 2.1 -------------------------------------------------------------------------------- /MID/Introduction to Programming_Model Paper.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Introduction to Programming_Model Paper.pdf -------------------------------------------------------------------------------- /MID/Questions/Answers.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/Answers.docx -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0000.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0000.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0001.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0001.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0002.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0003.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0003.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0004.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0004.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0005.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0005.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0006.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0006.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0007.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0007.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0008.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0008.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0009.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0009.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0010.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0010.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0011.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0011.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0012.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0012.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0013.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0013.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0014.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0014.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0015.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0015.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0016.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0016.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0017.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0017.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0018.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0018.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0019.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0019.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0020.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0020.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0021.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0021.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0022.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0022.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0023.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0023.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0024.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0024.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0025.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0025.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0026.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0026.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0027.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0027.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0028.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0028.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0029.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0029.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0030.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0030.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0031.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0031.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0032.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0032.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0033.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0033.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0034.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0034.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0035.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0035.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0036.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0036.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0037.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0037.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0038.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0038.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0039.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0039.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0040.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0040.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0041.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0041.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0042.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0042.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0043.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0043.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0044.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0044.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0045.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0045.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0046.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0046.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0047.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0047.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0048.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0048.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0049.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0049.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0050.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0050.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0051.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0051.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0052.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0052.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0053.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0053.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0054.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0054.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0055.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0055.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0056.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0056.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0057.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0057.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0058.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0058.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0059.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0059.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0060.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0060.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0061.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0061.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0062.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0062.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0063.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0063.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0064.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0064.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0065.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0065.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0066.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0066.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0067.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0067.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0068.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0068.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0069.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0069.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0070.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0070.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0071.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0071.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0072.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0072.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0073.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0073.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0074.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0074.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0075.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0075.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0076.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0076.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0077.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0077.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0078.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0078.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0079.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0079.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0080.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0080.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0081.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0081.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0082.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0082.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0083.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0083.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0084.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0084.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0085.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0085.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0086.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0086.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0087.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0087.jpg -------------------------------------------------------------------------------- /MID/Questions/IMG-20201221-WA0088.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/IMG-20201221-WA0088.jpg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-14 at 12.57.54 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-14 at 12.57.54 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.30.29 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.30.29 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.30.59 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.30.59 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.31.21 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.31.21 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.31.55 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.31.55 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.31.56 AM (1).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.31.56 AM (1).jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.31.56 AM (2).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.31.56 AM (2).jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.31.56 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.31.56 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.32.23 AM (1).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.32.23 AM (1).jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.32.23 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.32.23 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.32.37 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.32.37 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.34.23 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.34.23 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.39.38 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.39.38 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.41.31 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.41.31 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.57.11 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.57.11 AM.jpeg -------------------------------------------------------------------------------- /MID/Questions/june/WhatsApp Image 2020-12-22 at 12.57.27 AM.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Questions/june/WhatsApp Image 2020-12-22 at 12.57.27 AM.jpeg -------------------------------------------------------------------------------- /MID/Sample_MID_Exam_Questions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/MID/Sample_MID_Exam_Questions.pdf -------------------------------------------------------------------------------- /Other Questions/Question 1/Q1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Other Questions/Question 1/Q1.jpeg -------------------------------------------------------------------------------- /Other Questions/Question 2/Online2VersionB.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Other Questions/Question 2/Online2VersionB.jpeg -------------------------------------------------------------------------------- /Other Questions/Question 3/Answers - Randula/Q3 Part 1 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main () 5 | { 6 | //declaing variables 7 | char address[200]; 8 | int i , length; 9 | 10 | //taking user inputs 11 | printf("Input : "); 12 | gets(address); 13 | 14 | 15 | //getting the input's charactor length 16 | length = strlen(address); 17 | 18 | //print the output in different lines 19 | printf("Output : "); 20 | for (i = 0 ; i < length ; i++) 21 | { 22 | if (address[i] == ',') 23 | { 24 | printf(",\n\t "); 25 | } 26 | else 27 | { 28 | printf("%c" , address[i]); 29 | } 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Other Questions/Question 3/Answers - Randula/Q3 Part 2 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () 4 | { 5 | //declaring variables 6 | char name[20]; 7 | int year , age; 8 | 9 | //taking user inputs for name 10 | printf("Name : "); 11 | scanf("%s" , name); 12 | 13 | //taking user inputs for year 14 | printf("Year of Birth : "); 15 | scanf("%d" , &year); 16 | 17 | printf("\n"); 18 | 19 | //calculate the age 20 | age = 2021 - year; 21 | 22 | //print the output 23 | printf("Hey %s!!! You are %d years old. Great" , name , age); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Other Questions/Question 3/Q3-Ex1-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | 6 | char address[200]; 7 | int i; 8 | int len; 9 | 10 | printf("Input : "); 11 | gets(address); 12 | 13 | len = strlen(address); 14 | 15 | printf("Output : \n\n"); 16 | for(i = 0; i < len; i++) { 17 | if (address[i] == ',') { 18 | printf(",\n"); 19 | } 20 | else { 21 | printf("%c", address[i]); 22 | } 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Other Questions/Question 3/Q3-Ex2-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | 5 | char name[10]; 6 | int bYear; 7 | 8 | printf("Name : "); 9 | scanf("%s", name); 10 | 11 | printf("Year of Birth : "); 12 | scanf("%d", &bYear); 13 | 14 | printf("Hey %s!!! You are %d years old. Great", name, 2021-bYear); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Other Questions/Question 3/Q3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Other Questions/Question 3/Q3.jpeg -------------------------------------------------------------------------------- /Other Questions/Question 4 (ATM Question)/ATM Question.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Other Questions/Question 4 (ATM Question)/ATM Question.pdf -------------------------------------------------------------------------------- /Other Questions/Question 5/File Handling Assignment.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Other Questions/Question 5/File Handling Assignment.jpeg -------------------------------------------------------------------------------- /Past Papers/2017 Jan/Final Exam/Introduction to Programming (CC++) (N102).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2017 Jan/Final Exam/Introduction to Programming (CC++) (N102).pdf -------------------------------------------------------------------------------- /Past Papers/2017/Final Exam/Introduction to Programming (N102).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2017/Final Exam/Introduction to Programming (N102).pdf -------------------------------------------------------------------------------- /Past Papers/2018 Jan/Final Exam/Introduction to Programming C (IT1103).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2018 Jan/Final Exam/Introduction to Programming C (IT1103).pdf -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/1AQ2b-Thushara.c: -------------------------------------------------------------------------------- 1 | /* Final Paper 2018 2 | * Question 2 Part B 3 | */ 4 | 5 | // including header files 6 | #include 7 | 8 | #define SIZE 4 9 | 10 | // main function 11 | int main(void) { 12 | 13 | char bulbs[SIZE][SIZE]; 14 | int q, r; 15 | 16 | // input bulb 17 | for (r = 0; r < SIZE; r++) { 18 | for (q = 0; q < SIZE; q++) { 19 | scanf(" %c", &bulbs[r][q]); 20 | } 21 | } 22 | 23 | // print bulb array 24 | printf("\n"); 25 | for (r = 0; r < SIZE; r++) { 26 | for (q = 0; q < SIZE; q++) { 27 | printf("%c ", bulbs[r][q]); 28 | } 29 | printf("\n"); 30 | } 31 | 32 | // print Red LED bulb positions 33 | printf("\nRed LED bulb positions\n"); 34 | for (r = 0; r < SIZE; r++) { 35 | for (q = 0; q < SIZE; q++) { 36 | if (bulbs[r][q] == 'R') { 37 | printf("[%d,%d] ", r, q); 38 | } 39 | } 40 | } 41 | 42 | return 0; 43 | } 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/1AQ4a-Thushara.c: -------------------------------------------------------------------------------- 1 | /* Final Paper 2018 2 | * Question 4 Part A 3 | */ 4 | 5 | // including header files 6 | #include 7 | 8 | // main function 9 | int main(void) { 10 | 11 | // declaring variables 12 | FILE *ptr; 13 | char empNum[10], empName[10]; 14 | int status = 0; 15 | int emp, day; 16 | 17 | ptr = fopen("attendance.dat", "w"); 18 | 19 | for (emp = 1; emp <= 2; emp++) { 20 | printf("Emp - %d\n", emp); 21 | printf("Employee Number : "); 22 | scanf(" %10s", empNum); 23 | printf("Employee Name : "); 24 | scanf(" %10s", empName); 25 | fprintf(ptr, "%s\t%s\t", empNum, empName); 26 | 27 | printf("\n0 for absent and 1 for present\n"); 28 | for (day = 1;day <= 7; ) { 29 | printf("\tDay %d : ", day); 30 | scanf("%d", &status); 31 | if (status == 1 || status == 0) { 32 | fprintf(ptr, "%d ", status); 33 | day ++; 34 | } 35 | } 36 | fprintf(ptr, "\n"); 37 | } 38 | 39 | fclose(ptr); 40 | 41 | return 0; 42 | } 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/1AQ4b-Thushara.c: -------------------------------------------------------------------------------- 1 | /* Final Paper 2018 2 | * Question 4 Part B 3 | */ 4 | 5 | // including header files 6 | #include 7 | #include 8 | 9 | // main function 10 | int main(void) { 11 | 12 | // declaring variables 13 | FILE *ptr; 14 | char empNumU[10], empNumF[10], empName[10]; 15 | int status[] = {0}; 16 | int day, flag = 0, report = 0; 17 | 18 | ptr = fopen("attendance.dat", "r"); 19 | 20 | printf("Employee Number : "); 21 | scanf(" %s", empNumU); 22 | 23 | while (!feof(ptr)) { 24 | fscanf(ptr, "%s%s", &empNumF, &empName); 25 | 26 | for (day = 1;day <= 7; day++) { 27 | fscanf(ptr, "%d", &status[day-1]); 28 | } 29 | 30 | if (!strcmp(empNumU, empNumF)) { 31 | flag = 1; 32 | break; 33 | } 34 | } 35 | 36 | for (day = 1; day <= 7; day ++) { 37 | if (flag == 1 && status[day - 1] == 1) { 38 | report += 1; 39 | } 40 | } 41 | 42 | printf("\nTotal No of days %s reported to work : %d", empNumU, report); 43 | 44 | fclose(ptr); 45 | 46 | return 0; 47 | } 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/2018 - Randula/4A - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //define strings 6 | char emp_no[3]; 7 | char name[20]; 8 | //define array 9 | int status[7] ; 10 | //define variabele 11 | int i; 12 | 13 | //define file 14 | FILE *atdPtr; 15 | atdPtr = fopen("attendance.dat" , "a"); //open attendance.dat file for append 16 | 17 | //take inputs from the user 18 | printf("Enter the Employee Number : "); 19 | scanf("%s" , emp_no); 20 | 21 | printf("Enter the Employee Name : "); 22 | scanf("%s" , name); 23 | 24 | for (i = 0 ; i < 7 ; i++ ) 25 | { 26 | printf("Enter the attendance of the week for the day %d : " , i + 1); 27 | scanf("%d" , &status[i]); 28 | 29 | if(status[i] != 0 && status[i] != 1) //discard an invalid input and retake 30 | { 31 | printf("Invalid Input!! Try Again!!\n"); 32 | i--; 33 | } 34 | } 35 | 36 | //adding data to the attendance.dat file 37 | fprintf(atdPtr ,"%s\t%s\t" , emp_no , name); 38 | for (i = 0 ; i < 7 ; i++) 39 | { 40 | fprintf(atdPtr ,"%d " , status[i]); 41 | } 42 | 43 | //close attendance.dat file 44 | fclose(atdPtr); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/2018 - Randula/attendance.dat: -------------------------------------------------------------------------------- 1 | 111 Perera 1 0 1 1 0 1 1 2 | 112 Silva 1 0 1 1 0 0 0 3 | 113 John 1 1 1 1 1 0 0 4 | 555 nick 1 1 0 1 1 1 0 -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/Answers - Sahan/1AJune1 - Sahan.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i; 5 | char type; 6 | int course[3] = {0,0,0}; 7 | 8 | printf("Press E to exit.\n"); 9 | 10 | for (i = 0; i <= 100; ++i) 11 | { 12 | printf("Enter course type(H/M/F): "); 13 | scanf("%c%*c", &type); 14 | 15 | if (type == 'E' || type == 'e') 16 | break; 17 | 18 | else if (type == 'H' || type == 'h') 19 | ++course[0]; 20 | 21 | else if (type == 'M' || type == 'm') 22 | ++course[1]; 23 | 24 | else if (type == 'F' || type == 'f') 25 | ++course[2]; 26 | 27 | else { 28 | printf("Invalid Input!\n"); 29 | --i; 30 | } 31 | } 32 | 33 | printf("\nCourse\tNo of students\tTotal income"); 34 | printf("\nH\t%d\t\t%.2f", course[0], course[0] * 1500.00); 35 | printf("\nM\t%d\t\t%.2f", course[1], course[1] * 2000.00); 36 | printf("\nF\t%d\t\t%.2f", course[2], course[2] * 2500.00); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/Answers - Sahan/1AJune2b - Sahan.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i, j; 5 | char led[4][4]; 6 | 7 | for (i = 0; i < 4; ++i) { 8 | for (j = 0; j < 4; ++j) { 9 | printf("Enter the colour for %d row x %d column LED bulb(R/G/B): ", i+1, j+1); 10 | scanf("%c%*c", &led[i][j]); 11 | 12 | while (led[i][j] != 'R' && led[i][j] != 'G' && led[i][j] != 'B') { 13 | printf("Invalid Input!\nEnter the colour for %d row x %d column LED bulb(R/G/B): ", i+1, j+1); 14 | scanf("%c%*c", &led[i][j]); 15 | } 16 | } 17 | } 18 | 19 | printf("\n"); 20 | 21 | for(i = 0; i < 4; ++i) { 22 | for(j = 0; j < 4; ++j) { 23 | printf(" %c ", led[i][j]); 24 | } 25 | printf("\n"); 26 | } 27 | 28 | printf("\nRed LED bulb positions:\n"); 29 | 30 | for(i = 0; i < 4; ++i) { 31 | for(j = 0; j < 4; ++j) { 32 | 33 | if(led[i][j] == 'R') 34 | printf("[%d,%d] ", i, j); 35 | } 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/Answers - Sahan/1AJune4a - Sahan.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i, j; 5 | char empNumber[3]; 6 | char name[8]; 7 | int attendance; 8 | 9 | FILE * cfPtr; 10 | cfPtr = fopen("attendance.dat", "w"); 11 | 12 | if(cfPtr == NULL) { 13 | printf("File cannot be create"); 14 | return -1; 15 | } 16 | 17 | for(i = 1; i <= 2; ++i) { 18 | printf("Enter Employee Number: "); 19 | scanf("%s", empNumber); 20 | printf("Enter Employee Name: "); 21 | scanf("%s", name); 22 | 23 | fprintf(cfPtr,"%s\t%s\t", empNumber, name); 24 | 25 | for(j = 1; j <= 7; ++j) { 26 | printf("Attendance Status for day %d(0/1): ", j); 27 | scanf("%d", &attendance); 28 | 29 | fprintf(cfPtr,"%d", attendance); 30 | } 31 | printf("\n"); 32 | fprintf(cfPtr,"\n"); 33 | } 34 | fclose(cfPtr); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/Answers - Sahan/1AJune4b - Sahan.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int count, i; 5 | int empNumberInput; 6 | int empNumber; 7 | char name[10]; 8 | char attendace[7]; 9 | 10 | count=0; 11 | 12 | FILE * cfPtr; 13 | cfPtr = fopen("attendance.dat", "r"); 14 | 15 | if(cfPtr == NULL) { 16 | printf("File cannot be open"); 17 | return -1; 18 | } 19 | 20 | printf("Enter Employee Number: "); 21 | scanf("%d", &empNumberInput); 22 | 23 | fscanf(cfPtr,"%d%s%s", &empNumber, name, attendace); 24 | 25 | while(!feof(cfPtr)) { 26 | 27 | if(empNumber == empNumberInput) { 28 | break; 29 | } 30 | 31 | fscanf(cfPtr,"%d%s%s", &empNumber, name, attendace); 32 | } 33 | 34 | for (i = 0; i < 7; ++i) { 35 | 36 | if (attendace[i] == '1') 37 | ++count; 38 | } 39 | printf("Number of days reported to work: %d", count); 40 | fclose(cfPtr); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/Answers- Léo/1AJune1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i=0; 6 | float hm=0,mk=0,fn=0; 7 | char course,des; 8 | 9 | while((i!=100)) 10 | { 11 | printf("Enter Course Type:"); 12 | scanf("%c%*c",&course); 13 | 14 | if((course =='H') || (course =='h')) 15 | { 16 | hm += 1500; 17 | i++; 18 | } 19 | else if ((course =='M') || (course =='m')) 20 | { 21 | mk += 2000; 22 | i++; 23 | } 24 | else if ((course =='F') || (course =='f')) 25 | { 26 | fn += 2500; 27 | i++; 28 | } 29 | else 30 | { 31 | printf("Invalid course.... TRY AGAIN...\n"); 32 | continue; 33 | } 34 | 35 | printf("Do you want to register more students?(Y/N) : "); 36 | scanf("%c%*c",&des); 37 | 38 | if((des == 'N') || (des == 'n')) 39 | { 40 | break; 41 | } 42 | } 43 | 44 | printf("\nTotal fees from DHM is %.2f with %.0f students\n",hm,(hm/1500)); 45 | printf("\nTotal fees from DM is %.2f with %.0f students\n",mk,(mk/2000)); 46 | printf("\nTotal fees from DF is %.2f with %.0f students\n",fn,(fn/2500)); 47 | } 48 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/Answers- Léo/1AJune2b.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char LED[4][4],choice; 6 | int i,j,counter=1,fin=0; 7 | 8 | for(i=0;i<=3;i++) 9 | { 10 | for(j=0;j<=3;j++) 11 | { 12 | printf("Enter the color %d of the display: ",counter); 13 | scanf("%c%*c",&LED[i][j]); 14 | counter ++; 15 | } 16 | } 17 | 18 | printf("Which colour?(R/B/G): "); 19 | scanf("%c",&choice); 20 | 21 | switch (choice) 22 | { 23 | case('R') : printf("Red LED bulb positions\n"); 24 | break; 25 | case('B') : printf("Blue LED bulb positions\n"); 26 | break; 27 | case('G') : printf("Green LED bulb positions\n"); 28 | break; 29 | default : printf("Unknown colour"); 30 | return -1; 31 | } 32 | 33 | for(i=0;i<=3;i++) 34 | { 35 | for(j=0;j<=3;j++) 36 | { 37 | if(LED[i][j]==choice) 38 | { 39 | printf("[%d,%d] ",i,j); 40 | } 41 | } 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/Answers- Léo/1AJune4a.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char ENo[5],check[5]; 6 | char Name[20],name[20]; 7 | int i,days,present=0,checker,attendance; 8 | 9 | FILE *att; 10 | 11 | att = fopen("attendance.dat","w"); 12 | if(att==NULL) 13 | { 14 | printf("No space to create such file..."); 15 | return -1; 16 | } 17 | 18 | for(i=0;i<=1;i++) 19 | { 20 | days=0; 21 | 22 | printf("Enter Employee Number: "); 23 | scanf("%s",ENo); 24 | 25 | printf("Enter Name: "); 26 | scanf("%s",Name); 27 | 28 | fprintf(att,"%s\t%s\t",ENo,Name); 29 | 30 | while(days<=6) 31 | { 32 | printf("Attendance: "); 33 | scanf("%d",&attendance); 34 | days +=1; 35 | fprintf(att,"%d",attendance); 36 | }fprintf(att,"\n"); 37 | printf("\n\n"); 38 | } 39 | 40 | fclose(att); 41 | 42 | 43 | 44 | return 0; 45 | } 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/Answers- Léo/1AJune4b.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char EmpNo[3],Emp_No[3]; 6 | char name[20]; 7 | char Attend[7],attend[7]; 8 | int days=0,i,con; 9 | 10 | FILE *att; 11 | 12 | att = fopen("attendance.dat","r"); 13 | if(att==NULL) 14 | { 15 | printf("No space to create such file..."); 16 | return -1; 17 | } 18 | 19 | 20 | if(att==NULL) 21 | { 22 | printf("No such file found..."); 23 | return -1; 24 | } 25 | 26 | 27 | printf("Enter Employee Number: "); 28 | scanf("%s",EmpNo); 29 | 30 | fscanf(att,"%s\t%s\t%s%*c",Emp_No,name,attend); 31 | while(!feof(att)) 32 | { 33 | //con=0; 34 | for(i=0;i<=2;i++) 35 | { 36 | if(EmpNo[i]!=Emp_No[i]) 37 | { 38 | fscanf(att,"%s\t%s\t%s%*c",Emp_No,name,attend); 39 | break; 40 | } 41 | else 42 | con=1; 43 | } 44 | if(con==1) 45 | break; 46 | } 47 | 48 | for(i=0;i<=6;i++) 49 | { 50 | // fscanf(att,"%c",&Attend[i]); 51 | 52 | if (attend[i]=='1') 53 | { 54 | days ++; 55 | } 56 | } 57 | 58 | fscanf(att,"%s\t%s\t%s",Emp_No,name,attend); 59 | 60 | 61 | printf("Number of days attended : %d",days); 62 | fclose(att); 63 | } 64 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/Final Examination Past Paper_2018.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2018 June/Final Exam/Paper 1A/Final Examination Past Paper_2018.pdf -------------------------------------------------------------------------------- /Past Papers/2018 June/Final Exam/Paper 1A/attendance.dat: -------------------------------------------------------------------------------- 1 | 1111 Thushara 1 0 1 1 0 1 0 2 | 1112 Thiwanka 0 1 0 0 1 0 1 3 | -------------------------------------------------------------------------------- /Past Papers/2018 June/Online Exam 1/VersionB/2018juneO1VB.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2018 June/Online Exam 1/VersionB/2018juneO1VB.jpeg -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers - Randula/2A - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int fib[10] , i , store; 6 | 7 | fib[0] = 0; 8 | fib[1] = 1; 9 | 10 | for (i = 2 ; i <= 10 ; i++) 11 | { 12 | fib[i] = fib[i - 2] + fib[i - 1]; 13 | } 14 | 15 | for (i = 2 ; i <= 10 ; i++) 16 | { 17 | printf("Fib[%d] = Fib[%d] + Fib[%d]\t" , i , i - 2 , i - 1); 18 | printf("%d = %d + %d\n" , fib[i] , fib[i - 2] , fib[i - 1]); 19 | printf("\n"); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers - Randula/4 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | double loyaltyNo , loyaltyNoDat; 6 | char name[50] , nameDat[50]; 7 | int i , noCheck = 0; 8 | 9 | FILE *loyalPtr; 10 | 11 | for (i = 1 ; i <= 5 ; i++) 12 | { 13 | loyalPtr = fopen("loyalty.dat" , "r+"); 14 | 15 | if(loyalPtr == NULL) 16 | { 17 | printf("Error"); 18 | return -1; 19 | } 20 | 21 | noCheck = 0; 22 | 23 | if(i > 1) 24 | { 25 | scanf("%*c"); 26 | } 27 | 28 | printf("Enter Your Name : "); 29 | scanf("%s" , name); 30 | 31 | printf("Enter the Loyalty Number : "); 32 | scanf("%lf" , &loyaltyNo); 33 | 34 | fscanf(loyalPtr , "%lf%s" , &loyaltyNoDat , nameDat); 35 | while(!feof(loyalPtr)) 36 | { 37 | //printf("%.0lf\t%s\n" , loyaltyNoDat , nameDat); 38 | if(loyaltyNoDat == loyaltyNo) 39 | { 40 | printf("Loyalty Number is already in the Database!!\n"); 41 | noCheck++; 42 | } 43 | fscanf(loyalPtr , "%lf%s" , &loyaltyNoDat , nameDat); 44 | } 45 | 46 | if (noCheck == 0) 47 | { 48 | printf("New details added to the Database!!\n"); 49 | fprintf(loyalPtr , "%.0lf\t%s\n" , loyaltyNo , name); 50 | } 51 | 52 | fclose(loyalPtr); 53 | } 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers - Randula/loyalty.dat: -------------------------------------------------------------------------------- 1 | 7728369210 Dinesh 2 | 7773457219 Subash 3 | 1 1 4 | 2 2 5 | 3 3 6 | 4 4 7 | 5 5 8 | 123 Logan 9 | 56 basic 10 | 4563 kamal 11 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers - Sahan/1AQ2a-sahan.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i; 5 | int fib[10]; 6 | 7 | fib[0] = 0; 8 | fib[1] = 1; 9 | 10 | for(i=2; i<10; ++i) 11 | { 12 | fib[i] = fib[i-2] + fib[i-1]; 13 | } 14 | 15 | for(i=0; i<10; ++i) 16 | printf("%d ", fib[i]); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers - Sahan/1AQ2b-sahan.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i, j, totRate, maxrMovie; 5 | int ratings[3][4]; 6 | float avgRate[3], maxRate; 7 | 8 | maxRate = 0; 9 | 10 | for(i=0; i<3; ++i) 11 | { 12 | for(j=0; j<4; ++j) 13 | { 14 | ratings[i][j] = 0; 15 | 16 | printf("%d review for Movie %d: ", i+1, j+1); 17 | scanf("%d", &ratings[i][j]); 18 | } 19 | printf("\n"); 20 | } 21 | printf("\n"); 22 | for(i=0; i<3; ++i) 23 | { 24 | totRate = 0; 25 | 26 | for(j=0; j<4; ++j) 27 | { 28 | printf("%d ", ratings[i][j]); 29 | totRate += ratings[i][j]; 30 | } 31 | avgRate[i] = totRate / 4.0; 32 | 33 | if(maxRate < avgRate[i]) 34 | { 35 | maxRate = avgRate[i]; 36 | maxrMovie = i+1; 37 | } 38 | 39 | printf("\n"); 40 | } 41 | printf("\nMovie\tRate(avg)"); 42 | for(i=0; i<3; ++i) 43 | { 44 | printf("\n%d\t%.2f", i+1, avgRate[i]); 45 | } 46 | printf("\n\nMovie with highest average rating: %d", maxrMovie); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers - Sahan/loyalty.dat: -------------------------------------------------------------------------------- 1 | 7728369210 Dinesh 2 | 7773457219 Subash 3 | 778635445 Sahan 4 | 715818781 Kamal 5 | 711398019 Kumari 6 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers-Léo/1AQ2a-Léo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int fib[10]; 6 | fib[0]=0; 7 | fib[1]=1; 8 | int i,res; 9 | 10 | for(i=2;i<=9;i++) 11 | { 12 | res = fib[i-2]+fib[i-1]; 13 | fib[i] = res; 14 | } 15 | for(i=0;i<=9;i++) 16 | { 17 | printf("%d\t",fib[i]); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers-Léo/1AQ2b-Léo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int ratings[3][4]; 6 | int i,j,total=0,movie; 7 | float ave,max = 0; 8 | 9 | for(i=0;i<=2;i++) 10 | { 11 | for(j=0;j<=3;j++) 12 | { 13 | printf("Input the Ratings for movie %d by reviewer %d: ",i+1,j+1); 14 | scanf("%d",&ratings[i][j]); 15 | } printf("\n"); 16 | } 17 | 18 | for(i=0;i<=2;i++) 19 | { 20 | for(j=0;j<=3;j++) 21 | { 22 | printf("%d\t",ratings[i][j]); 23 | }printf("\n"); 24 | } 25 | printf("\n"); 26 | 27 | for(i=0;i<=2;i++) 28 | { 29 | ave = 0; 30 | total = 0; 31 | 32 | for(j=0;j<=3;j++) 33 | { 34 | total += ratings[i][j]; 35 | } 36 | ave = total / 4.0; 37 | printf("Average of movie %d is %.2f\n",i+1,ave); 38 | 39 | if(max< ave) 40 | { 41 | max = ave; 42 | movie = i+1; 43 | } 44 | } 45 | printf("\nThe movie with highest rating is %d with average of %.2f",movie,max); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers-Léo/1AQ3-Leo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | float calcAnnualInterest (float interestRate,float amount); 5 | float findTotalAmount (float interestRate,float amount); 6 | void testTotalAmount(); 7 | int main() 8 | { 9 | float amount,rt,fin; 10 | int i; 11 | testTotalAmount(); 12 | printf("Assertion Passed\n\n"); 13 | 14 | printf("Input the amount to be invested: "); 15 | scanf("%f",&amount); 16 | 17 | printf("Input Rate: "); 18 | scanf("%f",&rt); 19 | 20 | if(amount>1000000) 21 | { 22 | rt += 0.5; 23 | } 24 | for(i=1;i<=5;i++) 25 | { 26 | fin =findTotalAmount(rt,amount); 27 | printf("Amount after year %d : %.2f\n",i,fin); 28 | 29 | amount=fin; 30 | } 31 | } 32 | 33 | float calcAnnualInterest (float interestRate,float amount) 34 | { 35 | 36 | return (amount * (interestRate/100)); 37 | } 38 | 39 | float findTotalAmount (float interestRate,float amount) 40 | { 41 | float x; 42 | x = calcAnnualInterest(interestRate,amount); 43 | 44 | return (x+amount); 45 | 46 | } 47 | void testTotalAmount () 48 | { 49 | assert (findTotalAmount(10,10000)==11000); 50 | } 51 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers-Léo/1AQ4-Léo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | double no,check; 6 | int i; 7 | char name[20],dibs[20]; 8 | 9 | FILE *loy; 10 | 11 | loy = fopen("loyalty.dat","r+"); 12 | 13 | if(loy == NULL) 14 | { 15 | printf("Couldn't find such file..."); 16 | return -1; 17 | } 18 | 19 | 20 | for(i=0;i<=4;i++) 21 | { 22 | printf("Enter NAME: "); 23 | scanf("%s",name); 24 | 25 | printf("Enter Loyalty number: "); 26 | scanf("%lf",&no); 27 | 28 | fscanf(loy,"%lf %s",&check,dibs); 29 | while(!feof(loy)) 30 | { 31 | if(check == no) 32 | { 33 | printf("Loyalty Number already exisits....\nRe-enter number...\n"); 34 | printf("Enter Loyalty number: "); 35 | scanf("%lf",&no); 36 | rewind(loy); 37 | } 38 | fscanf(loy,"%lf %s",&check,dibs); 39 | } 40 | fprintf(loy,"%.0lf %s\n",no,name); 41 | rewind(loy); 42 | } 43 | fclose(loy); 44 | } 45 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/Answers-Léo/loyalty.dat: -------------------------------------------------------------------------------- 1 | 7728369210 Dinesh 2 | 7773457219 Subash 3 | -------------------------------------------------------------------------------- /Past Papers/2019/Final Exam/Paper 1A/IT1010_FInalPaper_2019.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2019/Final Exam/Paper 1A/IT1010_FInalPaper_2019.pdf -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionA/2020 June Online 3 Version A - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declare array 6 | int rate[5] = {0}; 7 | 8 | //declare variables 9 | int i , input; 10 | 11 | //taking user inputs until user enters -1 12 | printf("Please input the service rating (1 - 5) : "); 13 | scanf("%d" , &input); 14 | 15 | //sort data by the input 16 | while(input != -1) 17 | { 18 | if (input >= 1 && input <= 5) 19 | { 20 | rate[input - 1]++; 21 | } 22 | else 23 | { 24 | printf("Invalid Input!!!\n"); 25 | } 26 | 27 | //taking user inputs until user enters -1 28 | printf("Please input the service rating (1 - 5) : "); 29 | scanf("%d" , &input); 30 | } 31 | printf("\n"); 32 | 33 | //print the collected data 34 | printf("Rating\tNumber of response\n"); 35 | for(i = 0 ; i < 5 ; i++) 36 | { 37 | printf("%d\t%d\n" , i + 1 , rate[i]); 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionA/2020juneO3VA-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // main function 4 | int main(void) 5 | { 6 | int rate[5] = {0}; 7 | int rating = 1; /* rating to be enterd by user 8 | * rating = 1 for begin while loop 9 | */ 10 | int i; // counter control variable 11 | 12 | // begin while 13 | while (rating != -1) { 14 | 15 | // user input for rating 16 | printf("Pls input the service rating (1- 5): "); // prompt for input 17 | scanf("%d", &rating); 18 | 19 | // check if rating valid 20 | if (rating >= 1 && rating <= 5) { 21 | rate[rating-1] += 1; // store the number of response for rate 22 | } // end if 23 | 24 | else if (rating == -1) { 25 | break; 26 | } // end else if 27 | 28 | // invalid rating error message 29 | else { 30 | printf("Invalid Input\n"); 31 | continue; 32 | } // end else 33 | }// end while 34 | 35 | printf("\nRating\tNumber of response\n"); // prompt 36 | // loop each element in array 37 | for (i = 0; i < 5; i++) { // loop 5 times 38 | printf("%d\t%d\n", i+1, rate[i]); // print results 39 | } 40 | 41 | return 0; 42 | 43 | } // end function main 44 | 45 | -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionA/Version A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/June/Online Exam 3/VersionA/Version A.pdf -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionB/2020 June Online 3 Version B - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declaring array 6 | int seat[10] = {0}; 7 | 8 | //declaring variables 9 | int i , input; 10 | 11 | //taking user inputs until user enters -1 12 | printf("Please input the seat number (1 - 10) : "); 13 | scanf("%d" , &input); 14 | 15 | //sort data by the input 16 | while(input != -1) 17 | { 18 | if (input >= 1 && input <= 10) 19 | { 20 | if ((seat[input - 1]) > 0) 21 | { 22 | printf("The Seat No.%d is reseved!!\n" , input); 23 | } 24 | else 25 | { 26 | seat[input - 1]++; 27 | } 28 | } 29 | else 30 | { 31 | printf("Sorry. Please input a valid seat number!!!\n"); 32 | } 33 | 34 | //taking user inputs until user enters -1 35 | printf("Please input the seat number (1 - 10) : "); 36 | scanf("%d" , &input); 37 | } 38 | printf("\n"); 39 | 40 | //print the collected data 41 | printf("Reserved Seat Numbers : "); 42 | for (i = 0 ; i < 10 ; i++) 43 | { 44 | if (seat[i] > 0) 45 | { 46 | printf("%d " , i + 1); 47 | } 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionB/Version B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/June/Online Exam 3/VersionB/Version B.pdf -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionC/2020 June Online 3 Version C - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | double salaries[5]; 6 | 7 | //declare variable 8 | int i; 9 | double input; 10 | 11 | //taking user inputs for 5 employees 12 | for (i = 0 ; i < 5 ; i++) 13 | { 14 | printf("Input the salary of Employee No.%d : " , i + 1); 15 | scanf("%lf" , &input); 16 | 17 | //only take inputs > 0 18 | if (input < 0) 19 | { 20 | printf("Please re-enter the amount!!\n"); 21 | i--; 22 | } 23 | else 24 | { 25 | salaries[i] = input; 26 | } 27 | } 28 | printf("\n"); 29 | 30 | //display the employees' new salary 31 | printf("Employee Number\tSalary\n"); 32 | for (i = 0 ; i < 5 ; i++) 33 | { 34 | //give a 10% increment for employees less than 10000 35 | if (salaries[i] < 10000) 36 | { 37 | salaries[i] *= 110.0 / 100; 38 | } 39 | 40 | //display salaries 41 | printf("%d\t\t%.2lf\n" , i + 1 , salaries[i]); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionC/2020juneO3VC-Thushara.c: -------------------------------------------------------------------------------- 1 | /* 2020 June 2 | * Online Exam 3 3 | * Version C 4 | */ 5 | 6 | #include 7 | 8 | // size of an array 9 | # define SIZE 5 10 | 11 | // main function 12 | int main(void) 13 | { 14 | double salaries[SIZE] = {-1, -1, -1, -1, -1}; // salaries array 15 | double salary = 0; // salary enterd by user 16 | int count; // counter control variable 17 | 18 | // begin for loop 19 | for (count = 1; count <= SIZE; ) { 20 | 21 | // user input for salary 22 | printf("Input the salary of employee %d :", count); // prompt for input 23 | scanf("%lf", &salary); 24 | 25 | // check if salary is a negative value 26 | if (salary < 0) { 27 | 28 | // invalid salary error message 29 | printf("Please re-enter the amount\n"); 30 | continue; 31 | } // end if 32 | 33 | // check if salary < 10000.00 34 | if (salary < 10000.00) { 35 | 36 | // add 10% to salary 37 | salary += salary * 10 / 100; 38 | } // end if 39 | 40 | // store salary in to salaries array 41 | salaries[count - 1] = salary; 42 | count++; 43 | } 44 | 45 | // printing array 46 | printf("\nEmployee number\t\tSalary\n"); 47 | for (count = 1; count <= SIZE; count++) { 48 | printf("%d\t\t\t%.2f\n", count, salaries[count - 1]); 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionC/Version C.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/June/Online Exam 3/VersionC/Version C.pdf -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionD/2020 June Online 3 Version D - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | double sales[5]; 6 | 7 | //declare variable 8 | int i; 9 | double input; 10 | 11 | //taking user inputs for 5 employees 12 | for (i = 0 ; i < 5 ; i++) 13 | { 14 | printf("Input the sales of Salesmen No.%d : " , i + 1); 15 | scanf("%lf" , &input); 16 | 17 | //only take inputs > 0 18 | if (input < 0) 19 | { 20 | printf("Please re-enter the amount!!\n"); 21 | i--; 22 | } 23 | else 24 | { 25 | sales[i] = input; 26 | } 27 | } 28 | printf("\n"); 29 | 30 | //display details of employees who have satisfied the criteria 31 | printf("Sales Person Number\tSales Amount\n"); 32 | for (i = 0 ; i < 5 ; i++) 33 | { 34 | if (sales[i] > 20000) 35 | { 36 | printf("%d\t\t\t%.2lf\n" , i + 1 , sales[i]); 37 | } 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionD/2020juneO3VD-Thushara.c: -------------------------------------------------------------------------------- 1 | /* 2020 June 2 | * Online Exam 3 3 | * Version D 4 | */ 5 | 6 | #include 7 | 8 | // size of an array 9 | # define SIZE 5 10 | 11 | // main function 12 | int main(void) 13 | { 14 | double sales[SIZE] = {0}; // sales array 15 | double sale = 0; // sales enterd by user 16 | int count; // counter control variable 17 | 18 | // begin for loop 19 | for (count =1; count <= SIZE; ) { 20 | 21 | // user input for sale 22 | printf("Input the sales of salesmen %d :", count); // prompt for input 23 | scanf("%lf", &sale); 24 | 25 | // check if sale is a negative value 26 | if (sale < 0) { 27 | 28 | // invalid sale error message 29 | printf("Please re-enter the amount\n"); 30 | continue; 31 | } // end if 32 | 33 | // store sale in to sales array 34 | sales[count - 1] = sale; 35 | count++; 36 | } 37 | 38 | // printing array 39 | printf("\nSales person number\tSales amount\n"); 40 | for (count = 1; count <= SIZE; count++) { 41 | if (sales[count - 1] > 20000.00) { 42 | printf("%d\t\t\t%.2f\n", count, sales[count - 1]); 43 | } 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionD/Version D.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/June/Online Exam 3/VersionD/Version D.pdf -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionE/2020 June Online 3 Version E - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declare array 6 | double price[6]; 7 | 8 | //declare variables 9 | int i ; 10 | double input; 11 | 12 | //taking user inputs of 5 book 13 | for (i = 0 ; i < 6 ; i++) 14 | { 15 | printf("Input the salary of Book No.%d : " , i + 1); 16 | scanf("%lf" , &input); 17 | 18 | //only take inputs > 0 19 | if (input <= 0) 20 | { 21 | printf("Please re-enter the amount!!\n"); 22 | i--; 23 | } 24 | else 25 | { 26 | price[i] = input; 27 | } 28 | } 29 | printf("\n"); 30 | 31 | //display the new price of the books 32 | printf("Book ID\tPrice\n"); 33 | 34 | for (i = 0 ; i < 6 ; i++) 35 | { 36 | //calculate the price reduction of the books 37 | price[i] *= 90.0 / 100; 38 | 39 | printf("%d\t%.2lf\n" , i + 1 , price[i]); 40 | } 41 | 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionE/2020juneO3VE-Thushara.c: -------------------------------------------------------------------------------- 1 | /* 2020 June 2 | * Online Exam 3 3 | * Version E 4 | */ 5 | 6 | #include 7 | 8 | // size of an array 9 | # define SIZE 6 10 | 11 | // main function 12 | int main(void) 13 | { 14 | double price[SIZE] = {0}; // price array 15 | double priceOfBook = 0; // price enterd by user 16 | int count = 0; // counter control variable 17 | 18 | // begin for loop 19 | for (count = 1; count <= SIZE; ) { 20 | 21 | // user input for price 22 | printf("Input the price of book %d :", count); // prompt for input 23 | scanf("%lf", &priceOfBook); 24 | 25 | // check if sale is a negative value or 0 26 | if (priceOfBook <= 0) { 27 | printf("Please re-enter the amount\n"); 28 | continue; 29 | } // end if 30 | 31 | // reduce 10% from priceOfBook 32 | priceOfBook -= priceOfBook * 10 / 100; 33 | 34 | // store priceOfBook in to price array 35 | price[count - 1] = priceOfBook; 36 | count++; 37 | } 38 | 39 | // printing array 40 | printf("\nBook ID\t\tPrice\n"); 41 | for (count = 1; count <= SIZE; count++) { 42 | printf("%d\t\t%.2f\n", count, price[count - 1]); 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Past Papers/2020/June/Online Exam 3/VersionE/Version E.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/June/Online Exam 3/VersionE/Version E.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 1/VersionA/VersionA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 1/VersionA/VersionA.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 1/VersionB/VersionB.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 1/VersionB/VersionB.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 1/VersionC/VersionC.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 1/VersionC/VersionC.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 1/VersionD/VersionD.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 1/VersionD/VersionD.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 1/VersionE/VersionE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 1/VersionE/VersionE.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2 - resit/Online2-resit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 2 - resit/Online2-resit.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionA/Version A - Randula/Q1 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //variables 6 | int i , j , letter; 7 | 8 | //for loop for rows 9 | for(i = 1 ; i <= 5 ; i++) 10 | { 11 | //for loop for colunms 12 | for (j = 1 ; j <= i ; j++) 13 | { 14 | printf("%c" , 97 + i - 1); //print the letters 15 | } 16 | printf("\n"); 17 | } 18 | 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionA/Version A - Randula/Q2 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //function prototype 4 | float calcIncrement(float salary, int noofYearsWorked); 5 | float calcTotSalary(float salary, float increment); 6 | 7 | int main(void) 8 | { 9 | //variables 10 | int years; 11 | float salary , increment , totalSalary; 12 | 13 | //inputs from the user 14 | printf("Enter the Salary : "); 15 | scanf("%f" , &salary); 16 | 17 | printf("Enter the Years of worked : "); 18 | scanf("%d" , &years); 19 | 20 | increment = calcIncrement(salary , years); //calling function #1 21 | 22 | totalSalary = calcTotSalary(salary , increment); //calling function #2 23 | 24 | //print details 25 | printf("Increment : %.2f\n" , increment); 26 | printf("Total Salary : %.2f\n" , totalSalary); 27 | 28 | return 0; 29 | } 30 | 31 | //called function #1 32 | float calcIncrement(float salary, int noofYearsWorked) 33 | { 34 | float increment = 0; 35 | 36 | if(noofYearsWorked > 2) 37 | { 38 | increment = salary * 10.0 / 100; 39 | } 40 | 41 | return increment; 42 | } 43 | 44 | //called function #2 45 | float calcTotSalary(float salary, float increment) 46 | { 47 | float totalSalary; 48 | 49 | totalSalary = salary + increment; 50 | 51 | return totalSalary; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionA/VersionA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 2/VersionA/VersionA.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionA/versionA-a-Sasitha.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | //Declaring variables 6 | int a=0,b=0; 7 | //For loop 01 8 | for(a=1; a<6; ++a){ 9 | //For loop 02 10 | for(b=1; b<=a; ++b){ 11 | printf("%c ",a+96); 12 | } 13 | //End of For loop 02 14 | printf("\n"); 15 | } 16 | //End of For loop 01 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionA/versionA-b-Sasitha.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //Declare function calcIncrement 4 | float calcIncrement(float salary, int nooofYearsWorked) 5 | { 6 | //Declare variables 7 | float increment; 8 | //Calculation 9 | increment = salary * 10/100; 10 | return increment; 11 | } 12 | //Declare function calcToSalary; 13 | float calcToSalary(float salary, float increment) 14 | { 15 | //Declare variables 16 | float Totalsalary,incrementGiven; 17 | //Calculation 18 | Totalsalary = salary + increment; 19 | } 20 | //Main 21 | int main() 22 | { 23 | //Declare variables 24 | float salary,increment; 25 | int workTime; 26 | //Getting user inputs 27 | printf("Enter Salary : "); 28 | scanf("%f", &salary); 29 | printf("Enter Number of years worked : "); 30 | scanf("%d", &workTime); 31 | 32 | if(workTime >= 2) 33 | { 34 | increment = calcIncrement(salary, increment); 35 | printf("Increment : %.2f\n", increment); 36 | } 37 | else 38 | { 39 | printf("Increment : No Increment\n"); 40 | } 41 | salary = calcToSalary(salary, increment); 42 | printf("Total Salary : %.2f\n", salary); 43 | } 44 | //End of main 45 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionB/Version B - Randula/Q1 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int i , j , k = 0; 6 | 7 | for (i = 5 ; i >= 1 ; i--) 8 | { 9 | for (j = 1 ; j <= i ; j++) 10 | { 11 | printf("%c" , 97 + k); 12 | } 13 | k++; 14 | printf("\n"); 15 | } 16 | 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionB/Version B - Randula/Q2 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float getDiscountPrice(int noOfGuests, float chargePerGuest); 4 | float getAmount(int noOfGuests, float chargePerGuest, float discount); 5 | 6 | int main(void) 7 | { 8 | int guests; 9 | float charge , discount , total; 10 | 11 | printf("Enter no of Guests : "); 12 | scanf("%d" , &guests); 13 | 14 | printf("Enter charge per Guest : "); 15 | scanf("%f" , &charge); 16 | 17 | discount = getDiscountPrice(guests , charge); 18 | 19 | total = getAmount(guests , charge , discount); 20 | 21 | printf("Discount : %.2f\n" , discount); 22 | printf("Amount to be paid : %.2f\n" , total); 23 | 24 | return 0; 25 | } 26 | 27 | float getDiscountPrice(int noOfGuests, float chargePerGuest) 28 | { 29 | float discount = 0; 30 | 31 | if(noOfGuests > 200) 32 | { 33 | discount = (noOfGuests * chargePerGuest) * 10.0 / 100; 34 | } 35 | 36 | return discount; 37 | } 38 | 39 | float getAmount(int noOfGuests, float chargePerGuest, float discount) 40 | { 41 | float total = 0; 42 | 43 | total = (float) (noOfGuests * chargePerGuest) - discount; 44 | 45 | return total; 46 | } 47 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionB/VersionB.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 2/VersionB/VersionB.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionB/versionB-a-Thushara.c: -------------------------------------------------------------------------------- 1 | // Online Test2 - Version B - a 2 | 3 | #include 4 | 5 | // main function 6 | int main(void) 7 | { 8 | // variable declaration 9 | int i, j; 10 | int value = 97; // initialize value variable 11 | 12 | // print rows 13 | for (i = 1; i <= 5; i++) { 14 | 15 | // print column 16 | for (j = 5; j >= i; j--) { 17 | 18 | // print character value 19 | printf("%c", value); 20 | } 21 | printf("\n"); 22 | 23 | // increse value by 1 24 | value += 1; 25 | } // end for 26 | 27 | return 0; 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionC/Version C - Randula/Q1 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | int i, r, p, value = 2; 6 | 7 | for (i = 1; i <= value; i++) 8 | { 9 | for (r = 1; r <= value; r++) 10 | { 11 | for (p = 1; p <= value; p++) 12 | { 13 | printf("[%d %d %d]\n", i, r, p); 14 | } 15 | } 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionC/Version C - Randula/Q2 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float calculateWeeklySalary(int grade, float hrsWorked); 4 | void printDetails(int grade, float hrsWorked, float salary); 5 | 6 | int main (void) 7 | { 8 | int grade; 9 | float hours , salary; 10 | 11 | printf("Enter Grade : "); 12 | scanf("%d" , &grade); 13 | 14 | printf("Enter No of hours Worked of the week : "); 15 | scanf("%f" , &hours); 16 | 17 | salary = calculateWeeklySalary(grade , hours); 18 | 19 | printDetails(grade , hours , salary); 20 | 21 | return 0; 22 | } 23 | 24 | float calculateWeeklySalary(int grade, float hrsWorked) 25 | { 26 | float salary; 27 | 28 | if (grade == 1) 29 | { 30 | salary = 100.00 * hrsWorked; 31 | } 32 | else if (grade == 2) 33 | { 34 | salary = 200.00 * hrsWorked; 35 | } 36 | else if (grade == 3) 37 | { 38 | salary = 300.00 * hrsWorked; 39 | } 40 | 41 | return salary; 42 | } 43 | 44 | void printDetails(int grade, float hrsWorked, float salary) 45 | { 46 | printf("Grade - %d\n" , grade); 47 | printf("No of hours worked for the week : %.0f\n" , hrsWorked); 48 | printf("Salary of the employee : Rs.%.2f\n" , salary); 49 | } 50 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionC/VersionC.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 2/VersionC/VersionC.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionC/versionC-a-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Online Test2 - Version C - a 4 | 5 | // main function 6 | int main(void) 7 | { 8 | // variable declaration 9 | int i, r, p, value = 2; 10 | 11 | // nested loop 12 | for (i = 1; i <= value; i++) { 13 | for (r = 1; r <= value; r++) { 14 | for (p = 1; p <= value; p++) { 15 | // print 16 | printf("[%d %d %d]\n", i, r, p); 17 | } 18 | } 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionD/Version D - Randula/Q1 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | int i, r, p, value = 1; 6 | 7 | for (i = 2; i >= value; i--) 8 | { 9 | for (r = 2; r >= value; r--) 10 | { 11 | for (p = 2; p >= value; p--) 12 | { 13 | printf("[%d %d %d]\n", i, r, p); 14 | } 15 | } 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionD/Version D - Randula/Q2 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float calculateTotalCost(int itemNo, int quantity); 4 | void printDetails(int itemNo, int quantity, float totalCost); 5 | 6 | int main (void) 7 | { 8 | int itemNo , quantity; 9 | float totalCost; 10 | 11 | printf("Enter Item No : "); 12 | scanf("%d" , &itemNo); 13 | 14 | printf("Enter Quantity : "); 15 | scanf("%d" , &quantity); 16 | 17 | totalCost = calculateTotalCost(itemNo, quantity); 18 | printDetails(itemNo , quantity, totalCost); 19 | 20 | return 0; 21 | } 22 | 23 | float calculateTotalCost(int itemNo, int quantity) 24 | { 25 | float totalCost; 26 | 27 | if (itemNo == 1) 28 | { 29 | totalCost = 100.00 * quantity; 30 | } 31 | else if (itemNo == 2) 32 | { 33 | totalCost = 200.00 * quantity; 34 | } 35 | else if (itemNo == 3) 36 | { 37 | totalCost = 300.00 * quantity; 38 | } 39 | 40 | return totalCost; 41 | } 42 | 43 | void printDetails(int itemNo, int quantity, float totalCost) 44 | { 45 | printf("Item No : %d\n" , itemNo); 46 | printf("Quantity : %d\n" , quantity); 47 | printf("Total Cost : Rs.%.2f\n" , totalCost); 48 | } 49 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionD/VersionD.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 2/VersionD/VersionD.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionE/Version E - Randula/Q1 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | int input = 0, minMarks , maxMarks; 6 | 7 | minMarks = 100; 8 | maxMarks = -100; 9 | 10 | printf("Enter the Marks : "); 11 | scanf("%d" , &input); 12 | 13 | while(input != -99) 14 | { 15 | if(input > 100 || input < 0) 16 | { 17 | printf("Invalid Input!!"); 18 | } 19 | else 20 | { 21 | if (input >= maxMarks) 22 | { 23 | maxMarks = input; 24 | } 25 | else if (input < minMarks) 26 | { 27 | minMarks = input; 28 | } 29 | } 30 | printf("Enter the Marks : "); 31 | scanf("%d" , &input); 32 | } 33 | 34 | printf("Maximum Marks : %d\n" , maxMarks); 35 | printf("Minimum Marks : %d\n" , minMarks); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionE/Version E - Randula/Q2 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float findRadianValue(float angleInDegrees); 4 | void printRadianValues(void); 5 | 6 | int main (void) 7 | { 8 | printRadianValues(); 9 | return 0; 10 | } 11 | 12 | float findRadianValue(float angleInDegrees) 13 | { 14 | float angleInradian; 15 | 16 | angleInradian = angleInDegrees / 180 * 22.0 / 7; 17 | 18 | return angleInradian; 19 | } 20 | void printRadianValues(void) 21 | { 22 | int i; 23 | float radian; 24 | 25 | printf("Angle(degree)\tAngle(radians)\n"); 26 | 27 | for (i = 100 ; i <= 200 ; i += 20) 28 | { 29 | radian = findRadianValue(i); 30 | printf("%d%17.2f\n" , i , radian); 31 | } 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionE/VersionE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 2/VersionE/VersionE.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionE/versionE-a-Lakshan.c: -------------------------------------------------------------------------------- 1 | //Online Exam2 versionE 2 | //including header files 3 | #include 4 | 5 | //main function 6 | int main() 7 | { 8 | // declare and initializing variables 9 | int mark = 0, min = 0, max = 0; 10 | 11 | // input first mark 12 | printf("Enter Marks, -99 to terminate : "); 13 | scanf("%d", &mark); 14 | 15 | if(mark != -99) 16 | min =mark; 17 | 18 | while(mark != -99) 19 | { 20 | while (mark <= 100 && mark >= 0) 21 | { 22 | if(mark > max) 23 | max = mark; 24 | if(mark < min) 25 | min = mark; 26 | 27 | printf("Enter Marks, -99 to terminate : "); 28 | scanf("%d", &mark); 29 | } 30 | if(mark != -99) 31 | { 32 | //print an error message 33 | printf("Invalid mark, marks should be between 0 and 100\n"); 34 | printf("Enter Marks, -99 to terminate : "); 35 | scanf("%d", &mark); 36 | } 37 | } 38 | 39 | //print minimum and maximum marks 40 | printf("Your minimum mark is : %d\n", min); 41 | printf("Your maximum mark is : %d\n", max); 42 | 43 | return 0; 44 | } 45 | //end main function 46 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 2/VersionE/versionE-b-Lakshan.c: -------------------------------------------------------------------------------- 1 | //Online Exam01 versionE 2 | #include 3 | #include 4 | 5 | // function prototype 6 | float findRadianValue(float angleInDegrees); 7 | void printRadianValues(void); 8 | 9 | // main function 10 | int main() 11 | { 12 | //function call 13 | printRadianValues(); 14 | 15 | return 0; 16 | } 17 | 18 | // function implementation 19 | float findRadianValue(float angleInDegrees) 20 | { 21 | float radianValue; 22 | 23 | radianValue = M_PI / 180 * angleInDegrees; 24 | 25 | return radianValue; 26 | } 27 | 28 | void printRadianValues(void) 29 | { 30 | float radianValue, angleInDegrees; 31 | int count = 0; 32 | 33 | angleInDegrees = 100; 34 | 35 | printf("Angle(degrees)\tAngle(radians)\n"); 36 | 37 | while(count < 6) 38 | { 39 | radianValue = findRadianValue(angleInDegrees); 40 | 41 | printf("%.0f\t\t\t%.3f\n", angleInDegrees, radianValue); 42 | 43 | count = count + 1; 44 | 45 | angleInDegrees = angleInDegrees + 20; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionA/Version A - Online Test 03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 3/VersionA/Version A - Online Test 03.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionA/Version A - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declare arrays 6 | int input[6]; 7 | int oddNum[6] = {0}; 8 | int evenNum[6] = {0}; 9 | 10 | //declare variables 11 | int i; 12 | 13 | //taking user inputs 14 | for (i = 0 ; i < 6 ; i++) 15 | { 16 | printf("Enter a number : "); 17 | scanf("%d" , &input[i]); 18 | } 19 | 20 | //printing user inputs 21 | printf("Number Series : "); 22 | for (i = 0 ; i < 6 ; i++) 23 | { 24 | printf("%d " , input[i]); 25 | } 26 | printf("\n"); 27 | 28 | //selecting odd and even numbers and assign them to relevent arrays 29 | for (i = 0 ; i < 6 ; i++) 30 | { 31 | if (input[i] % 2 == 0) 32 | { 33 | evenNum[i] = input[i]; 34 | } 35 | else 36 | { 37 | oddNum[i] = input[i]; 38 | } 39 | } 40 | 41 | //display odd numbers 42 | printf("Odd Numbers : "); 43 | for (i = 0 ; i < 6 ; i++) 44 | { 45 | if (oddNum[i] != 0) 46 | { 47 | printf("%d " , oddNum[i]); 48 | } 49 | } 50 | printf("\n"); 51 | 52 | //display even numbers 53 | printf("Even Numbers : "); 54 | for (i = 0 ; i < 5 ; i++) 55 | { 56 | if (evenNum[i] != 0) 57 | { 58 | printf("%d " , evenNum[i]); 59 | } 60 | } 61 | 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionB/Version B - Online Test 03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 3/VersionB/Version B - Online Test 03.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionB/Version B - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declare arrays 6 | int input[10]; 7 | int positiveNum[10] = {0}; 8 | int negativeNum[10] = {0}; 9 | 10 | //declare variable 11 | int i , posNos = 0 , negNos = 0; 12 | 13 | //get user inputs 14 | for (i = 0 ; i < 10 ; i++) 15 | { 16 | printf("Enter a Number : "); 17 | scanf("%d" , &input[i]); 18 | } 19 | 20 | //print entered numbers 21 | printf("Number Series : "); 22 | for (i = 0 ; i < 10 ; i++) 23 | { 24 | printf("%d " , input[i]); 25 | } 26 | 27 | //selecting positive numbers 28 | for (i = 0 ; i < 10 ; i++) 29 | { 30 | if (input[i] >= 0) 31 | { 32 | positiveNum[posNos] = input[i]; 33 | posNos++; 34 | } 35 | else 36 | { 37 | negativeNum[negNos] = input[i]; 38 | negNos++; 39 | } 40 | } 41 | 42 | printf("\n"); 43 | 44 | //printing positive numbers 45 | printf("Positive numbers : "); 46 | for (i = 0 ; i < posNos ; i++) 47 | { 48 | printf("%d " , positiveNum[i]); 49 | } 50 | printf("\n"); 51 | 52 | //printing negative numbers 53 | printf("Negative numbers : "); 54 | for (i = 0 ; i < negNos ; i++) 55 | { 56 | printf("%d " , negativeNum[i]); 57 | 58 | } 59 | 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionC/Version C - Online Test 03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 3/VersionC/Version C - Online Test 03.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionC/Version C - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | //declaring arrays 6 | int myArray[10] , largeNum[10]; 7 | 8 | //declaring variables 9 | int i , largeNo , lrgNo = 0; 10 | int total = 0; 11 | float average ; 12 | 13 | //taking user inputs 14 | for (i = 0 ; i < 10 ; i++) 15 | { 16 | printf("Enter a Number : "); 17 | scanf("%d" , myArray[i]); 18 | } 19 | 20 | //calculate total and average 21 | for (i = 0 ; i < 10 ; i++) 22 | { 23 | total += myArray[i]; 24 | } 25 | average = (float) total / 10; 26 | 27 | printf("Average : %.1f\n" , average); 28 | 29 | //printing myArray 30 | printf("My Array : "); 31 | for (i = 0 ; i < 10 ; i++) 32 | { 33 | printf("%d " , myArray[i]); 34 | } 35 | 36 | //assigning values to largeNum array 37 | for (i = 0 ; i < 10 ; i++) 38 | { 39 | if (myArray[i] > (int)average) 40 | { 41 | largeNum[lrgNo] = myArray[i]; 42 | lrgNo++; 43 | } 44 | } 45 | printf("\n"); 46 | 47 | //printing largeNum 48 | printf("largeNum : "); 49 | for (i = 0 ; i < lrgNo ; i++) 50 | { 51 | printf("%d " , largeNum[i]); 52 | } 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionD/Version D - Online Test 03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 3/VersionD/Version D - Online Test 03.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionD/Version D - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | //declaring array 6 | int num[8]; 7 | 8 | //declaring variables 9 | int i , patten = 0; 10 | 11 | //taking user inputs (numbers between 1 - 4) 12 | for (i = 0 ; i < 8 ; i++) 13 | { 14 | printf("Enter a number (1 - 4) : "); 15 | scanf("%d" , &num[i]); 16 | 17 | if(num[i] > 4 || num[i] < 1) 18 | { 19 | printf("Invalid Input!!\n"); 20 | i--; 21 | } 22 | } 23 | 24 | //printing user inputs 25 | printf("Num Array : "); 26 | for (i = 0 ; i < 8 ; i++) 27 | { 28 | printf("%d " , num[i]); 29 | } 30 | printf("\n"); 31 | 32 | 33 | //checking the given pattern 34 | for (i = 0 ; i < 8 ; i++) 35 | { 36 | if (num[i] == 3 && num[i - 1] == 1) 37 | { 38 | patten++; 39 | } 40 | } 41 | 42 | //getting the output 43 | printf("Number of times the pattern '1 3' appear : %d\n" , patten); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionE/Due to an error of the question here gives the two possibilities.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 3/VersionE/Due to an error of the question here gives the two possibilities.txt -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionE/Version E - Online Test 03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2020/September/Online Exam 3/VersionE/Version E - Online Test 03.pdf -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionE/Version E - Randula (Ascending).c: -------------------------------------------------------------------------------- 1 | //ascending check 2 | 3 | #include 4 | 5 | int main (void) 6 | { 7 | //declaring array 8 | int input[6]; 9 | 10 | //declaring variavle 11 | int i; 12 | 13 | //taking inputs from the user 14 | for(i = 0 ; i < 6 ; i++) 15 | { 16 | printf("Enter a Number : "); 17 | scanf("%d" , &input[i]); 18 | } 19 | 20 | //check if the input sequence in ascending 21 | for(i = 1 ; i < 6 ; i++) 22 | { 23 | if (input[i] < input[i - 1]) 24 | { 25 | printf("Numbers are not stored in ascending order.\n"); 26 | return -1; 27 | } 28 | } 29 | 30 | printf("Numbers are stored in ascending order.\n"); 31 | return 0; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Past Papers/2020/September/Online Exam 3/VersionE/Version E - Randula (Deascending).c: -------------------------------------------------------------------------------- 1 | //deascending check 2 | 3 | #include 4 | 5 | int main (void) 6 | { 7 | //declaring array 8 | int input[6]; 9 | 10 | //declaring variavle 11 | int i; 12 | 13 | //taking inputs from the user 14 | for(i = 0 ; i < 6 ; i++) 15 | { 16 | printf("Enter a Number : "); 17 | scanf("%d" , &input[i]); 18 | } 19 | 20 | //check if the input sequence in ascending 21 | for(i = 1 ; i < 6 ; i++) 22 | { 23 | if (input[i] > input[i - 1]) 24 | { 25 | printf("Numbers are not stored in deascending order.\n"); 26 | return -1; 27 | } 28 | } 29 | 30 | printf("Numbers are stored in deascending order.\n"); 31 | return 0; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 2/Version 1 - (pizzaOutlet)/V1-(pizzaOutlet) - Thushara.c: -------------------------------------------------------------------------------- 1 | // Example 2 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 2/Version 1 - (pizzaOutlet)/Version 1 - (pizzaOutlet).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 2/Version 1 - (pizzaOutlet)/Version 1 - (pizzaOutlet).png -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 2/Version 2 - (purchasedItem)/V 2 - (purchasedItem) - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declare variables 6 | int item , quantity; 7 | float totalPrice = 0 , unitPrice; 8 | 9 | //taking user inputs until user enters -1 for item 10 | printf("Enter Item : "); 11 | scanf("%d" , &item); 12 | 13 | while(item != -1) 14 | { 15 | unitPrice = 0; 16 | 17 | printf("Enter Quantity : "); 18 | scanf("%d" , &quantity); 19 | 20 | //calculate the unit price by the input 21 | switch (item) 22 | { 23 | case 1 : unitPrice = (float)300.25 * quantity; 24 | break; 25 | case 2 : unitPrice = (float)145.50 * quantity; 26 | break; 27 | case 3 : unitPrice = (float)525.00 * quantity; 28 | break; 29 | default : printf("Invalid Input!!\n"); 30 | break; 31 | } 32 | totalPrice += unitPrice; 33 | 34 | printf("\n"); 35 | printf("Enter Item : "); 36 | scanf("%d" , &item); 37 | } 38 | printf("Total Price to pay Rs : %.2f\n" , totalPrice); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 2/Version 2 - (purchasedItem)/Version 2 - (purchasedItem).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 2/Version 2 - (purchasedItem)/Version 2 - (purchasedItem).jpeg -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 2/Version 3 - (bowlingGame)/V 3 - (bowlingGame) - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declaring variables 6 | int players , score , totalScore = 0 , playerNo; 7 | int maxScore = 0 , maxPlayerNo , i , j; 8 | 9 | //taking user input - number of players 10 | printf("Input Number of Players : "); 11 | scanf("%d" , &players); 12 | 13 | printf("\n"); 14 | //taking details of the players and do the calculations 15 | for (i = 0 ; i < players ; i++) 16 | { 17 | totalScore = 0; 18 | 19 | printf("Input Player Number : "); 20 | scanf("%d" , &playerNo); 21 | 22 | for (j = 0 ; j < 3 ; j++) 23 | { 24 | printf("Input Score %d : " , j + 1); 25 | scanf("%d" , &score); 26 | 27 | totalScore += score; 28 | } 29 | printf("Total Score : %d\n" , totalScore); 30 | 31 | if (maxScore < totalScore) 32 | { 33 | maxScore = totalScore; 34 | maxPlayerNo = playerNo; 35 | } 36 | printf("\n"); 37 | } 38 | 39 | //printing the number of the player who got the maximum score 40 | printf("The Player who got the Maximum Score of %d is Player No.%d\n" , maxScore , maxPlayerNo); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 2/Version 3 - (bowlingGame)/Version 3 - (bowlingGame).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 2/Version 3 - (bowlingGame)/Version 3 - (bowlingGame).jpeg -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 2/Version 4 - (burgerOutlet)/V 4 - (burgerOutlet) - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declare variables 6 | int type , quantity; 7 | float totalPrice; 8 | 9 | //take user input until user enters other than 1 , 2 or 3 to type 10 | printf("Enter Burger Type : "); 11 | scanf("%d" , &type); 12 | 13 | //calculate and retake inputs 14 | while(type == 1 || type == 2 || type == 3) 15 | { 16 | printf("Enter Quantity : "); 17 | scanf("%d" , &quantity); 18 | 19 | switch (type) 20 | { 21 | case 1 : totalPrice = (float)500.00 * quantity; 22 | break; 23 | case 2 : totalPrice = (float)550.00 * quantity; 24 | break; 25 | case 3 : totalPrice = (float)600.00 * quantity; 26 | break; 27 | } 28 | printf("Total Price : %.2f\n" , totalPrice); 29 | printf("\n"); 30 | 31 | printf("Enter Burger Type : "); 32 | scanf("%d" , &type); 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 2/Version 4 - (burgerOutlet)/Version 4 - (burgerOutlet).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 2/Version 4 - (burgerOutlet)/Version 4 - (burgerOutlet).jpeg -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 2/Version 5 - (stationaryShop)/V 5 - (stationaryShop) - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declare variables 6 | int itemNo , quantity; 7 | float totalPrice = 0 , unitPrice; 8 | 9 | //taking inputs until user enters -99 to type 10 | printf("Enter Item : "); 11 | scanf("%d" , &itemNo); 12 | 13 | //calculation by the user inputs 14 | while(itemNo != -99) 15 | { 16 | unitPrice = 0; 17 | 18 | printf("Enter Quantity : "); 19 | scanf("%d" , &quantity); 20 | 21 | switch(itemNo) 22 | { 23 | case 1 : unitPrice = (float)30.00 * quantity; 24 | break; 25 | case 2 : unitPrice = (float)45.00 * quantity; 26 | break; 27 | case 3 : unitPrice = (float)55.00 * quantity; 28 | break; 29 | default : printf("Invalid Input!!\n"); 30 | break; 31 | } 32 | 33 | totalPrice += unitPrice; 34 | printf("\n"); 35 | 36 | printf("Enter Item : "); 37 | scanf("%d" , &itemNo); 38 | } 39 | 40 | //printing the calculation result 41 | printf("Total Price to Pay : %.2f\n" , totalPrice); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 2/Version 5 - (stationaryShop)/Version 5 - (stationaryShop).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 2/Version 5 - (stationaryShop)/Version 5 - (stationaryShop).jpeg -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 1 - (chocolate)/V1-(chocolate) - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declaring array 6 | float size[3][5] = {0}; 7 | float avgSize[3] = {0}; 8 | 9 | //declaring variables 10 | int i , j; 11 | float totalSize; 12 | 13 | //taking inputs from the user 14 | for (i = 0 ; i < 3 ; i++) 15 | { 16 | printf("Production of Day No.%d\n" , i + 1); 17 | for (j = 0 ; j < 5 ; j++) 18 | { 19 | printf(" Produce of the machine No.%d : " , j + 1); 20 | scanf("%f" , &size[i][j]); 21 | } 22 | printf("\n"); 23 | } 24 | printf("\n"); 25 | 26 | //displaying user inputs 27 | for (i = 0 ; i < 3 ; i++) 28 | { 29 | for (j = 0 ; j < 5 ; j++) 30 | { 31 | printf("%.1f " , size[i][j]); 32 | } 33 | printf("\n"); 34 | } 35 | printf("\n"); 36 | 37 | //calculate the average size of each day and assign to the relevant array 38 | for (i = 0 ; i < 3 ; i++) 39 | { 40 | totalSize = 0; 41 | for (j = 0 ; j < 5 ; j++) 42 | { 43 | totalSize += size[i][j]; 44 | } 45 | avgSize[i] = totalSize / 5; 46 | } 47 | 48 | //display the average size 49 | for (i = 0 ; i < 3 ; i++) 50 | { 51 | printf("Average Produce of Day No.%d : %.2f\n" , i + 1 , avgSize[i]); 52 | } 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 1 - (chocolate)/V1-(chocolate) - Thushara.c: -------------------------------------------------------------------------------- 1 | // Thushara Thiwanka 2 | #include 3 | 4 | int main(void) { 5 | 6 | float ballSize = 0; 7 | float size[3][5]; 8 | float avgSize[3]; 9 | int i, j; 10 | float avg = 0, temp = 0; 11 | 12 | for(i = 0; i < 3; i++) { 13 | printf("Input for Machine %d\n", i+1); 14 | for(j = 0; j < 5; j++) { 15 | printf("\tSize : "); 16 | scanf("%f", &ballSize); 17 | size[i][j] = ballSize; 18 | } 19 | } 20 | 21 | for(i = 0; i < 3; i++) { 22 | for(j = 0; j < 5; j++) { 23 | temp += size[i][j]; 24 | } 25 | avg = temp / 5; 26 | avgSize[i] = avg; 27 | temp = 0; 28 | } 29 | 30 | for(i = 0; i < 3; i ++) { 31 | printf("Machine %d average size = %f\n", i+1, avgSize[i]); 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 1 - (chocolate)/Version 1 - (chocolate).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 5/Version 1 - (chocolate)/Version 1 - (chocolate).jpg -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 2 - (Student's Final Mark)/Version 2(Student's Final Mark).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 5/Version 2 - (Student's Final Mark)/Version 2(Student's Final Mark).png -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 3 - (Boxes)/Version3 (Boxes) - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declare the 2D array 6 | float boxes[4][3]; 7 | 8 | //declare variables 9 | int i , j; 10 | char mesurement[20]; 11 | float volume; 12 | 13 | //taking user inputs 14 | for (i = 0 ; i < 4 ; i++) 15 | { 16 | printf("Details of Box No : %d\n" , i + 1); 17 | for (j = 0 ; j < 3 ; j++) 18 | { 19 | switch (j) 20 | { 21 | case 0 : printf("Enter the Length of the Box : " ); 22 | break; 23 | case 1 : printf("Enter the Width of the Box : " ); 24 | break; 25 | case 2 : printf("Enter the Height of the Box : " ); 26 | break; 27 | } 28 | scanf("%f" , &boxes[i][j]); 29 | } 30 | printf("\n"); 31 | } 32 | 33 | //displaying user inputs 34 | for (i = 0 ; i < 4 ; i++) 35 | { 36 | for (j = 0 ; j < 3 ; j++) 37 | { 38 | printf("%.0f " , boxes[i][j]); 39 | } 40 | printf("\n"); 41 | } 42 | printf("\n"); 43 | 44 | //calculate and display the volume of the boxes 45 | for (i = 0 ; i < 4 ; i++) 46 | { 47 | volume = 1; 48 | printf("Volume of box No.%d : " , i + 1); 49 | for (j = 0 ; j < 3 ; j++) 50 | { 51 | volume *= boxes[i][j]; 52 | } 53 | printf("%.2f\n" , volume); 54 | 55 | } 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 3 - (Boxes)/Version3 (Boxes)- Leo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | int main(void) 6 | { 7 | int boxes[4][3]; //Declaration of the 2D array with it's name and size 8 | int i,j,count=0; //Decalring variables 9 | float volume[4],volumeCalculation; // Decalring an array and a variable 10 | 11 | for(i=0;i<=3;i++) 12 | { 13 | for(j=0;j<=2;j++) // loops used to go through the 2D array 14 | { 15 | printf("Enter measurements of box %d: ",i+1); //Asking for user input 16 | scanf("%d",&boxes[i][j]); //Saving user input 17 | } 18 | printf("\n"); 19 | } 20 | 21 | printf("\n"); 22 | 23 | for(i=0;i<=3;i++) 24 | { 25 | volumeCalculation=1; //inialized a variable 26 | for(j=0;j<=2;j++) //loop used to go through the elements in the array 27 | { 28 | volumeCalculation *= boxes[i][j]; //calculation to find the volume 29 | } 30 | volume[count]=volumeCalculation; //storing the volume obtained of a box in the array named volume 31 | count++; //incrementing a counter 32 | } 33 | 34 | printf("\n"); 35 | 36 | for(i=0;i<=3;i++) //loop used to go through the elements in the array 37 | { 38 | printf("Volume of box %d is: %.2f\n",i+1,volume[i]); //Printing the volume of each box 39 | } 40 | 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 3 - (Boxes)/Version3 (Boxes).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 5/Version 3 - (Boxes)/Version3 (Boxes).jpg -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 4 - (Rainfall)/Version4 (Rainfall) - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | //declare array 6 | int rainfall[3][4]; 7 | 8 | //declare variable 9 | int i , j; 10 | int maxRainfall = 0; 11 | 12 | //taking user input 13 | for (i = 0 ; i < 3 ; i++) 14 | { 15 | printf("Details of day No.%d\n" , i + 1); 16 | for (j = 0 ; j < 4 ; j++) 17 | { 18 | printf("Rainfall of City No.%d : " , j + 1); 19 | scanf("%d" , &rainfall[i][j]); 20 | } 21 | printf("\n"); 22 | } 23 | 24 | //displaying user inputs 25 | for (i = 0 ; i < 3 ; i++) 26 | { 27 | for (j = 0 ; j < 4 ; j++) 28 | { 29 | printf("%d " , rainfall[i][j]); 30 | } 31 | printf("\n"); 32 | } 33 | printf("\n"); 34 | 35 | //displaying maximum rainfall of each day 36 | for (i = 0 ; i < 3 ; i++) 37 | { 38 | maxRainfall = 0; 39 | 40 | printf("Maximum Rainfall of Day No.%d : " , j + 1); 41 | for (j = 0 ; j < 4 ; j++) 42 | { 43 | if (maxRainfall < rainfall[i][j]) 44 | { 45 | maxRainfall = rainfall[i][j]; 46 | } 47 | } 48 | printf("%d\n" , maxRainfall); 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 4 - (Rainfall)/Version4(Rainfall) - Sahan.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i, j; 6 | float rainfall[3][4], maxRainfall[4]; 7 | 8 | for (i = 0; i < 3; ++i) 9 | { 10 | maxRainfall[i] = 0; 11 | 12 | for (j = 0; j < 4; ++j){ 13 | rainfall[i][j] = 0; 14 | 15 | printf("Input the rainfall for day %d in city %d: ", i+1, j+1); 16 | scanf("%f", &rainfall[i][j]); 17 | 18 | if (rainfall[i][j] > maxRainfall[i]) 19 | maxRainfall[i] = rainfall[i][j]; 20 | } 21 | printf("\n"); 22 | } 23 | 24 | for (i = 0; i < 3; ++i) 25 | { 26 | printf("\nMaximum rainfall for day %d: %.2f", i+1, maxRainfall[i]); 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 4 - (Rainfall)/Version4(Rainfall) - Sahan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 5/Version 4 - (Rainfall)/Version4(Rainfall) - Sahan.png -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 5 - (temperature)/V5-(temperature) - Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | 5 | float temp[2][3]; 6 | float avgTemp[2]; 7 | int i = 0, j = 0; 8 | float t = 0, avg = 0; 9 | 10 | for(i = 0; i < 2; i++) { 11 | printf("City %d\n", i+1); 12 | for(j = 0; j < 3; j++) { 13 | printf("\tTemperature : "); 14 | scanf("%f", &temp[i][j]); 15 | } 16 | } 17 | 18 | for(i = 0; i < 2; i++) { 19 | for(j = 0; j < 3; j++) { 20 | t += temp[i][j]; 21 | } 22 | avg = t / 3; 23 | avgTemp[i] = avg; 24 | t = 0; 25 | } 26 | 27 | for(i = 0; i < 2; i ++) { 28 | printf("\nCity %d average temperature = %.2f\n", i+1, avgTemp[i]); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 5 - (temperature)/Version 5 - (temperature).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 5/Version 5 - (temperature)/Version 5 - (temperature).jpeg -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 5/Version 6 - (Rainfall in colombo and kandy)/V 6 - (Rainfall in colombo and kandy).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 5/Version 6 - (Rainfall in colombo and kandy)/V 6 - (Rainfall in colombo and kandy).jpeg -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 6/Version 1 - Product/Version 1 - Product.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 6/Version 1 - Product/Version 1 - Product.jpeg -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 6/Version 2 - Employee/Version 2 - Employee.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 6/Version 2 - Employee/Version 2 - Employee.jpeg -------------------------------------------------------------------------------- /Past Papers/2021 Feb/Online Exam 6/Version 3 - Book/Version 3 - Book.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 Feb/Online Exam 6/Version 3 - Book/Version 3 - Book.jpeg -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 1 (advertisement)/Version 1 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | //declare variables 6 | int timeP , noOfTimes; 7 | char pTime; 8 | float amount , peakPrice; 9 | 10 | //take user inputs 11 | printf("Time period : "); 12 | scanf("%d" , &timeP); 13 | 14 | printf("Number of times : "); 15 | scanf("%d" , &noOfTimes); 16 | 17 | printf("Peak Time(Y/N) : "); 18 | scanf("%*c%c" , &pTime); 19 | 20 | //calculate the amount 21 | if (timeP > 60) 22 | { 23 | amount = (float)25000 * noOfTimes; 24 | } 25 | else if (timeP >= 45) 26 | { 27 | amount = (float)12000 * noOfTimes; 28 | } 29 | else 30 | { 31 | amount = (float)75000 * noOfTimes; 32 | } 33 | 34 | if (pTime == 'Y' || pTime == 'y') 35 | { 36 | peakPrice = (float) 20 / 100; 37 | } 38 | else if (pTime == 'N' || pTime == 'n') 39 | { 40 | peakPrice = 0; 41 | } 42 | else 43 | { 44 | printf("Invalid Input!\n"); 45 | return -1; 46 | } 47 | 48 | amount += peakPrice; 49 | 50 | //display total amount 51 | printf("Total amount to be paid : %.2f\n" , amount); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 1 (advertisement)/Version 1_(advertisement).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 May/Online Test 1/Version 1 (advertisement)/Version 1_(advertisement).jpeg -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 2 (restaurant)/Version 2_ (restaurant).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 May/Online Test 1/Version 2 (restaurant)/Version 2_ (restaurant).jpeg -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 3 (bank)/Version 3 (Bank).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 May/Online Test 1/Version 3 (bank)/Version 3 (Bank).jpeg -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 3 (bank)/Version 3 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | //declare variables 6 | int age; 7 | float balance; 8 | 9 | //take user inputs 10 | printf("Age : "); 11 | scanf("%d" , &age); 12 | 13 | printf("Bank Balance : "); 14 | scanf("%f" , &balance); 15 | 16 | //display the gift 17 | printf("Gift : "); 18 | if (age > 18) 19 | { 20 | if (balance > 100000) 21 | { 22 | printf("Rice Cooker\n"); 23 | } 24 | else 25 | { 26 | printf("Travelling Bag\n"); 27 | } 28 | } 29 | else 30 | { 31 | if (balance > 100000) 32 | { 33 | printf("Tablet\n"); 34 | } 35 | else 36 | { 37 | printf("School Bag\n"); 38 | } 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 3 (bank)/Version 3 - radser2001.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //function main begins program execution 4 | int main(void) 5 | { 6 | //declaring variables 7 | int age; 8 | float bankBalance; 9 | 10 | //taking age as the user input 11 | printf("Enter your Age: "); 12 | scanf("%d", &age); 13 | 14 | //taking bank balance as the user input 15 | printf("Enter your Bank balance: "); 16 | scanf("%f", &bankBalance); 17 | 18 | 19 | //deciding and displaying the gift 20 | if( age <= 18) 21 | { 22 | if( bankBalance <= 100000 ) 23 | { 24 | printf("\nCongratulations!!!\n"); 25 | printf("\nGift: School Bag"); 26 | } 27 | else 28 | { 29 | printf("\nCongratulations!!!\n"); 30 | printf("\nGift: Tablet "); 31 | } 32 | } 33 | 34 | else if( age > 18 ) 35 | { 36 | if( bankBalance <= 100000) 37 | { 38 | printf("\nCongratulations!!!\n"); 39 | printf("\nGift: Travelling Bank"); 40 | } 41 | else 42 | { 43 | printf("\nCongratulations!!!\n"); 44 | printf("\nGift: Rice Cooker"); 45 | } 46 | } 47 | 48 | 49 | return 0; 50 | 51 | } //end functin main 52 | -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 3 (bank)/Version3 - radser2001.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //function main begins program execution 4 | int main(void) 5 | { 6 | //declaring variables 7 | int age; 8 | float bankBalance; 9 | 10 | //taking age as the user input 11 | printf("Enter your Age: "); 12 | scanf("%d", &age); 13 | 14 | //taking bank balance as the user input 15 | printf("Enter your Bank balance: "); 16 | scanf("%f", &bankBalance); 17 | 18 | 19 | //deciding and displaying the gift 20 | if( age <= 18) 21 | { 22 | if( bankBalance <= 100000 ) 23 | { 24 | printf("\nCongratulations!!!\n"); 25 | printf("\nGift: School Bag"); 26 | } 27 | else 28 | { 29 | printf("\nCongratulations!!!\n"); 30 | printf("\nGift: Tablet "); 31 | } 32 | } 33 | 34 | else if( age > 18 ) 35 | { 36 | if( bankBalance <= 100000) 37 | { 38 | printf("\nCongratulations!!!\n"); 39 | printf("\nGift: Travelling Bank"); 40 | } 41 | else 42 | { 43 | printf("\nCongratulations!!!\n"); 44 | printf("\nGift: Rice Cooker"); 45 | } 46 | } 47 | 48 | 49 | return 0; 50 | 51 | } //end functin main 52 | -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 4 (partyPackage)/Version 4 (partyPackage).jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 May/Online Test 1/Version 4 (partyPackage)/Version 4 (partyPackage).jpeg -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 4 (partyPackage)/Version 4 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | //declare variables 6 | int foodType , noOfGuests; 7 | char pType; 8 | float pPrice , foodPrice , bill; 9 | 10 | //take user inputs 11 | printf("Package Type : "); 12 | scanf("%c" , &pType); 13 | 14 | printf("Food Type : "); 15 | scanf("%d" , &foodType); 16 | 17 | printf("Number Of Guests : "); 18 | scanf("%d" , &noOfGuests); 19 | 20 | //calculate the bill 21 | if (pType == 'S' || pType == 's') 22 | { 23 | pPrice = 10000; 24 | } 25 | else if (pType == 'G' || pType == 'g') 26 | { 27 | pPrice = 25000; 28 | } 29 | else 30 | { 31 | printf("Invalid Package Type\n"); 32 | return -1; 33 | } 34 | 35 | if (foodType == 1) 36 | { 37 | foodPrice = 1000; 38 | } 39 | else if (foodType == 2) 40 | { 41 | foodPrice = 2000; 42 | } 43 | else if (foodType == 3) 44 | { 45 | foodPrice = 1500; 46 | } 47 | else 48 | { 49 | printf("Invalid Food Type\n"); 50 | return -1; 51 | } 52 | 53 | bill = (float)pPrice + (foodPrice * noOfGuests); 54 | 55 | //display the bill amount 56 | printf("Bill Amount : %.2f\n" , bill); 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 5 (salary)/Version 5 - Randula.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | //declare variables 6 | char position; 7 | float sales , mSalary , comRate , commission , salary; 8 | 9 | //take user inputs 10 | printf("Position : "); 11 | scanf("%c" , &position); 12 | 13 | printf("Sales Amount : "); 14 | scanf("%f" , &sales); 15 | 16 | //calculate the commision and the salary 17 | if (position == 'M' || position == 'm') 18 | { 19 | mSalary = 50000; 20 | } 21 | else if (position == 's' || position == 'S') 22 | { 23 | mSalary = 75000; 24 | } 25 | else 26 | { 27 | printf("Invalid Input!!\n"); 28 | return -1; 29 | } 30 | 31 | if (sales < 30000) 32 | { 33 | comRate = 0; 34 | } 35 | else 36 | { 37 | comRate = 10.0 / 100; 38 | } 39 | 40 | commission = sales * comRate; 41 | 42 | salary = mSalary + commission; 43 | 44 | //display the commission and the salary 45 | printf("Commission : %.2f\n" , commission); 46 | printf("Salary : %.2f\n" , salary); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Past Papers/2021 May/Online Test 1/Version 5 (salary)/Version 5_salary.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Past Papers/2021 May/Online Test 1/Version 5 (salary)/Version 5_salary.jpeg -------------------------------------------------------------------------------- /Small C Excersices/Answers - Randula/Excercise 1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | int no1 , no2; 6 | float average; 7 | 8 | printf("Enter Number 1 and Number: "); 9 | scanf("%d %d" , &no1 , &no2); 10 | 11 | average = (float) (no1 + no2) / 2; 12 | 13 | printf("\n"); 14 | printf("The Average is : %.2f\n" , average); 15 | 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Small C Excersices/Answers - Randula/Excercise 2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () 4 | { 5 | float distance , amount = 0; 6 | 7 | printf("Enter the Distance : "); 8 | scanf("%f" , &distance); 9 | 10 | if (distance <= 30) 11 | { 12 | amount = distance * 50; 13 | } 14 | else 15 | { 16 | amount = (30 * 50) + ( (distance - 30) * 40); 17 | } 18 | 19 | printf("\n"); 20 | printf("Amount : %.2f\n" , amount); 21 | 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Small C Excersices/Answers - Randula/Excercise 3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (void) 4 | { 5 | int n , sum = 0 , i; 6 | 7 | printf("Enter a value for 'n' : "); 8 | scanf("%d" , &n); 9 | 10 | for (i = 1 ; i <= n ; i++) 11 | { 12 | sum += i; 13 | } 14 | 15 | printf("sum = %d\n" , sum); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Small C Excersices/Answers - Randula/Excercise 4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int minimum(int number1 ,int number2); 4 | int maximum(int number1 ,int number2); 5 | int multiply(int number1 ,int number2); 6 | 7 | int main (void) 8 | { 9 | int no1 , no2; 10 | 11 | printf("Enter a Value for no 1 : "); 12 | scanf("%d" , &no1); 13 | 14 | printf("Enter a Value for no 2 : "); 15 | scanf("%d" , &no2); 16 | 17 | printf("%d " , minimum(no1 , no2)); 18 | printf("%d " , maximum(no1 , no2)); 19 | printf("%d " , multiply(no1 , no2)); 20 | 21 | return 0; 22 | } 23 | 24 | int minimum(int number1 ,int number2) 25 | { 26 | if (number1 >= number2) 27 | { 28 | return number2; 29 | } 30 | else 31 | { 32 | return number1; 33 | } 34 | } 35 | 36 | int maximum(int number1 ,int number2) 37 | { 38 | if (number1 <= number2) 39 | { 40 | return number2; 41 | } 42 | else 43 | { 44 | return number1; 45 | } 46 | } 47 | 48 | int multiply(int number1 ,int number2) 49 | { 50 | int answer; 51 | 52 | answer = number1 * number2; 53 | 54 | return answer; 55 | } 56 | -------------------------------------------------------------------------------- /Small C Excersices/Pactice C Language.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Small C Excersices/Pactice C Language.pdf -------------------------------------------------------------------------------- /Tutorials/Tutorial 10/Additional Exercises/Question1-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | int numbers[5],a=0; 7 | 8 | for(int i=0; i<5; ++i){ 9 | printf("Enter number%d: ",i+1); 10 | scanf("%d", &numbers[i]); 11 | } 12 | 13 | for(int j=0;j<5;j++){ 14 | if(a 2 | 3 | // main function 4 | int main() { 5 | 6 | // declaring variables 7 | int numbers[5], count, i, max = 0; 8 | 9 | // input values to numbers array 10 | for (count = 1; count <= 5; count++) { 11 | printf("Enter value : "); 12 | scanf("%d", &numbers[count]); 13 | } 14 | 15 | // finding maximun value of the array 16 | for (i = 1; i < count; i++) { 17 | if (numbers[i] > max) { 18 | max = numbers[i]; 19 | } 20 | } 21 | 22 | // printing maximun value 23 | printf("\nMaximum value : %d", max); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 10/Additional Exercises/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | int ar[]={19,3,15,7,11,9,13,5,17,1}; 7 | printf("Element Value \tHistogram\n"); 8 | 9 | for(int i=0; i<10; ++i){ 10 | printf("%d \t%d\t",i,ar[i]); 11 | 12 | for(int j = ar[i];j>0;j--) 13 | printf("*"); 14 | 15 | printf("\n"); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 10/Additional Exercises/Question2-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // function prototype 4 | void printGraph(int); 5 | 6 | // main function 7 | int main() 8 | { 9 | // declaring variables 10 | int count, numbers[10] = {19, 3, 15, 7, 11, 9, 13, 5, 17, 1}; 11 | 12 | // printing header 13 | printf("Element\tValue\tHistogram\n"); 14 | 15 | // printing Element & Value 16 | for (count = 0; count < 10; count++) { 17 | printf("%d\t%d\t", count, numbers[count]); 18 | 19 | // function call for print graph 20 | printGraph(numbers[count]); 21 | printf("\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | 27 | // function definition 28 | void printGraph(int value) { 29 | int i; 30 | for (i = 1; i <= value; i ++) { 31 | printf("*"); 32 | } 33 | } 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 10/Question1-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | int marks[10], n=10, sum = 0, mean; 7 | int a; 8 | 9 | for(int i=0; i0){ 13 | marks[i]=a; 14 | } 15 | } 16 | 17 | for(int j=0;jmean){ 29 | printf("indexes of the students with more than the mean: %d\n", k);} 30 | } 31 | 32 | 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 10/Question1-full-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // main function 4 | int main() 5 | { 6 | // declaring variables 7 | int count, marks, marksList[10], total = 0; 8 | float mean; 9 | 10 | // adding marks to the array 11 | for (count = 1; count <= 10;) { 12 | printf("Enter Marks : "); 13 | scanf("%d", &marks); 14 | 15 | // check if marks between 0 to 20 16 | if (marks > 0 && marks < 20) { 17 | marksList[count] = marks; 18 | count++; 19 | } 20 | } 21 | 22 | // finding total of the marksList array 23 | for (count = 1; count <= 10; count++) { 24 | total += marksList[count]; 25 | } 26 | 27 | // finding mean of the marks 28 | mean = (float)total / 10; 29 | 30 | // printing mean of the marks 31 | printf("\nMean of the marks : %.2f ", mean); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 10/Question2-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // main function 4 | int main() 5 | { 6 | // declaring variables 7 | int count, marks, marksList[10], total = 0; 8 | float mean; 9 | 10 | // adding marks to the array 11 | for (count = 1; count <= 10;) { 12 | printf("Enter Marks : "); 13 | scanf("%d", &marks); 14 | 15 | // check if marks between 0 to 20 16 | if (marks > 0 && marks < 20) { 17 | marksList[count] = marks; 18 | count++; 19 | } 20 | } 21 | 22 | // finding total of the marksList array 23 | for (count = 1; count <= 10; count++) { 24 | total += marksList[count]; 25 | } 26 | 27 | // finding mean of the marks 28 | mean = (float)total / 10; 29 | 30 | // printing mean of the marks 31 | printf("\nMean of the marks : %.2f\n", mean); 32 | 33 | // finding indexes 34 | printf("\nIndexes of the students who obtained more than the mean of the marks\n\n"); 35 | for (count = 1; count <= 10; count++) { 36 | if (marksList[count] >= mean) { 37 | printf("%d\t", count); 38 | } 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 10/Question3-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | int Motion[5]; 7 | 8 | for(int i=0; i<5; ++i){ 9 | printf("Enter number%d: ",i+1); 10 | scanf("%d", &Motion[i]); 11 | } 12 | 13 | printf("After rotating: "); //doesn't need additional loops if you want to just print 14 | for(int j=0;j<4;j++){ //rotated array. 15 | printf("%d " ,Motion[j+1]); 16 | } 17 | 18 | printf("%d",Motion[0]); 19 | return 0; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 10/Question3-Thushara.c: -------------------------------------------------------------------------------- 1 | // including header files 2 | #include 3 | 4 | // main function 5 | int main() { 6 | 7 | // initialize variables 8 | int motion[] = {10, 6, 8, 2, 9}, lengthOfArray, i, firstIndex; 9 | 10 | // array length 11 | lengthOfArray = 5; 12 | 13 | // printing original array 14 | printf("Initial values : "); 15 | for (i = 0; i < lengthOfArray; i++) { 16 | printf("%d ", motion[i]); 17 | } 18 | 19 | // store first element 20 | firstIndex = motion[0]; 21 | 22 | // rotating 23 | for (i = 0; i < lengthOfArray - 1; i++) { 24 | motion[i] = motion[i+1]; 25 | } 26 | 27 | // adding first element in to last element 28 | motion[i] = firstIndex; 29 | 30 | // printing rotated array 31 | printf("\nAfter rotating : "); 32 | for (i = 0; i < lengthOfArray; i++) { 33 | printf("%d ", motion[i]); 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 10/Tutorial 10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Tutorials/Tutorial 10/Tutorial 10.pdf -------------------------------------------------------------------------------- /Tutorials/Tutorial 11/Additional Exercises/Question1(a,b)-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char stAnswer[3][5]={'0'}; 6 | char a; 7 | 8 | for(int i=0;i<3;i++){ 9 | printf("Student %d:\n",i+1); 10 | 11 | for(int j=0;j<5;j++){ 12 | printf("Answer for question %d: ",j+1); 13 | scanf(" %c",&a); 14 | 15 | if(a=='t' || a=='T' || a=='f' || a=='F') 16 | a=stAnswer[i][j]; 17 | else{ 18 | printf("re-enter the value\n"); 19 | j-=1; 20 | } 21 | } 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 11/Additional Exercises/Question1(c)-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char stAnswer[3][5]; 6 | char AS[5] = {'F','F','T','T','F'}; 7 | char as[5] = {'f','f','t','t','f'}; 8 | char a; 9 | 10 | for(int i=0;i<3;i++){ 11 | printf("Student %d:\n",i+1); 12 | 13 | for(int j=0;j<5;j++){ 14 | printf("Answer for question %d: ",j+1); 15 | scanf(" %c",&a); 16 | if(a=='t' || a=='T' || a=='f' || a=='F') 17 | stAnswer[i][j]=a; 18 | else{ 19 | printf("re-enter the value\n"); 20 | j-=1; 21 | } 22 | } 23 | printf("\n"); 24 | } 25 | 26 | for(int i=0;i<3;i++){ 27 | int c=0; 28 | for(int j=0;j<5;j++){ 29 | if(stAnswer[i][j]==as[j] || stAnswer[i][j]==AS[j]){ 30 | c+=1; 31 | } 32 | } 33 | printf("Student %d correct answers %d\n",i+1,c); 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 11/Additional Exercises/Question1-full-Thushara.c: -------------------------------------------------------------------------------- 1 | //Tutorial 11 Additional Exercises Question 1 2 | // Thushara Thiwanka 3 | 4 | #include 5 | 6 | #define STUDENT 3 7 | #define QUESTION 5 8 | 9 | int main(void) { 10 | 11 | char stAnswer[STUDENT][QUESTION]; 12 | char correctAnswers[5] = {'F', 'F', 'T', 'T', 'F'}; 13 | char answer; 14 | int s, q; 15 | int results; 16 | int upperCase; 17 | 18 | for (s = 0; s < STUDENT; s++) { 19 | printf("Student %d:\n", s+1); 20 | for (q = 0; q < QUESTION; ) { 21 | 22 | printf("\tAnswer for question %d : ", q+1); 23 | scanf(" %c", &answer); 24 | 25 | //convert lowercase to uppercase 26 | if(answer >= 'a' && answer <= 'z') { 27 | answer -= 32; 28 | } 29 | 30 | if (answer=='T' || answer=='t' || answer=='F' || answer=='f') { 31 | stAnswer[s][q] = answer; 32 | } 33 | else { 34 | printf("\tInvalid...! re-enter the value.\n"); 35 | continue; 36 | } 37 | q++; 38 | } 39 | } 40 | 41 | printf("\n"); 42 | 43 | for (s = 0; s < STUDENT; s++) { 44 | for (q = 0; q < QUESTION; q++) { 45 | if (stAnswer[s][q] == correctAnswers[q]) { 46 | results += 1; 47 | } 48 | } 49 | printf("Student %d No. of correct answers = %d\n", s+1, results); 50 | results = 0; 51 | } 52 | 53 | return 0; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 11/Question1-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | int a=1; 7 | 8 | char w[20]; 9 | printf("enter a word: "); 10 | scanf("%s", &w); 11 | int l = strlen(w); 12 | 13 | for(int i=0;i<(l/2);i++){ 14 | if(w[i]==w[(l-1)-i]){ 15 | 16 | }else 17 | a=0; 18 | break; 19 | } 20 | 21 | a == 1 ? printf( "%s is a palindrome",w ) : printf( "%s is a not a palindrome",w ); 22 | 23 | return 0; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 11/Question1-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | 6 | char word[10]; 7 | int length, count, flag; 8 | 9 | printf("Enter any word : "); 10 | scanf("%10s", word); 11 | 12 | length = strlen(word); 13 | 14 | for (count = 0; count <= (length/2); count++) { 15 | if (word[count] != word[(length - 1) - count]) { 16 | flag = 0; 17 | break; 18 | } 19 | 20 | else { 21 | flag = 1; 22 | } 23 | } 24 | 25 | if (flag == 1) { 26 | printf("\n%s is a palindrome\n", word); 27 | } 28 | else { 29 | printf("\n%s is a not a palindrome\n", word); 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 11/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main() 5 | { 6 | int a[4][4]={{5,7,8,10},{9,3,0,6},{8,1,9,2},{4,7,2,1}}; 7 | int b[4][4]={{2,2,1,3},{8,1,3,1},{1,2,2,4},{3,1,1,2}}; 8 | int c[4][4]; 9 | 10 | for(int i=0;i<4;i++){ 11 | for(int j=0;j<4;j++){ 12 | c[i][j]=a[i][j]+b[i][j]; 13 | } 14 | } 15 | 16 | for(int k=0;k<4;k++){ 17 | for(int l=0;l<4;l++) 18 | printf("%d ",c[k][l]); 19 | printf("\n"); 20 | } 21 | 22 | return 0; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 11/Question2-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SIZE 4 5 | 6 | int main(void) 7 | { 8 | int A[SIZE][SIZE] = { {5,7,8,10}, 9 | {9,3,0,6}, 10 | {8,1,9,2}, 11 | {4,7,2,1} }; 12 | 13 | int B[SIZE][SIZE] = { {2,2,1,3}, 14 | {8,1,3,1}, 15 | {1,2,2,4}, 16 | {3,1,1,2} }; 17 | int C[SIZE][SIZE]; 18 | int a, b; 19 | 20 | for (a = 0; a < SIZE; a++) { 21 | for (b = 0; b < SIZE; b++) { 22 | C[a][b] = A[a][b] + B[a][b]; 23 | printf("%d ", C[a][b]); 24 | } 25 | printf("\n"); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 11/Question3-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a[4][5]={0}; 6 | int s,p,d; 7 | int b=1; 8 | int i; 9 | int j; 10 | 11 | while(b==1){ 12 | printf("sales person number: "); 13 | scanf("%d",&s); 14 | printf("product number: "); 15 | scanf("%d",&p); 16 | printf("total dollar value: "); 17 | scanf("%d",&d); 18 | a[s-1][p-1]=d; 19 | 20 | printf("If you want to enter more, enter 1, else 0: "); 21 | scanf("%d",&b); 22 | printf("\n"); 23 | } 24 | 25 | for(i=0;i<4;i++){ 26 | for(j=0;j<5;j++) 27 | printf("%d person's %d product sales %d$\n",(i+1),(j+1),a[i][j]); 28 | printf("\n"); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 11/Question3-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SALE 4 4 | #define PRODUCT 5 5 | 6 | int main() 7 | { 8 | float salesProduct[SALE][PRODUCT] = {0}; 9 | int i, j; 10 | float value; 11 | char choice = 'y'; 12 | 13 | while (choice == 'y') { 14 | printf("\nEnter Salesperson Number(1-4) : "); 15 | scanf("%d", &i); 16 | printf("Enter Product Number(1-5) : "); 17 | scanf("%d", &j); 18 | printf("Enter Total dollar Value : $"); 19 | scanf("%f", &value); 20 | 21 | if (i < 1 || j < 1 || i > 4 || j > 5) { 22 | printf("\nInvalid input!!!\n"); 23 | continue; 24 | } 25 | 26 | salesProduct[i-1][j-1] = value; 27 | 28 | printf("\nIf you want to enter more, type 'y' : "); 29 | scanf(" %c", &choice); 30 | 31 | if (choice != 'y') { 32 | break; 33 | } 34 | } 35 | 36 | for (i = 0; i < SALE; i++) { 37 | for (j = 0; j < PRODUCT; j++) { 38 | printf("%d person's %d product sales $%.2f", i+1, j+1, salesProduct[i][j]); 39 | printf("\n"); 40 | } 41 | printf("\n"); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 12/Question1.(c)-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a,b=1; 6 | char c[30]; 7 | while(b==1){ 8 | printf("Enter a number: "); 9 | scanf("%d",&a); 10 | if(a==21||a==43||a==76||a==98||a==40){ 11 | printf("Wrong number\n"); 12 | }else 13 | b=0; 14 | } 15 | 16 | FILE *fptr; 17 | fptr = fopen("number.dat","a+"); 18 | if(fptr==NULL) 19 | { 20 | printf("Error opening file"); 21 | return(-1); 22 | } 23 | 24 | fprintf(fptr," %d",a); 25 | fclose(fptr); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 12/Question1.(d)-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char c[30]; 6 | 7 | FILE *fptr; 8 | fptr = fopen("number.dat","r"); 9 | 10 | if(fptr==NULL) 11 | { 12 | printf("Error opening file"); 13 | return -1; 14 | } 15 | 16 | fgets(c,30,fptr); 17 | printf("%s",c); 18 | 19 | fclose(fptr); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 12/Question2(a,b)-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char n[10]; 6 | char d; 7 | 8 | FILE *fptr; 9 | fptr = fopen("appointment.dat","w+"); 10 | 11 | for(int i=0;i<5;i++){ 12 | printf("Name: "); 13 | scanf(" %s",&n); 14 | printf("Type: "); 15 | scanf(" %c",&d); 16 | fprintf(fptr,"%s\t%c\n",n,d); 17 | } 18 | 19 | fclose(fptr); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 12/Question2.(c)-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int c=0,s=0,t=0; 6 | char d; 7 | char n[20]; 8 | FILE *fptr; 9 | fptr = fopen("appointment.dat","r"); 10 | 11 | printf("Appointment Type\tNumber of Patients\n"); 12 | for(int i=0;i<5;i++){ 13 | fscanf(fptr,"%s %c\n",&n,&d); 14 | if(d=='C') 15 | c++; 16 | else if(d=='S') 17 | s++; 18 | else if(d=='T') 19 | t++; 20 | } 21 | 22 | printf("Consulting\t%d\n",c); 23 | printf("Scanning\t%d\n",s); 24 | printf("Testing\t%d\n",t); 25 | 26 | fclose(fptr); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 12/Tutorial 12.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Tutorials/Tutorial 12/Tutorial 12.pdf -------------------------------------------------------------------------------- /Tutorials/Tutorial 12/appointment.dat: -------------------------------------------------------------------------------- 1 | qw S 2 | qw S 3 | qw S 4 | qw S 5 | qw S 6 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 12/number.dat: -------------------------------------------------------------------------------- 1 | 21 43 76 98 40 55 66 -------------------------------------------------------------------------------- /Tutorials/Tutorial 4/Question1-i-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Thushara"); 6 | 7 | return 0; 8 | } -------------------------------------------------------------------------------- /Tutorials/Tutorial 4/Question1-ii-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf("Welcome\nto\nSLIIT"); 6 | 7 | return 0; 8 | } -------------------------------------------------------------------------------- /Tutorials/Tutorial 4/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | int i; 8 | int j; 9 | int k; 10 | 11 | //1 12 | printf("********\n"); 13 | for(i=0;i<4;i++){ 14 | printf("* *\n"); 15 | }printf("********\n"); 16 | 17 | //2 18 | char a[20] = "*"; 19 | for(j=0;j<6;j++){ 20 | printf("%s\n",a); 21 | strcat(a, "*"); 22 | } 23 | 24 | //3 25 | printf(" *\n ***\n*****\n"); 26 | for(k=3;k>0;k--){ 27 | printf("%3s\n","*"); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 4/Question3-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int num1, num2, total; 6 | 7 | printf("Enter Number 1 : "); 8 | scanf("%d", &num1); 9 | printf("Enter Number 2 : "); 10 | scanf("%d", &num2); 11 | 12 | total = num1 + num2; 13 | 14 | printf("Total : "); 15 | printf("%d", total); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 4/Question4-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float balance, annualInterest, newBalance; 6 | 7 | printf("Enter Account Balance : "); 8 | scanf("%f", &balance); 9 | 10 | annualInterest = balance * 10 / 100; 11 | printf("Annual interest : %.2f\n", annualInterest); 12 | 13 | newBalance = balance + annualInterest; 14 | printf("New Balance : %.2f", newBalance); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 4/Tutorial 4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Tutorials/Tutorial 4/Tutorial 4.pdf -------------------------------------------------------------------------------- /Tutorials/Tutorial 5/Additional Exercises/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | 8 | int a; 9 | int t=0; 10 | int i; 11 | 12 | for(i = 1; i < 4; i++) { 13 | printf("Enter fee for bus %d: ",i); 14 | scanf("%d", &a); 15 | t += a; 16 | } 17 | 18 | printf(" traveling expenditure for the semester %d: ",t*2*120); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 5/Additional Exercises/Question3-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int p; 8 | int d; 9 | float r; 10 | 11 | printf("Enter Principal: "); 12 | scanf("%d",&p); 13 | printf("Enter rate: "); 14 | scanf("%f",&r); 15 | printf("Enter no of days: "); 16 | scanf("%d",&d); 17 | 18 | printf("Interest : %.2f: ",(p*d*r/365)); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 5/Additional Exercises/Question4-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | float w; 8 | float h; 9 | 10 | printf("Enter Weight in KG: "); 11 | scanf(" %f",&w); 12 | printf("Enter Height in M: "); 13 | scanf(" %f",&h); 14 | 15 | printf("BMI : %.2f: ",(w/pow(h,2)) ); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 5/Additional Exercises/Question5-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int n; 8 | 9 | printf("Enter n: "); 10 | scanf(" %d",&n); 11 | int sum = n*(n+1)*0.5; 12 | printf("SUM : %d: ", sum ); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 5/Additional Exercises/Question6-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int d; 7 | 8 | printf("Enter 5 digit number: "); 9 | scanf(" %d",&d); 10 | printf("%d %d %d %d %d",d/10000,(d%10000)/1000,(d%1000)/100,(d%100)/10,d%10 ); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 5/Question3-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { float a; 7 | printf("Enter radius: "); 8 | scanf(" %f",&a); 9 | printf("diameter: %.2f\n",a*2); 10 | printf("circumference: %.2f\n",(a*2*22/7)); 11 | printf("area: %.2f\n",pow(a,2)*22/7); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 5/Question4-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { int a; 7 | printf("Enter Time in Seconds: "); 8 | scanf(" %d",&a); 9 | printf("HH:%d MM:%d SS:%d\n",a/3600,(a%3600)/60,a%60); 10 | 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 5/Tutorial 5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Tutorials/Tutorial 5/Tutorial 5.pdf -------------------------------------------------------------------------------- /Tutorials/Tutorial 6/Question1-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int a; 8 | printf("Enter a number: "); 9 | scanf("%d",&a); 10 | 11 | if(a>0) 12 | printf("number is positive"); 13 | else if(a==0) 14 | printf("number is zero"); 15 | else 16 | printf("number is negative"); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 6/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int a; 8 | printf("Enter a number: "); 9 | scanf("%d",&a); 10 | 11 | if(a%2==0) 12 | printf("even number"); 13 | else 14 | printf("odd number"); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 6/Question3-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int a; 8 | printf("Enter a number: "); 9 | scanf("%d",&a); 10 | 11 | if( ((a/10000)==(a%10)) && ( ((a%10000)/1000) ==((a%100)/10) ) ) 12 | printf("Palindrome "); 13 | else 14 | printf("Not Palindrome"); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 6/Question4-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | char a; 8 | printf("Enter Grade: "); 9 | scanf(" %c",&a); 10 | 11 | if( a=='A' || a=='a' ) 12 | printf("Excellent"); 13 | else if( (a=='B' || a=='b') ) 14 | printf("Good"); 15 | else if( (a=='C' || a=='c') ) 16 | printf("Satisfactory"); 17 | else if( (a=='D' || a=='d') ) 18 | printf("Needs Improvement"); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 6/Question5-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | char a; 8 | printf("Enter Grade: "); 9 | scanf(" %c",&a); 10 | 11 | switch(a){ 12 | 13 | case 'A': 14 | case 'a': 15 | printf("Excellent"); 16 | break; 17 | 18 | case 'B': 19 | case 'b': 20 | printf("Good"); 21 | break; 22 | 23 | case 'C': 24 | case 'c': 25 | printf("Satisfactory"); 26 | break; 27 | 28 | case 'D': 29 | case 'd': 30 | printf("Needs Improvement"); 31 | break; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 6/Question6-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | char grade; 8 | printf("Enter Grade: "); 9 | scanf(" %c",&grade); 10 | 11 | 12 | if( grade=='A' ) 13 | printf("Excellent"); 14 | else if( grade=='B') 15 | printf("Good"); 16 | else if( (grade=='C' || grade=='c') ) 17 | printf("OK"); 18 | else 19 | printf("Needs Improvement"); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 6/Question7-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int c; 8 | int s; 9 | 10 | printf("Enter Employee category: "); 11 | scanf(" %d",&c); 12 | printf("Enter Employee Salary: "); 13 | scanf(" %d",&s); 14 | 15 | printf("Bonus :%.2f", 0.05*c*s ); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 6/Tutorial 6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Tutorials/Tutorial 6/Tutorial 6.pdf -------------------------------------------------------------------------------- /Tutorials/Tutorial 7/Additional Exercises/Question1-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int i; 8 | 9 | //a) 10 | for(i=1;i<8;i++) 11 | printf("%d ",i); 12 | 13 | 14 | printf("\n"); //New line 15 | 16 | //b) 17 | for(i=3;i<25;i+=5) 18 | printf("%d ",i); 19 | 20 | printf("\n"); //New line 21 | 22 | //c) 23 | for(i=20;i>(-11);i-=6) 24 | printf("%d ",i); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 7/Additional Exercises/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | int r=1; 8 | float t; 9 | int p; 10 | float d; 11 | 12 | while(r==1){ 13 | printf("Package No: "); 14 | scanf(" %d",&p); 15 | if(p>0 && p<5){ 16 | printf("Total Distance: "); 17 | scanf(" %f",&d); 18 | 19 | 20 | if(p==1) 21 | t= 150 + 175*(d-1); 22 | else if(p==2) 23 | t= 100*d; 24 | else if(p==3) 25 | t= 130 + 150*(d-1); 26 | else if(p==4) 27 | t= 120 + 130*(d-1); 28 | 29 | printf("Total Amount: Rs.%.2f\n",t); 30 | 31 | }else 32 | printf("Invalid Package Number"); 33 | 34 | char n; 35 | printf("Do you have more customers? "); 36 | scanf(" %c",&n); 37 | if(n=='y' || n=='Y') 38 | r=1; 39 | else if((n=='n' || n=='N')) 40 | r=0; 41 | 42 | }//end of while 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 7/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | char n[10]; 8 | int m; 9 | char nn[10]; 10 | int mm=0; 11 | int i; 12 | int j; 13 | 14 | for(i=0;i<3;i++){ 15 | printf("Enter name: "); 16 | scanf(" %s",&n); 17 | int t = 0; 18 | 19 | for(j=0;j<4;j++){ 20 | 21 | printf("Enter Mark: "); 22 | scanf(" %d",&m); 23 | t+=m; 24 | } 25 | 26 | printf("Total marks: %d\n",t); 27 | 28 | if(mm 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | //top 8 | char a[10]="*"; 9 | for(int i=0;i<7;i++){ 10 | printf("%s\n",a); 11 | strcat(a, "*");//concatenating a[] with * 12 | } 13 | 14 | //bottom 15 | int b=7; 16 | for(int i=4;i>0;i--){ 17 | for(int i=b;i>0;i--){ 18 | printf("*"); 19 | } 20 | printf("\n"); 21 | b-=2; 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 7/Tutorial 7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Tutorials/Tutorial 7/Tutorial 7.pdf -------------------------------------------------------------------------------- /Tutorials/Tutorial 8/Additional Exercises/Question1-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void ab(int a);//i)function initialization 5 | void abc(int c,char d);//ii) 6 | 7 | int main() 8 | { 9 | //i) 10 | int a=4; 11 | ab(a);//calling ab function 12 | 13 | printf("\n"); 14 | 15 | //ii) 16 | int c=4; 17 | char fillCharacter = '#'; 18 | abc(c,fillCharacter);//calling abc function 19 | 20 | return 0; 21 | } 22 | 23 | void ab(int a){ 24 | int x=a; 25 | for(a;a>0;a--){ 26 | for(int b=x;b>0;b--){ 27 | printf("*"); 28 | } 29 | printf("\n"); 30 | } 31 | } 32 | 33 | void abc(int c,char d){ 34 | int y=c; 35 | for(c;c>0;c--){ 36 | for(int f=y;f>0;f--){ 37 | printf("%c",d); 38 | } 39 | printf("\n"); 40 | } 41 | } 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 8/Additional Exercises/Question1-i-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void solidSquare(int); 4 | 5 | int main() 6 | { 7 | int side; 8 | 9 | printf("Side Value : "); 10 | scanf("%d", &side); 11 | printf("\n"); 12 | 13 | solidSquare(side); 14 | 15 | return 0; 16 | } 17 | 18 | void solidSquare(int side) { 19 | int count1, count2; 20 | for (count1 = 1; count1 <= side; count1++){ 21 | for (count2 = 1; count2 <= side; count2++){ 22 | printf("*"); 23 | } 24 | printf("\n"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 8/Additional Exercises/Question1-ii-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void solidSquare(int, char); 4 | 5 | int main() 6 | { 7 | int side = 0, count1, count2; 8 | char fillCharacter; 9 | 10 | printf("Side Value : "); 11 | scanf("%d", &side); 12 | printf("Fill Character : "); 13 | scanf(" %c", &fillCharacter); 14 | printf("\n"); 15 | 16 | solidSquare(side, fillCharacter); 17 | 18 | return 0; 19 | } 20 | 21 | void solidSquare(int side, char fillCharacter) { 22 | int count1, count2; 23 | for (count1 = 1; count1 <= side; count1++){ 24 | for (count2 = 1; count2 <= side; count2++){ 25 | printf("%c", fillCharacter); 26 | } 27 | printf("\n"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 8/Additional Exercises/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void roots(float a,float b,float c);//i)function initialization 5 | 6 | int main() 7 | { 8 | float a; 9 | float b; 10 | float c; 11 | 12 | printf("Enter a: "); 13 | scanf("%f",&a); 14 | printf("Enter b: "); 15 | scanf("%f",&b); 16 | printf("Enter c: "); 17 | scanf("%f",&c); 18 | 19 | roots(a,b,c); 20 | 21 | return 0; 22 | } 23 | 24 | void roots(float a,float b,float c){ 25 | 26 | float d = sqrt( (pow(b,2)-(4*a*c)) ); 27 | //root 1 28 | float r1 = ((-b)+d)/(2*a); 29 | //root 2 30 | float r2 = ((-b)-d)/(2*a); 31 | 32 | printf("Roots are: %.2f, %.2f",r1,r2); 33 | 34 | } 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 8/Question2-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | float circleArea(float r);//function intilaization 5 | int main() 6 | { 7 | float r; 8 | printf("Enter Radius: "); 9 | scanf("%f",&r); 10 | 11 | float a = circleArea(r);//calling function and assign return value to a. 12 | printf("Area: %.2f",a); 13 | 14 | return 0; 15 | } 16 | 17 | float circleArea(float r){ 18 | return( pow(r,2)*22/7 ); 19 | } 20 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 8/Question3-Anjana.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int add(int a,int b);//function initialization 5 | int multiply(int a,int b); 6 | int square(int a); 7 | 8 | int main() 9 | { 10 | int c = multiply(3,4); 11 | int d = multiply(5,7); 12 | int f = add(c,d); 13 | int g = square(f); 14 | 15 | printf("%d", g ); 16 | return 0; 17 | } 18 | 19 | int add(int a,int b){ 20 | return( a+b ); 21 | } 22 | int multiply(int a,int b){ 23 | return( a*b ); 24 | } 25 | int square(int a){ 26 | return( pow(a,2) ); 27 | } 28 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 8/Tutorial 8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Tutorials/Tutorial 8/Tutorial 8.pdf -------------------------------------------------------------------------------- /Tutorials/Tutorial 9/Additional Exercises/Question3-Thushara.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int qualityPoints(int average); 5 | void testQualityPoints(); 6 | 7 | int main() { 8 | int average, qualityPoint; 9 | 10 | printf("Student's average : "); 11 | scanf("%d", &average); 12 | 13 | testQualityPoints(); 14 | qualityPoint = qualityPoints(average); 15 | printf("Quality Point : %d", qualityPoint); 16 | 17 | return 0; 18 | } 19 | 20 | int qualityPoints(int average) { 21 | 22 | if (100 >= average && average >= 90) 23 | return 4; 24 | else if (89 >= average && average >= 80) 25 | return 3; 26 | else if (79 >= average && average >= 70) 27 | return 2; 28 | else if (69 >= average && average >= 60) 29 | return 1; 30 | else if (60 > average) 31 | return 0; 32 | } 33 | 34 | void testQualityPoints() { 35 | assert(qualityPoints(100) == 4); 36 | assert(qualityPoints(90) == 4); 37 | assert(qualityPoints(89) == 3); 38 | assert(qualityPoints(80) == 3); 39 | assert(qualityPoints(79) == 2); 40 | assert(qualityPoints(70) == 2); 41 | assert(qualityPoints(69) == 1); 42 | assert(qualityPoints(60) == 1); 43 | assert(qualityPoints(59) == 0); 44 | } 45 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 9/Question1-Thushara.c: -------------------------------------------------------------------------------- 1 | #include // including header files 2 | #include 3 | #include 4 | 5 | // function prototype 6 | double hypotenuse(double side1, double side2); 7 | 8 | // main function 9 | int main() { 10 | 11 | // assert 12 | assert(hypotenuse(3.0, 4.0) == 5.0); 13 | assert(hypotenuse(5.0, 12.0) == 13.0); 14 | assert(hypotenuse(8.0, 15.0) == 17.0); 15 | 16 | // print hypotenuse 17 | printf("Triangle 1 Hypotenuse : %f\n", hypotenuse(3.0, 4.0)); 18 | printf("Triangle 2 Hypotenuse : %f\n", hypotenuse(5.0, 12.0)); 19 | printf("Triangle 3 Hypotenuse : %f\n", hypotenuse(8.0, 15.0)); 20 | 21 | return 0; 22 | } 23 | 24 | // function definition 25 | double hypotenuse(double side1, double side2) { 26 | double hypotenuse; 27 | 28 | hypotenuse = sqrt((side1 * side1) + (side2 * side2)); 29 | 30 | return hypotenuse; // return statement 31 | } 32 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 9/Question2-Thushara.c: -------------------------------------------------------------------------------- 1 | #include // including header files 2 | #include 3 | #include 4 | 5 | // function prototype 6 | double hypotenuse(double side1, double side2); 7 | void testHypotenuse(); 8 | 9 | // main function 10 | int main() { 11 | 12 | // function call 13 | testHypotenuse(); 14 | 15 | // print hypotenuse 16 | printf("Triangle 1 Hypotenuse : %f\n", hypotenuse(3.0, 4.0)); 17 | printf("Triangle 2 Hypotenuse : %f\n", hypotenuse(5.0, 12.0)); 18 | printf("Triangle 3 Hypotenuse : %f\n", hypotenuse(8.0, 15.0)); 19 | 20 | return 0; 21 | } 22 | 23 | // function definition 24 | double hypotenuse(double side1, double side2) { 25 | double hypotenuse; 26 | 27 | hypotenuse = sqrt((side1 * side1) + (side2 * side2)); 28 | 29 | return hypotenuse; // return statement 30 | } 31 | 32 | void testHypotenuse() { 33 | assert(hypotenuse(6.0, 8.0) == 10.0); 34 | assert(hypotenuse(10.0, 24.0) == 26.0); 35 | assert(hypotenuse(32.0, 60.0) == 68.0); 36 | } 37 | -------------------------------------------------------------------------------- /Tutorials/Tutorial 9/Tutorial 9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Randula98/C-programming/79911e0e3cc6b41b7bde52ca2ffa42a3e0796e0c/Tutorials/Tutorial 9/Tutorial 9.pdf --------------------------------------------------------------------------------