Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINNERING

EEE3123
COMPUTER PROGRAMMING
GROUP 1
LAB 1: INTRODUCTION TO C PROGRAMMING

NAME : MD AZIZUL HOQUE


MATRIC NO : 200191
LECTURER : ASSOC. PROF. DR. WAN ZUHA BIN WAN HASAN
SUBMSSION DATE : 01.12 .2020
Objective:

 To introduce C language.
 To edit, create, compile, execute and debug a simple text output program written
in C language.

Equipment: Personal Computer with C Program Pre-Installed

Introduction:

A C program is generally formed by a set of functions, which subsequently consist of


many programming statements. Using functions, a large computing task can be broken
into smaller ones. Functions can be created to execute small, frequently-used tasks. In
C, there are predefined functions or sometimes called standard functions, and user
-defined functions.

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>

int main (void)

{
/* local declarations */
float celsius;
float fahrenheit;

/* prompt the user to key in the temperature in Fahrenheit */


printf(“Enter temperature in Celcius: “);

/* the value is passed into the variable named Fahrenheit */


scanf(“%f”, &celcius);

/* computation of the conversion */


fahrenheit = ((9.0 / 5.0) * celcius) + 32;

/* displaying the corresponding Celsius value */


printf(“the value in Fahrenheit is: %f”, fahrenhiet);

return 0;
}
3. Redo step 2 using listing 1.2, 1.3 and 1.4.
Listing 1.2

/* this is an example program


*
#include <stdio.h>
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
/* this program has error(s)
#include <stdio.h>

int main (void)


{
printf “hello THERE !!”);
printf(‘we are to find’];
printf (‘the error’);
return 0
}

Listing 1.4

/this is another program with some errors in it and needs to be corrected/

#include (stdio.h)

void main (void)


{
/*local variable declarations

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>

int main (void)

/* local declarations */

float Celsius;

float Fahrenheit;

/* prompt the user to key in the temperature in Fahrenheit */

printf("Enter temperature in Celsius: ");

/* the value is passed into the variable named Fahrenheit */

scanf("%f", & Celsius);

/* computation of the conversion */

Fahrenheit = ((9.0 / 5.0) * Celsius) + 32;

/* displaying the corresponding Celsius value */

printf("the value in Fahrenheit is: %f", Fahrenheit);

return 0;

}
Figure 1: Listing1.1, Program code after the detection of errors.

Figure 2: Listing 1.1, output of the amended program.


Listing 1.2:

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;
}

Figure 3: Listing1.2, Program code after the detection of errors.


Figure 4: Listing 1.2, output of the amended program.

LISTING 1.3:

Coding
#include <stdio.h>

int main (void)


{
printf("hello THERE !!");
printf("we are to find ");
printf("the error.");
return 0;
}
Figure 5: Listing1.3, Program code after the detection of errors.

Figure 6: Listing 1.3, output of the amended program.

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;

Figure 1: Listing1.4, Program code after the detection of errors.

Figure 8: Listing 1.4, output of the amended program.


Discussion:

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:

1.Lab manual 1, EEE3123- Computer Programming.

You might also like