











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lab exercise provides a comprehensive introduction to debugging techniques in c programming using codeblocks ide. It guides students through the process of identifying and fixing syntax and logical errors in code. The lab also explores the implementation of piecewise functions in c, demonstrating how to handle different conditions within a single program. Students will gain practical experience in debugging, code optimization, and applying mathematical concepts to programming.
Typology: Schemes and Mind Maps
1 / 19
This page cannot be seen from the preview
Don't miss anything!












ASSESSMENT In-Lab Performance: / Post-Lab: Data Presentation (4) Data Analysis (4) Writing Style (4) Total: / Instructor’s remarks: Lab # 01 Introduction to Development Tools, Basics of C
Programming and Debugging
Learn to use IDE such as Code Blocks for compiling and debugging computer programs written in C language.
Code Blocks IDE MinGW C Compiler Pre Lab Get the Code Block IDE and MinGW C Compiler setup files from the lab and install them on your computer.
Introduction to Computer Programming
#include <stdio.h> #include <stdlib.h> int main() { int x, y, r; printf ("Enter first number:"); scanf("%d" , &x); printf("Enter second number:"); scanf("%d", &y); r = x + y; printf("Sum is : %d/n",r); return 0; }
In-Lab
Make a new C project (console application) using CodeBlocks and type the following code in the main.c file. Build the code, fix the indicated errors, and run it. #include <stdio.h> #include <stdlib.h> int main () { int N = 0 ; // Take a number N. printf ( "Enter a number for which you want to find the factorial: \n" ); Scanf ( "%d" , & N ); // Get input from the user printf ( "\nYou entered: %d\n\n" , n ); // Display what the user entered. int R = 0 ; // Take a variable R to hold result int x = 0 ; // And another x to count x = N - 1 ; // Let x equal to N-1 R = N// let R = N do { R = R ***** x ; // multiply R with x and store result in R.
Fill the table using the above equation for values of n from -20 to 20. You will be using this table to compare the output of the program in the next task and fixing some logical errors. n f[n] n f[n] -10 150 -11 176 -12 204 -13 234 -14 266 -15 300 -16 336 -2 92 -3 16 -4 15 -5 14 -6 13 -7 12 10 500 11 781 12 1128 13 1547 14 3444 5 - 6 - 7 -
Type and build the following code in a new CodeBlocks project. Compare the output of the program with the table in task 1. Find any logical error and write the correct program. #include <stdio.h> #include <stdlib.h> int main (void) { int range_min = - 20 ; int range_max = 20 ; int n ;
14 22. 15 23
#include <stdio.h> #include <stdlib.h> int main(void) { int range_min = - 5 ; int range_max = 20; int n; int output; printf("For the range %d to %d, ", range_min, range_max); printf("The output of the function is: \n"); for(n=range_min; n<range_max; n++) { if(n< 3 ) { output = (-n-4); } else if((n>=3)&&(n<=10)) { output = ((n*n)-7); } else if (n> 10 ) { output = ((120/n)+n); } printf("%d\n", output); } printf("\n\n"); return 0; }