Lecture 2
Lecture 2
E-mail: [email protected]
Lecture 2
Standard Input – Output Functions
2. Input function : Receive the inputs from the keyboard
Scanf (“ %Data_type”, & variable);
Integer %d
Float %f
Character %c
Example: read an integer number and store in a variable called “num”
scanf(“%d”, &num);
Example: read two float numbers and store them in “num1” and “num2”
scanf(“%f %f”, &num1, &num2);
Example: read three characters and store them in “let1” , “let2” and “let3”
scanf(“%c %c %c”, &let1, &let2, &let3);
Example 1: Write a program to read two integer numbers and print
their summation and average.
#include<stdio.h>
void main()
{
int num1,num2,sum;
float aver;
scanf(“%d %d”, &num1,&num2);
sum=num1+num2;
aver=(num1+num2)/2;
printf(“The summation =%d, and the average=%f”,sum,aver);
}
Types of operators
1. Arithmetic Operators
2. Increment & Decrement
3. Assignment Operators
4. Relational Operators
5. Logical Operators
6. Bitwise Operators
4
1. Arithmetic Operators
5
6
2. Increment & Decrement Operators
7
8
3. Assignment Operators
9
10
4. Relational Operators
11
12
13
5. Logical Operators
15
6. Bitwise Operators
17
18