Reading the data from the input devices and displaying the results on the screen are the two main tasks of any program. To perform these tasks user friendly.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

Computer Programming w/ Eng. Applications
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Lecture 2 Introduction to C Programming
Introduction to C Programming
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Functions Definition: Instruction block called by name Good design: Each function should perform one task and do it well Functions are the basic building.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Basic Input/Output and Variables Ethan Cerami New York
Introduction to C language
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
1 CSC103: Introduction to Computer and Programming Lecture No 30.
Copyrights© 2008 BVU Amplify DITM Software Engineering & Case Tools Page:1 INTRODUCTION TO ‘C’ LANGUAGE Chapter 2.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Computer Science 210 Computer Organization Introduction to C.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Yu Yuanming CSCI2100B Data Structures Tutorial 3
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
C Programming Lecture 10 Instructor: Wen, Chih-Yu Department of Electrical Engineering National Chung Hsing University.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
C Programming Lecture 5 : Basic standard I/O Lecture notes : courtesy of Ohio Supercomputing Center, science and technolgy support.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
Programming, an introduction to Pascal
CECS 130 EXAM 1. To declare a constant (read only) value: const int x = 20; const float PI = 3.14; Can we do this? const int x;
Khalid Rasheed Shaikh Computer Programming Theory 1.
Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
Computer Programming for Engineers
1 TOPICS TO DISCUSS : FUNCTIONS TYPES OF FUNCTIONS HEADER FILES PRESENTED BY : AVISHEK MAJUMDAR(837837) GUNJAN AGARWAL(856587) SATYAPRIYA DEY(856624)
1 Arrays and Pointers The name of an array is a pointer constant to the first element. Because the array’s name is a pointer constant, its value cannot.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Lecture2.
Computer Science 210 Computer Organization
Zhang Hongyi CSCI2100B Data Structures Tutorial 3
INC 161 , CPE 100 Computer Programming
Programming Fundamental
INTRODUCTION Every language has some features that provides interaction between the program and the user of the program. C language uses the reference.
Unit-4, Chapter-2 Managing Input and Output Operations
FUNCTIONS.
Visit for more Learning Resources
Formatted and Unformatted Input/Output Functions
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Computer Science 210 Computer Organization
توابع ورودي-خروجي.
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Lecture3.
In C Programming Language
C – Programming Language
DATA TYPES There are four basic data types associated with variables:
Course Outcomes of Programming In C (PIC) (17212, C203):
Introduction to C Programming
Presentation transcript:

Reading the data from the input devices and displaying the results on the screen are the two main tasks of any program. To perform these tasks user friendly C has a number of input/Output functions. When a program needs data, it takes the data through the input functions and sends results obtained through the output functions. Thus the input/output functions are link between the user and the terminal. There are numbers of I/O function in C based on the data types. They are classified in to two types. Formatted Function Unformatted Function 1Basic of Computer & 'C' Programming

Formatted Functions :- The formatted input/output functions read and write all types of data values. They require conversion symbol to identify the data type. Hence, they can be used for both reading and writing of all data values. The formatted functions return the values after execution. The return value is equal to the number of variables successfully read/written. Using this value the user can find out the errors occurring during reading the data. 2Basic of Computer & 'C' Programming

Unformatted Functions :- The unformatted input/output functions only work with the character data types. They do not require conversion symbol for identification of data types because they work only with character data type. There is no need to convert the data. In case values of other data types are passed to these function, they are treated as the character data. The unformatted functions also return values, but return value of unformatted function is always the same. 3Basic of Computer & 'C' Programming

FormattedUnformatted Input Output scanf() printf()getch() putch() getchar() puts() gets() getche() putchar() 4Basic of Computer & 'C' Programming

The printf() statements:- The printf() function prints all types of data values to the console. It requires conversion symbol and variable names should be same in number. The scanf() statements:- The scanf() statements reads all types of data values. It is used for runtime assignments of variable. The scanf() statements also requires conversion symbol of the program. Syntax of scanf(“%d %f %c”,&a,&b,&c); 5Basic of Computer & 'C' Programming

6

7

Unformatted Function:- Character I/O String I/O Files I/O 1. Character I/O:- a) getchar():- This function reads character types data from the standard input. It reads one character at a time till the user presses the enter key. b) putchar():- This function prints one character on the screen at a time which is read by the standard input. c) getch() & getche():- These function read any alphanumeric characters from the standard input device. The character entered is not displayed by getch() function. d) putch():- This function prints any alphanumeric character taken by the standard input device. 8Basic of Computer & 'C' Programming

2.String I/O:- a) gets():- This function is used for accepting any string through stdin(keyboard) until enter key is pressed. The header file stdio.h is needed for implementing the above function. b) puts():- This function prints the strings or character array. c) cgets():- This function reads string from the console. Syntax: cgets (char *st); d) cputs():- This function display string on the console. Syntax: cputs (char *st); 9Basic of Computer & 'C' Programming

Commonly used Library Functions:- a) clrscr():- This function is used to clear the screen. It cleans the previous output from the screen and display the output of the current program from the first line of the screen. It is defined in conio.h header file. Syntax: clrscr(); b) exit():- This function terminates the program. It is defined in process.h header file. Syntax:- exit(); c) sleep():- This function pauses the execution of the program for a given number of seconds. The number of seconds is to be enclosed between the parenthesis. It is defined in dos.h header file. Syntax:- sleep (1); d) system():- This function is helpful in executing the different dos commands. It return 0 on success and -1 on failure. Syntax:- system (“dir”); This command should be enclosed within the double quotation mar ks. 10Basic of Computer & 'C' Programming

Programs: Q. WAP to add Two No. #include void main(); { int a,b,c; printf(“Enter Two No”); scanf(“%d %d”, &a,&b); c=a+b; printf(“Sum =%d”, c); } 11Basic of Computer & 'C' Programming

Q. WAP to Subtract Two No. #include void main(); { int a,b,c; printf(“Enter Two No”); scanf(“%d %d”, &a,&b); c=a-b; printf(“Subtraction =%d”, c); } Q. WAP to Multiply Two No. #include void main(); { int a,b,c; printf(“Enter Two No”); scanf(“%d %d”, &a,&b); c=a*b; printf(“Multiply =%d”, c); } 12Basic of Computer & 'C' Programming

Q. WAP to Divide Two No. #include void main(); { int a,b,c; printf(“Enter Two No”); scanf(“%d %d”, &a,&b); c=a/b; printf(“Divide =%d”, c); } Q. WAP to Print Square of a Given No. #include void main(); { int a,c; printf(“Enter Any No”); scanf(“%d”, &a); c=a*a; printf(“Square of Given No =%d”, c);} 13Basic of Computer & 'C' Programming

Q. WAP to swap the values of two variable without using third variable. #include void main(); { int a=10,b=20; printf(“A=%d B=%d”,a,b); a=a + b; b=a - b; a=a - b; printf(“Now A=%d B =%d”,a,b); } 14Basic of Computer & 'C' Programming

Q. WAP to calculate average of Three real Nos. #include void main() { float a,b,c,d; printf(“Enter Three Float Nos”); scanf(“%f%f%f”,&a,&b,&c); d=a+b+c; printf(“ Average of Given No =%f,d/3); } 15Basic of Computer & 'C' Programming

Thanks 16Basic of Computer & 'C' Programming