0% found this document useful (0 votes)
23 views17 pages

Lab Report1

Uploaded by

lexuankhoa321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views17 pages

Lab Report1

Uploaded by

lexuankhoa321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

VIETNAM NATIONAL UNIVERSITY – HOCHIMINH CITY

INTERNATIONAL UNIVERSITY
SCHOOL OF ELECTRICAL ENGINEERING

PROGRAMMING FOR ENGINEER LABORATORY

[Data Types, Making Decisions and Looping ]

Submitted by
[Lê Nguyễn Khả Ngân – EEEEIU23017]

Date Submitted: [21/10/2024]


Date Performed: [21/10/2024]
Lab Section: [LAB 01]
Course Instructor: [Dr. Huynh Tan Quoc]
International University School of Electrical Engineering

GRADING GUIDELINE FOR LAB REPORT


Number Content Score Comment

1 Format (max 9%)

- Font type Yes No

- Font size Yes No

- Lab title Yes No

- Page number Yes No

- Table of contents Yes No

- Header/Footer Yes No

- List of figures (if exists) Yes No

- List of tables (if exists) Yes No

- Lab report structure Yes No

2 English Grammar and Spelling (max 6%)

- Grammar Yes No

- Spelling Yes No

3 Data and Result Analysis (max 85%)

Total Score

Signature:

Date:

[Programming for Engineers Laboratory] [EEEE22IU41]


International University School of Electrical Engineering

Table of Contents

List of Figures.................................................................................................................................... I

List of Tables...................................................................................................................................... I

Nomenclature.................................................................................................................................. II

1 Theoretical Background............................................................................................................ 1

2 Exercise’s Procedure.................................................................................................................. 2
2.1 Exercise 1................................................................................................................................................... 2
2.2 Exercise 2................................................................................................................................................... 2
2.3 Exercise 3................................................................................................................................................... 2
2.4 Exercise 4................................................................................................................................................... 2

3 Exercise’s Results........................................................................................................................ 3
3.1 Exercise 1................................................................................................................................................... 2
3.2 Exercise 2................................................................................................................................................... 2
3.3 Exercise 3................................................................................................................................................... 2
3.4 Exercise 4................................................................................................................................................... 2

4 Discussion of Results.................................................................................................................. 4

List of Figures
Figure 1: Circuit diagram 1........................................................................................................................... 2
Figure 2: Circuit diagram 2........................................................................................................................... 2
Figure 3: Simulation for experiment 1......................................................................................................3

List of Tables
Table 1: Comparison of circuit parameters............................................................................................1
Table 2: Data of experiment 1...................................................................................................................... 3

[Programming for Engineers Laboratory] I [EEEE22IU41]


International University School of Electrical Engineering

Nomenclature

[Programming for Engineers Laboratory] II [EEEE22IU41]


International University School of Electrical Engineering

1 Theoretical Background

In this section, we study several methods about how to write a complete program in C language
by using input/output statement,if…else, switch, while, for, do…while statements and

[Programming for Engineers Laboratory] 1 [EEEE22IU41]


International University School of Electrical Engineering

2 Experimental Procedure

The goal in this section is to explain the experiment well enough that someone else
could repeat the procedure. You should describe what equipment and components are
used, how the equipment is set up, and how the data are collected. A schematic diagram
may be necessary to fully explain the setup – remember – a picture is worth a thousand
words.

[Schematic of Circuit]

Figure 1: Circuit diagram 1.


In these writing assignments, you should figure out how to appropriately format your
text. You should be using the correct symbols like “”, not “a”. The symbol “” requires the
use of Symbol font. Also, superscripts and subscripts are easily done by selecting the text,
and changing the format. For numbers less than 1, you should remember to type the
leading zero, as in “Vin = 0.01V)”. Learn how to insert a Table in the text and format the
table borders. Your reports will have a more professional character when you take the
time to properly format the text.

2.1 Exercise 1

For this exercise, we have to write a C program that reads 12 integers. The program
should count the number of positive and negative values among 12 inputs. Print them on
the screen.

#include<stdio.h>
int main(){
printf("Le Nguyen Kha Ngan - EEEEIU23017 \n");
int count_positive=0;
int count_negative=0;
int number[12];

[Programming for Engineers Laboratory] 2 [EEEE22IU41]


International University School of Electrical Engineering

for (int i = 0; i < 12; i++)


{
printf("Enter your number %d: ",i+1);
scanf(" %d",&number[i]);
}

for (int i = 0; i < 12; i++)


{
if (number[i]>0)
{
count_positive++;
}
else
{
count_negative++;
}
}
printf("Number of positive:%d\n",count_positive);
printf("Number of negatiqve:%d\n",count_negative);
return 0;
}

2.2 Experiment 2

For this exercise, we have to write a C program that reads two integers a and b. Check
if a <= b or not. If yes, prints all the even numbers from a to b and their sum. Otherwise,
prints “As a is greater than b so that we cannot calculate the sum.”

#include<stdio.h>
int main(){
printf("Le Nguyen Kha Ngan - EEEEIU23017\n");
int a;

[Programming for Engineers Laboratory] 3 [EEEE22IU41]


International University School of Electrical Engineering

printf("Enter a:");
scanf("%d",&a);
int b;
printf("Enter b:");
scanf("%d",&b);
int sum=0;
if (a<=b)
{
for (int i = a; i <= b; i++)

if (i%2==0)

{
printf("The even numbers in a and b: %d\n",i);

sum+=i;
}
printf("Sum of even numbers in a and b: %d\n",sum);

}
else
printf("As a is greater than b so that we cannot calculate the sum");

return 0;
}

2.3 Experiment 3

For this exercise, we have to write a C program that reads a character. The input
process continues when the character prompted is not a vowel (a,e,i,o,u). The program
should also count the number of valid inputs until a vowel is entered. Otherwise, prints “No
character was entered.”

[Programming for Engineers Laboratory] 4 [EEEE22IU41]


International University School of Electrical Engineering

#include<stdio.h>
int main(){
printf("Le Nguyen Kha Ngan - EEEEIU23017\n");
int input_numbers;
char character;

while (character!='a'&& character!='e'&& character!='i'&& character!='o'&& character!


='u')
{
printf("Enter a character: ");
scanf(" %c",&character);
input_numbers++;
}
printf("Number of inputs: %d",input_numbers-1);

2.4 Experiment 4

For this exercise, we have to write a C program that reads a student grade which is a
character. The program should print the classification based on the grade as:

Grade Classification

A Excellent

B Good

C Fair

D Average

F Weak

Other characters Invalid

[Programming for Engineers Laboratory] 5 [EEEE22IU41]


International University School of Electrical Engineering

At the end, the program should ask the user to continue to read another grade or not.
If yes, continues, otherwise, prints “Exit program...”.

#include<stdio.h>
int main(){
printf("Le Nguyen Kha Ngan - EEEEIU23017\n");
char grade;
char cont; //continue or not
do
{
printf("Enter your grade: ");
scanf(" %c",&grade);
switch (grade)
{
case 'A':
printf("Excellent\n");
break;
case 'B':
printf("Good\n");
break;
case 'C':
printf("Fair\n");
break;
case 'D':
printf("Average\n");
break;
case 'F':
printf("Weak\n");
break;
default:
printf("Your character is invalid");

[Programming for Engineers Laboratory] 6 [EEEE22IU41]


International University School of Electrical Engineering

break;
}
printf("Do you want to continue?\n");
printf("Enter your answer: ");
scanf(" %c",&cont);

} while (cont == 'y');

printf("Exit program...");

[Programming for Engineers Laboratory] 7 [EEEE22IU41]


International University School of Electrical Engineering

Experimental Results

In this section, describe the results. Remember to refer your reader to specific
Figures, Tables and Appendices where applicable and show your calculations and data
manipulation. Note that it is preferable to have Figures and Tables close to the text where
they are discussed. The goal here is to report the results – NOT to discuss whether they are
good or bad results. Usually the trends in a graph are pointed out, but not fully explained.
The discussion of the trend is saved for the Discussion section.

2.5 Experiment 1

Figure 1: Program C for exercise 1.

[Programming for Engineers Laboratory] 8 [EEEE22IU41]


International University School of Electrical Engineering

2.6 Experiment 2

Figure 2: Program C for exercise 2.

2.7 Experiment 3

Figure 3: Program C for exercise 3.

[Programming for Engineers Laboratory] 9 [EEEE22IU41]


International University School of Electrical Engineering

2.8 Experiment 4

Figure 4: Program C for exercise 4.

[Programming for Engineers Laboratory] 10 [EEEE22IU41]


International University School of Electrical Engineering

3 Discussion of Results

In the discussion, you should point out how your experimental results compare with
theory, and suggest and explain reasons for deviations. Discuss the sources of error in this
section.

[Programming for Engineers Laboratory] 11 [EEEE22IU41]

You might also like