Professional Documents
Culture Documents
Lab 1
Lab 1
EEE3123
COMPUTER PROGRAMMING
GROUP 1
LAB 1: INTRODUCTION TO C PROGRAMMING
To introduce C language.
To edit, create, compile, execute and debug a simple text output program written
in C language.
Introduction:
Methodology:
1. Locate and execute C program in your computer.
2. Enter listing 1.1 into the editor. Compile and run the program. Record errors
encountered.
Listing 1.1
/* This program is to convert the temperature in Celsius to its corresponding
Fahrenheit value. Happy trying! */
#include <stdio.h>
{
/* local declarations */
float celsius;
float fahrenheit;
return 0;
}
3. Redo step 2 using listing 1.2, 1.3 and 1.4.
Listing 1.2
Listing 1.3
/* this program has error(s)
#include <stdio.h>
Listing 1.4
#include (stdio.h)
a = 3 int;
b = 5.3 float, double;
c,d = a,b character;
/*statements
printf (The values are: , a,b,c,d);
printf(“the end of the program’)
return 0;
}/*main*/
Listing 1.1:
CODING
#include <stdio.h>
/* local declarations */
float Celsius;
float Fahrenheit;
return 0;
}
Figure 1: Listing1.1, Program code after the detection of errors.
CODING
#include <stdio.h>
int main()
{
int num;
printf ("This is ");
printf ("a program ");
printf("that does not ");
printf("look too good.");
printf("Enter a number > ");
scanf("%d",&num);
printf("This is number %d",num);
return 0;
}
LISTING 1.3:
Coding
#include <stdio.h>
Listing 1.4:
Coding
#include<stdio.h>
int main(void)
{
int a=3;
double b=5.3;
float d=b;
char c=a;
printf ("the values are:%d ,%f, %d, %f ",a , b, c, d);
printf (" the end of the program ");
return 0;
In the listing 1.1, was given a program mainly with so many spelling errors. In the figure
1, all the spelling errors were fixed and after the fixation of the program, I was able to
run the program and I got the mathematically accurate output which is given in the
figure 2. In the listing 2.2, was given a program which is not organized in order to run
the program, I had to organize the program in right c programming manner else it would
not run properly. I was able to run the program once I organized the coding program
and fixed all the existing errors in the listing 2.2. In figure 3, correct coding of the
program is written and once I run the program, I got the desired output which is stated in
the figure 4. In the listing 1.3, there was an error in the line 5 where a first bracket was
missing after the printf and also in the line 6, there was a third bracket instead of the first
bracket and there was some problem with the right spacing which was also amended.
Once I corrected all the errors, I was able to run the program which is stated in the
figure 5 and 6. At last in the listing 1.4, there was errors in in the beginning of the
program and also in the declaration of integer value, float value and char value. Those
values were not declared properly after the correction of the program, I was able to run
it also able to get the desired output which implies that I have detected all the errors in
given flawed program and able to run it properly.
Conclusion:
In this lab, I was introduced to the basic fundamentals of the C programming and I was
able to detect the errors and solve the problem in C programming.
REFERENCE: