ES 202 - Introduction to Computers and Programming in C
Dr. Kanta Prasad Sharma ( K P Sharma)
Associate Professor –CSE
Amity School of Engineering & Technology
Greater Noida Campus
+91 9760 207629
Faculty Profile
Greater Noida Campus Academic Highlights
Ph.D. – Information Technology
Industrial Training- UI Path Automation
Industrial Training – Global Logic – Full Stack
Books Published : 5
Experience
14 Years as academics &Innovative Research
Research Highlights
SCI :18 [ WOS -H Index :08] & WCIF – 01.02
Scopus : 42 [Scopus- H Index : 12]
Citations : 454 [ H- 11 & I- 13 ]
Dr. Kanta Prasad Sharma
Associate Professor (CSE) Research Gate : 9.9 [ H- 8]
Amity School of Engineering & Technology
Official : Faculty Cabin - 413 ( IV Floor,)
Amity University – G –Noida Campus Patents :15 [ Published :18 ,Grant:10]
+91 9760 20 7629 Members
MODULE - I
Greater Noida Campus
Outlines
• Introduction to Computer .
• History and types of computer
• Memory System
• H/W Concept – Input and Output Devices
• S/W Concept ( System , Application and Utility S/w )
• Data Representation – Number System, Character Representation code , binary , Octal, Hexadecimal code.
• Number system operations ( Binary Arithmetic, Floating point Arithmetic, Signed and Unsigned number)
• Memory Storage Unit
MODULE -II
Greater Noida Campus
Outlines ..
• Introduction & History of C Programming Language
• Concept of Variables and its Types
• Operators & types in C programming
• Expressions
• Managing input and outputs
• Formatting I/O
INTRODUCTION – C
Greater Noida Campus
C is a general-purpose programming language that has been widely used for over 50 years.
C is very powerful; it has been used to develop operating systems, databases, applications, etc.
C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
Why C?
• It is one of the most popular programming languages in the world.
• If you know C, you will have no problem learning other popular programming languages such as
Java, Python, C++, C#,
• C is very fast, compared to other programming languages, like Java and Python
• C is very versatile;
• it can be used in both applications and technologies
C - Compiler
Greater Noida Campus
Online Compiler : https://onecompiler.com/c
https://www.onlinegdb.com/
Offline Compiler
C Install IDE
IDE (Integrated Development Environment) used for compiled the code.
Download Process
http://www.codeblocks.org/. mingw-setup.exe
Let’s Work
Open Codeblocks and go to File > New > Empty File .
Write the following C code and save the file as Experiment1.c (File > Save File as)
Editor Environment
Greater Noida Campus
!"
Source Code Syntax
Greater Noida Campus
#include <stdio.h>
#include <stdio.h>
int main()
void main() {
{ printf(“Welcome in Amity University ");
printf(“Welcome in Amity University "); return 0;
} }
Line 1: #include <stdio.h> is a header file library that lets us work with input and output functions,
such as printf() (used in line 4)
Line 2: A blank line. C ignores white space. But we use it to make the code more readable.
Line 3: Another thing that always appear in a C program is main().
This is called a function. Any code inside its curly brackets {} will be executed.
Line 4: printf() is a function used to output/print text to the screen.
In our example, it will output :Welcome in Amity University
Comments in C
Greater Noida Campus
Single-line comments start with two forward slashes (//)
#include <stdio.h>
void main()
{
// The code below will print the words
printf(“Welcome in Amity University!");
}
Multi-line comments statement with /* and ends with */
#include <stdio.h>
int main()
{
/* The code below will print to the screen,
Amity University Welcome you */
printf("Hello Future Engineers!");
return 0;
}
Variable in C
Greater Noida Campus
Variables are containers for storing data values, like numbers and characters.
In C, there are different types of variables (defined with different keywords),
Basic Data Types
int - stores integers (whole numbers), without decimals, such as 123 or -123
float - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Characters are surrounded by single quotes
Syntax: type variableName = value;
Example : int myNum = 15;
Output Variable printf("Hello World!");
#include <stdio.h>
int main() {
int myNum = 15;
printf(myNum);
return 0;
}
Variables Name
Greater Noida Campus
• Names should be unique identifiers
• Names can contain letters, digits and underscores
• Names must begin with a letter or an underscore (_)
• Names are case-sensitive (myVar and myvar are different variables)
• Names cannot contain whitespaces or special characters like !, #, %, etc.
• Reserved words (such as int) cannot be used as names
Print Variable Value
Greater Noida Campus
int m = 15; int my = 15; // Integer (whole number)
printf("%d", m); float myF = 5.99; // Floating point number
char myL = 'D'; // Character
// Print variables
printf("%d\n", my);
Print value without variable printf("%f\n", myF);
#include <stdio.h> printf("%c\n", myL);
int main()
{ Da
ta M
printf("My favorite number is: %d\n", 15); Diff ay
ere be
printf("My favorite letter is: %c", 'D'); nt
return 0;
}
Change value & Add Variables
Greater Noida Campus
#include <stdio.h>
void main() #include <stdio.h>
{ int main()
int m = 15; {
m = 100; int x = 5;
printf("%d", myNum); int y = 6;
} int sum = x + y;
printf("%d", sum);
Check the code and find error & correct them return 0;
}
Multiple Variables
Greater Noida Campus
Example
Syntax #include <stdio.h>
int x = 5, y = 6, z = 50; void main()
printf("%d", x + y + z); {
int x = 5, y = 6, z = 50;
printf("%d", x + y + z);
}
Assignment 1
Write Program in C Language to display student’s details like Name, Course , Roll
no, Phone number, Grade , Year with proper flow chart.
Operators
Greater Noida Campus
• Operators are symbols, that represent operations.
• Performed on one or more operands
• Operators can be defined as basic symbols that help us work on logical and mathematical
operations.
Arithmetic Operators
Greater Noida Campus
Arithmetic Operators Examples
Greater Noida Campus
#include <stdio.h>
int main()
{
#include <stdio.h> int x = 5;
int main() int y = 2;
{ printf("%d", x % y);
int x = 5; return 0;
#include <stdio.h> printf("%d", --x); }
int main() return 0;
{ }
int x = 5;
printf("%d", ++x);
return 0;
}
Assignment Operators
Greater Noida Campus
Assignment operators are used to assign values to variables.
assignment operator (=) int x = 10 ( Assign Integer value 10 to variable [ x] ) Value
addition assignment operator (+=)
of
int x = 10; X ???
x += 5;.
#include <stdio.h>
void main()
{
int x = 10;
x += 5;
printf("%d", x);
}
Assignment Operators
Greater Noida Campus
= (Assignment)- Used to assign a value from right side operand to left side operand.
+= (Addition Assignment)- To store the sum of both the operands to the left side operand.
-= (Subtraction Assignment) – To store the difference of both the operands to the left side operand.
*= (Multiplication Assignment) – To store the product of both the operands to the left side
operand.
/= (Division Assignment) – To store the division of both the operands to the left side operand.
Assignment Operators
Greater Noida Campus
Give the Output of
following operators
Logical Operators
Greater Noida Campus
Logical operators are used to determine the logic between variables or values, by
combining multiple conditions.
&&
||
!
Logical Operators Example
Greater Noida Campus
#include <stdio.h>
#include <stdio.h> int main()
int main() {
{ int x = 5;
int x = 5; int y = 3;
int y = 3; printf("%d", x > 3 || x < 4);
printf("%d", x > 3 && x < 10); return 0;
return 0; }
}
#include <stdio.h>
Void main()
Out Put {
??? int x = 5;
int y = 3;
printf("%d", !(x > 3 && x < 10));
}
Comparison Operators
Greater Noida Campus
Comparison operators are used to compare two values (or variables).
Because it helps us to find answers and make decisions.
The return value of a comparison is either 1 or 0, which means true (1) or false (0)
Comparison Operators
Greater Noida Campus
Comparison Operators
Greater Noida Campus
#include <stdio.h>
void main() #include <stdio.h>
{ int main()
int x = 5; {
int y = 5; int x = 5;
printf("%d", x == y); int y = 3;
} printf("%d", x <= y);
return 0;
#include <stdio.h> }
void main()
{
int x = 5;
int y = 3;
printf("%d", x != y);
}
Miscellaneous Operators
Greater Noida Campus
sizeof – It returns the memory occupied by the particular data type of the operand.
& (Pointer) – It refers to the address (memory location) in which the operand is stored.
* (Pointer) – It is a pointer operator
? (Condition) – It is an alternative for if-else condition
Bitwise Operators
Greater Noida Campus
& (Bitwise AND) – Converts the value of both the operands into binary form and
performs AND operation bit by bit.
| (Bitwise OR) – Converts the value of both the operands into binary form and performs
OR operation bit by bit.
^ (Bitwise exclusive OR) – Converts the value of both the operands into binary form and
performs EXCLUSIVE OR operation bit by bit.
~ (One’s complement operator): Converts the operand into its complementary form.
<< – Left shift
>> – Right shift
Operator Precedence and Associativity
Greater Noida Campus
• The concept of operator precedence and associativity helps [in determining]
• which operators will be given priority.
• when there are multiple operators in the expression.
• It is very common for compiler [first evaluates the operator with higher precedence]
• It helps to maintain the ambiguity of the expression and helps to avoiding unnecessary use of
parenthesis.
Operator Precedence and Associativity
Greater Noida Campus
Operator Precedence and Associativity
Greater Noida Campus
Operator Precedence and Associativity
Greater Noida Campus
Operator Precedence and Associativity
Greater Noida Campus
Operator Precedence and Associativity
Greater Noida Campus
Formatting input/output
Greater Noida Campus
There are two kinds of console input/output functions -
Formatted input/output functions.
Unformatted input/output functions.
Unformatted input/output
Greater Noida Campus
Unformatted console input/output functions are used to read a input from the user at console
It also allows us to display the value in the output to the user at the console.
Assignment 2:
Explain the given functions of
Formatted and unformatted with
proper example
Unformatted input/output
Greater Noida Campus
Web Links
https://www.javatpoint.com/c-operators
https://data-flair.training/blogs/operators-in-c-and-cpp/
https://www.tutorialspoint.com/cprogramming/c_operators.htm
https://byjus.com/gate/operators-in-c/
Book Reference
Let US C Yashwant Kanitkar
Programming in C E Balagurusamy
Programmin in ANSI C Tata McGraw-Hill
Assessment Test
Greater Noida Campus
Quiz