1 / 11

Basic Input / Outputs

Chapter 5. Basic Input / Outputs. By: Mr. Baha Hanene. LEARNING OUTCOMES. This chapter will cover the learning outcome 02 i.e. 2. Use basic data-types and input / output in C programs (L02). CONTENTS. Formatted Inputs & Outputs Input Statement Combining Inputs & Outputs

lunea-clark
Download Presentation

Basic Input / Outputs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 5 Basic Input / Outputs By: Mr. BahaHanene

  2. LEARNING OUTCOMES • This chapter will cover the learning outcome 02 i.e. • 2. Use basic data-types and input / output in C programs (L02)

  3. CONTENTS • Formatted Inputs & Outputs • Input Statement • Combining Inputs & Outputs • Things to Remember • Exercise

  4. FORMATTED OUTPUT WITH Printf

  5. FORMATTED INPUT WITH Scanf

  6. SAMPLE PROGRAM FORMATTED OUTPUT

  7. HOW Scanf() WORKS • It’s looks like printf statement but different in nature!! • As printf is used to display the text & variable values stored in the memory locations. • Scanf is an input statement which is used to store values in different memory locations using variables • For example: • intst_code; • scanf(“ ”, ); What format specifier we use to display Integer values (%li, %f ???) %i The variable in which we want to store value is ?????? & st_code Address of Symbol

  8. MULTIPLE VARIABLES IN ONE Scanf • scanf(“%d %d”, &num1, &num2); • It means that it would stop here and wait for the user to type in two values. Once they have been typed in & the Enter Key pressed, the values are assigned to num1 & num2.

  9. COMBINING INPUT & OUTPUT STATEMENTS • printf(“Input Two Integer Values ”); • scanf(“%d %d”, &num1, &num2); • In the first place, there is a problem that how the user would come to know about the program is waiting for two values? The program should prompt user to enter two values. Now it will be easy for user to understand which type of values he suppose to enter

  10. THINGS TO REMEMBER • Make sure that the specifications agree with the data to be read. • Make sure to put the & character before the variable name so that you specify the address of the variable in memory not the variable itself. • The prompt message should be short and clear

  11. EXERCISE • Design a program to get three integers representing a date (date, month, year) from the user, display each of the day, month, year on the separate lines and then display the full date without spaces in the following form: day/month/year • Your output should be displayed on the screen using the following format: Please enter date (dd, mm, yyyy) : 15 10 2010 ----- DATE CONVERSION ----- Day = 15 Month = 10 Year = 2010 The today’s date is 15/10/2010.

More Related