0% found this document useful (0 votes)
338 views

Lab 2

This document provides instructions for several input/output exercises in C programming. It asks the student to write programs that print text and variables to the screen. It also explains the purpose of escape characters like \n and how to format output using printf formatting specifiers like %s and %d. The homework assignment is to write a program that gets user input for an ID, gender, and temperature and displays the values in a single printf statement.

Uploaded by

mohammad
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
338 views

Lab 2

This document provides instructions for several input/output exercises in C programming. It asks the student to write programs that print text and variables to the screen. It also explains the purpose of escape characters like \n and how to format output using printf formatting specifiers like %s and %d. The homework assignment is to write a program that gets user input for an ID, gender, and temperature and displays the values in a single printf statement.

Uploaded by

mohammad
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

 

9 Input / Output Functions


 Lab Sheet:  

1. Write the keyboard commands to do the following:


Save  ___________                    Run  ___________         Compile Only  ___________ 
Execute Compiled Program  ___________ 
 
2. Type the following program carefully including spaces. Compile, run and save as:
hello.c

1. #include <stdio.h>
2.
3. int main(void)
4. {
5. printf("Hello World!");
6. return(0);
7. }

3. Delete line 5. Compile and run.


Write the error message? What does it mean? 
Error message:  ______________________________________________________ 
Meaning: ___________________________________________________________ 
 
4. Correct the program. Compile and run to check.
 
5. Delete line 4. Compile and run.
Write the error message? What does it mean? 
Error message:  ______________________________________________________ 
Meaning: ___________________________________________________________ 
 
6. Correct the program. Compile and run to check.
 
7. Change line 5 as follows. Compile and run.
5. printf("%d", 12+8);

8. Change line 6 as follows. Compile and run.


5. printf("12+8");

9. What is the different between the questions 7 and 8 ?

 
CPCS202 ‐ The Lab Note Lab 1
 
10 Input / Output Functions
 
10. Type the following program carefully including spaces. Compile, run and save as:
hello2.c

1. #include <stdio.h>
2.
3. int main(void)
4. {
5. printf("Hello World!\n");
6. printf("Fine thank you.");
7. return(0);
8. }

11. Remove the operator from line 5. Compile and run.


What does \n do? _____________________________________________________ 
 
12. Change line 5 as follows. Compile and run.
5. printf("Hello World!\n\n\n");

13. Change line 5 as follows. Compile and run.


5. printf("%s\n\n\n", "Hello World!");

 Homework:
1. Write a program that gets the ID (as integer), gender (as character), and  
temperature (as double) from the user. Then, display the values of the three 
variables using one printf statement? 
 
Hints:
1. Save your homework in your USB flash memory. 
2. Write your name & your ID number in the first line in your HW file. 
3. Take a copy from your output window by clicking Alt + Print Screen and paste it in 
your HW file in the same page. 

CPCS202 ‐ The Lab Note Lab 1

You might also like