Beruflich Dokumente
Kultur Dokumente
(CSE – 101N)
Unit 2
Overview of C: Elements of C, Data types; Storage classes in C;
Operators: Arithmetic, relational, logical, bitwise, unary, assignment
and conditional operators, precedence & associativity of operators.
By
Ashish Shrivastava
Assistant Professor
Computer Science and Engineering
PIET
Different Types of Software's in a Computer
There are two things every computer has in common: software and
hardware.
Computer software consists of one or more computer programs
which tell the computer what to do. It can be described as a set of
instructions and data that are stored inside the memory to enable it to
perform different functions.
2
Different Types of Software's in a Computer
Application Software
Database
Word processor
Paint
System Software
Games Operating system Tools & Utility
Hardware
Skype
Language Compiler like C, C++, Java
Calculator
4
Different Types of Software's in a Computer
There are two main types of computer software: System software and
Application software.
6
Different Types of Software's in a Computer
System software
8
Different Types of Software's in a Computer
Application Software
9
Different Types of Software's in a Computer
Application Software
10
What is C ?
11
What is C ?
12
What is C ?
Database systems
Graphics packages
Word processors
Spreadsheets
Operating system development
Compilers and Assemblers
Network drivers
Interpreters
Satellite programming
13
What is C ?
14
What is C ?
15
Execution of a C Program
Here is a simple table showing input and output of each step in the
compilation and execution process:
Input Program Output
17
Basic C Program
1. #include <stdio.h>
2. #include<conio.h>
3. void main()
4. {
5. clrscr();
6. /* Our first simple C basic program */
7. printf(“Hello World! “);
8. getch();
9. return 0;
10. }
18
Basic C Program
Sn Command Description
20
Variables and Data Types
21
Variables and Data Types
S.no Types Data Types
22
Variables and Data Types
Modifiers in C
The amount of memory space to be allocated for a variable is
derived by modifiers.
Modifiers are sufixed with basic data types to modify (either
increase or decrease) the amount of storage space allocated to a
variable.
For example, storage space for int data type is 2 byte. We can
increase the range by using long int which is 4 byte.
There are 4 modifiers available in C language. They are,
short
long
signed
unsigned
23
Variables and Data Types
S.N C Data types storage Size Range
8*8 8*8
4 double 8 -2 to (2 - 1)
5 long double 10
6 long int 4
24
Variables and Data Types
S.N C Data types storage Size Range
8 unsigned 2 0 to 65,535
short int
9 signed short 2 –32,768 to 32,767
int
10 long int 4
25
1. #include<stdio.h> a b
2. #include<conio.h> c d
3. void main()
4. { variables in RAM
5. clrscr();
6. int a; float b; char c; double d; long int e; long float f;
26
1. #include<stdio.h>
2. #include<conio.h>
3. void main()
4. {
5. clrscr();
6. int a,b,c; a b c
7. a=5; b=7; a 5 b 7 c 12
8. c=a+b;
9. printf(“\n Sum is =%d”, c);
10. getch();
11. }
27
printf() and scanf() library functions
28
printf() and scanf() library functions
printf()
29
printf() and scanf() library functions
printf()
Format specifiers in printf() and scanf()
%d got replaced by value of an integer variable
%c got replaced by value of a character variable
%f got replaced by value of a float variable
%lf got replaced by value of a double variable
%s got replaced by value of a string variable
%o got replaced by a octal value corresponding to integer variable
%x got replaced by a hexadecimal value corresponding to integer
variable
\n got replaced by a newline.
30
printf() and scanf() library functions
printf()
1) #include <stdio.h>
2) #include<conio.h>
3) void main()
4) {
5) clrscr();
6) char ch = ‘A’;
7) float flt = 10.234;
8) int num = 150;
9) double dbl = 20.123456;
10) printf(“Character is %c \n”, ch);
11) printf(“Float value is %f \n”, flt);
12) printf(“Integer value is %d\n” , num);
13) printf(“Double value is %lf \n”, dbl);
14) printf(“%lf %c %d %f”, dbl, ch, num, flt);
15) getch();
16) } 31
printf() and scanf() library functions
printf()
32
printf() and scanf() library functions
scanf()
Variable
Data
Keyboard scanf()
33
printf() and scanf() library functions
scanf()
1) #include <stdio.h>
num
2) #include<conio.h>
3) int main()
format specifier
4) {
address of operator
5) clrscr();
6) int num;
7) printf(“Enter any number\n”);
8) scanf(“%d”, &num);
9) printf(“Entered number is %d \n”, num);
10) getch();
variable
11) }
34
printf() and scanf() library functions
scanf()
Write a program to add two numbers, get numbers from user
through keyboard
1) #include <stdio.h>
2) #include<conio.h>
3) int main()
4) {
5) clrscr();
6) int num1, num2, num3;
7) printf(“Enter first number\n”);
8) scanf(“%d”, &num1);
continue
35
printf() and scanf() library functions
scanf()
9) printf(“Enter second number\n”);
10) scanf(“%d”, &num2);
11) num3=num1+num2;
12) printf(“Sum is = %d”, num3);
13) getch();
14) }
36
printf() and scanf() library functions
printf() and scanf()
1. Write a program to print square and cube of a number, get
the number from keyboard.
2. Write a program to addition, subtraction, multiplication, and
division of two integer numbers. get the numbers from
keyboard
3. Write a program to implement
(A+B) *(C-D)
X=----------------------
(A+(B/D))
where the values of A, B, C, and D are taken through
keyboard.
4. Write a program to find sum of series of four numbers, get
numbers from keyboard.
(num1*num2) + (num2*num3) + (num3*num4)
Sum= ----------------- ------------------ -------------------
num4 num3 (num1+num2)
37