Worksheet 4 Basic Input functions and Mathematical Operators

Similar documents
Engineering 12 - Spring, 1998

What we have learned so far

Unit 4. Input/Output Functions

Worksheet 11 Multi Dimensional Array and String

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Precedence and Associativity Table. % specifiers in ANSI C: String Control Codes:

Introduction to Computing Lecture 03: Basic input / output operations

EL2310 Scientific Programming

UNIT - V STRUCTURES AND UNIONS

Computers Programming Course 5. Iulian Năstac

More examples for Control statements

Faculty: Pushpendra K Rajput Session:

Overview (1A) Young Won Lim 9/14/17

Fundamentals of Programming

sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

Overview (1A) Young Won Lim 9/9/17

Subject: Fundamental of Computer Programming 2068

EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution

File IO and command line input CSE 2451

Overview (1A) Young Won Lim 9/25/17

ECET 264 C Programming Language with Applications

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

ONE DIMENSIONAL ARRAYS

Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II)

ECET 264 C Programming Language with Applications

Pointers and scanf() Steven R. Bagley

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Lecture 16. Daily Puzzle. Functions II they re back and they re not happy. If it is raining at midnight - will we have sunny weather in 72 hours?

Programming in C. Session 2. Seema Sirpal Delhi University Computer Centre

Informatica e Sistemi in Tempo Reale

Example: Structure, Union. Syntax. of Structure: struct book { char title[100]; char author[50] ]; float price; }; void main( )

BSM540 Basics of C Language

Multiple Choice Questions ( 1 mark)

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

Fundamentals of Programming Session 8

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

CCE RR REVISED & UN-REVISED KARNATAKA SECONDARY EDUCATION EXAMINATION BOARD, MALLESWARAM, BANGALORE G È.G È.G È..

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

Data types, variables, constants

b. array s first element address c. base address of an array d. all elements of an array e. both b and c 9. An array elements are always stored in a.

2. Numbers In, Numbers Out

The detail of sea.c [1] #include <stdio.h> The preprocessor inserts the header file stdio.h at the point.

upper and lower case English letters: A-Z and a-z digits: 0-9 common punctuation symbols special non-printing characters: e.g newline and space.

Introduction to Programming

This exam is to be taken by yourself with closed books, closed notes, no calculators.

Program Organization and Comments

The C Programming Language Part 2. (with material from Dr. Bin Ren, William & Mary Computer Science)

Section 1: C Programming Lab

UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:

Chapter 11 Introduction to Programming in C

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Friday, February 10, Lab Notes

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

Project 1: How to Make One Dollar

F28HS2 Hardware-Software Interface. Lecture 1: Programming in C 1

SU 2017 May 11/16 LAB 2: Character and integer literals, number systems, character arrays manipulation, relational operator

Fundamentals of Computer Science. Sentinel Based Repetition

EL2310 Scientific Programming

Problem # 1. calculate the grade. Allow a student the next grade if he/she needs only 0.5 marks to obtain the next grade. Use else-if construction.

Input/Output Week 5:Lesson 16.1

Online Judge and C. Roy Chan. January 12, Outline Information Online Judge Introduction to C. CSC2100B Data Structures Tutorial 1

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Visual Studio. Visual Studio is an extremely complex interactive development environment capable of handling many languages and tools.

Chapter 11 Introduction to Programming in C

Structure, Union. Ashishprajapati29.wordpress.com. 1 What is structure? How to declare a Structure? Explain with Example

Data Types. Data Types. Integer Types. Signed Integers

C programming basics T3-1 -

Structured programming

Lecture 3. Variables. Variables

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Organization of a file

Lecture 4. Console input/output operations. 1. I/O functions for characters 2. I/O functions for strings 3. I/O operations with data formatting

2. Numbers In, Numbers Out

Programming Language A

ECE 15 Fall 15 Final Solutions

WARM UP LESSONS BARE BASICS

CSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

Fundamentals of Programming

Fundamental of Programming (C)

Function a block of statements grouped together, to perform some specific task

Decision Making. if Statement. Decision Making

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Unit 8. Structures and Unions. School of Science and Technology INTRODUCTION

Programming Language B

IV Unit Second Part STRUCTURES

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT. Dept. of Electronic Engineering, NCHU. Original slides are from

Q1: C input/output; operators / 46 Q2: Conditional statements / 34 Q3: While and do-while loops / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10

Chapter 11 Introduction to Programming in C

Midterm Exam. CSCI 2132: Software Development. March 4, Marks. Question 1 (10) Question 2 (10) Question 3 (10) Question 4 (10) Question 5 (5)

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

CSE 1320 INTERMEDIATE PROGRAMMING - OVERVIEW AND DATA TYPES

for (i=0 ; i<100 ; i++){ do_sum_stuff(); i = i-1; } i=2; while (i>1) { do_something(); }

UNIT 3 OPERATORS. [Marks- 12]

CSE 351. Introduction & Course Tools

COMP s1 Lecture 1

Transcription:

Name: Student ID: Date: Worksheet 4 Basic Input functions and Mathematical Operators Objectives After completing this worksheet, you should be able to Use an input function in C Declare variables with suitable data types Understand the conversion specifications in an input function 1. Open a new project and write Program 4.1, then run it. int main(int argc, char *argv[]) { int x; float y; double z; printf( Please enter an integer value : ); scanf( %d,&x); printf( Please enter a float value : ); scanf( %f,&y); printf( Please enter a double value : ); scanf( %lf,&z); printf( \n\n ); // Wait for an integer value from a user // Wait for a floating point value from a user // Wait for a double precision floating point value the letter l (L) printf( Your integer value is %d \n,x); printf( Your float value is %f \n,y); printf( Your double value is %f \n,z); Program 4.1

Enter the following values to the program Please enter an integer value : 365 Please enter a float value : 99.12 Please enter a double precision value : 34567890.75 Record the result produced by the program Entered by a user 2. Open a new project and write program 4.2. int main(int argc, char *argv[]) { //To enter values to the program, users have to add int a, b; //a space between two input values Ex. Enter 2 integer values : 32 94 printf("enter 2 integer values : "); scanf("%2d %4d",&a,&b); printf("a = %d b = %d",a,b); // Add one space (press the key spacebar) Program 4.2 3. Run the program 4.2 and input to the program the values in Table 4.1 and then record the result. Input values 32 94 32 12345 345 12345 Results a = b = Table 4.1

4. Open a new project, write program 4.3 and run it. int main(int argc, char *argv[]) { int hour, min, sec; printf( Please enter time in hh:mm:ss : ); scanf( %d:%d:%d,&hour,&min,&sec); //To enter input data to the program, users printf( Current time : %02d:%02d:%02d,hour,min,sec); Program 4.3 Input the numbers 1:30:08 to the program. Please enter string: 1:30:08 press Enter Record the result.. 5. Open a new project, write program 4.4 and run it. int main(int argc, char *argv[]) { char ch; printf( Please enter one character : ); ch = getchar(); printf( \nch = %c\n,ch); ---------------- //getchar() is defined in the library stdio.h -------------- Program 4.4 ------------------ 6. Enter the characters in Table 4.2 into the program and record the result in Table 4.2. 7. From program 4.4, modify the statement and rerun it. ch = getchar(); ch = getche(); Enter the characters in Table 4.2 into the program and record the result in Table 4.2. 8. From program 4.4, modify the statement and rerun it. ch = getchar(); ch = getch(); Enter the characters in Table 4.2 into the program and record the result in Table 4.2.

Input Results from 6-8 Characters step 6. step 7. step 8. A a H + 1 Key Esc Table 4.2 9. What is the difference among these three functions: getchar(), getche() and getch()? 10. Open a new editor and write Program 4.5, then run it. Record the result in Table 4.3. int main(int argc, char *argv[]) { int a, b; float c, d; a = 35; b = 12; c = 185.73; d = 94.781; printf("a + b = %d\n",a+b); printf("a - b = %d\n",a-b); printf("a * b = %d\n",a*b); printf("a / b = %d\n",a/b); /* an integer value /an integer value produces an integer value */ printf("a % b = %d\n",a%b); printf("c + d = %f\n",c+d); printf("c - d = %f\n",c-d); printf("c * d = %f\n",c*d); printf("c / d = %f\n",c/d); /* a floating point /a floating point value produces a floating point value */ printf("a + c = %f\n",a+c); printf("c / b = %f\n",c/b); /* a floating point value /an integer value, and vice versa, produces */ // a floating point value Program 4.5

Expressions a + b a - b a * b a / b a % b c + d c - d c * d c / d a + c c / b Results a = 35, b = 12, c = 185.73, d = 94.781 Table 4.3 11. Open a new project and write program 4.6. int main(int argc, char *argv[] ) { float Area, Height, Base; Height = 5.5; Base = 10.0; Area = (1/2) * Height * Base; printf( Area of Triangle = %f,area); ---------------------------- Program 4.6

12. Run the program 4.6 and record the results. Area of Triangle =... Is the result correct? How can we correct the result? 13. Fill in the blanks with the correct answer. 25 / 6 = 25 / 6.0 = 3 / 12 = 15 % 5 = 8 % 12 =

Name: Student ID: Homework 4 1. Write a program in C that receives the information of three employees from the keyboard. The information of each employee is composed of gender (m or f), age, salary and telephone number. Then display the information of three employees on the screen in appropriate form.

2. Given a set of mathematical expressions below, 2.1 (( x * y) 3) (7 z), 2.2 3x 2 2y 7z, Write a program that accepts the values of variables x, y and z (as input variables) from the keyboard. Then calculate the expressions above by using these input variables. (Given that all of the variables used in this program are floating point variables).