Problem Solving
Problem Solving
SOLVING USING C
Expansion of computer
C - Common
O - Operating
M - Machine
P - Purposely
U - Used for
T -Technological and
E - Educational
R -Research
Father of Computer
History of Computers
❑ Can do X, /, +, -
❑ Can do X, /, +, -
Difference Engine
❑ Was invented in 1842 by Charles
Babbage
Analytical Engine
❑ Charles Babbage began working on it
in 1848
❑ This was the worlds first truly
programmable device, and therefore the
• English Mathematician
• Logician
• Cryptanalyst and
• Computer Scientist
• Father of Computer Science and Artificial
Intelligence
Turing machine
• ADA
Types of Computer
Components of Computer
System
Organization of Computer
Computer organization consist of following parts
CPU – central processing unit
Memory
Input devices
Output devices
Central processing unit
• Alternatively referred to as the brain of the computer,
processor, central processor,or microprocessor,
the CPU
• first developed at Intel in the early 1970’s
• The computer CPU is responsible for handling all
instructions it receives from hardware and software
running on the computer
• CPU performs all types of data processing
operations.
• It stores data, intermediate results and instructions
• It controls the operation of all parts of computer
CPU itself has following three components
1. ALU (Arithmetic Logic Unit)
All arithmetic calculations and logical operation are
performed using the Arithmetic/Logical Unit or ALU
2. Memory Unit
• A memory is just like a human brain.
• It is used to store data and instruction Computer
memory is use to Stores information being processed by
the CPU
3. Control Unit
unit help to perform operations of input unit, output
unit, Memory unit and ALU in a sequence.
Input Devices
• A device that can be used to insert data into a
computer system is called as input device.
• Examples : Keyboards, mouse, scanners and digital
cameras
Output Devices
• A device which is used to display result from a
computer is called as output device
• Examples: Printer, Scanner, Monitor, etc.
Examples of software and Hardware
Hardware Software
Hardware is further divided into Software is further divided into
four main categories: two main categories:
• Input Devices • Application Software
• Output Devices • System Software
• Secondary Storage Devices
• CPU
Developed using electronic and Developed by using a
other materials programming language
When damaged, it can be When damaged it can be installed
replaced with a new component once more using a backup copy
Hardware is physical in nature The software cannot be physically
and hence one can touch and see touched but still can be used and
hardware seen
Hardware cannot be infected by The software can be infected by
Viruses Viruses
Types of Computer Language
• Computer language is defined as code or syntax which is
used to write programs or any specific applications
• The computer language is used to communicate with
computers
• Three categories assembly language, machine language,
and high-level language
1. Machine Language
• The Machine language is considered a low-level language
• Other name -machine code or object code
• Which is set of binary digits 0 and 1
• These binary digits are understood and read by a computer system
• Example of machine language for the text “Hello World”.
01001000 0110101 01101100 01101100 01101111 00100000
01010111 01101111 01110010 01101100 01100100
2. Assembly Language
• Intermediate-level language for microprocessors
• It is second-generation language
3. High-Level Language
• The high-level language is easy to understand and
• human-readable program
• Examples: C++, C, JAVA, FORTRAN, etc..
Computer – Software
➢ Software is a set of programs,
which is designed to perform a
well-defined function.
➢ A program is a sequence of
instructions written to solve a
particular problem.
There are two types of software
• System Software
• Application Software
System Software
• The system software is a collection of programs
• designed to operate, control, and supports the process
of computer
• System software –Inbuilt in System
• System software written in low-level languages
• Use to Interact with the hardware and software
• It Serves as the interface between the hardware and
end users
• Examples: Operating System, Compilers, Interpreter,
Assemblers, etc..
System Software
Some examples of system software are Operating
• Fast in speed
• Difficult to design
• Difficult to understand
• Less interactive
• Smaller in size
• Difficult to manipulate
following −
• Payroll Software
• Microsoft Word
• Microsoft Excel
• Microsoft PowerPoint
Key System Software Application Software
Definition System Software is the Application Software is the
type of software which is type of software which runs
the interface between as per user request. It runs
application software and on the platform which is
system provide by system software
Developme low level language high level language
nt Language
Usage System software is used Application software is used
for operating computer by user to perform specific
hardware task
Installation Installed on the computer Application software are
when operating system is installed according to user’s
installed requirements
Dependenc System software can run Application software can’t
y independently, It provides run independently. They
platform for running can’t run without the
Program Design Tools
• Program Design tools are the tools used to
develop a program. A program is the expression of
an algorithm in a programming language.
01 Algorithms
02 Flowcharts
03 Pseudo codes
Algorithm
An algorithm in general is a sequence of steps to
solve a particular problem. Algorithms are
universal.
1. Preprocessor
2. Compiler
3. Assembler
4. Linker
Compilation process in c
Compilation process in c
Preprocessor
• The source code is the code which is written
in a text editor and the source code file is
given an extension ".c".
hello.c
#include <stdio.h>
int main()
printf("Hello javaTpoint");
return 0;
}
Compilation process in c
Structure of c program
A C program involves the following sections:
• Local Declarations
#include<stdio.h>
Void main()
printf("Hello, World!\n");
}
/* Comments */ - Comments are a way of explaining what
makes a program. The compiler ignores comments and
used by others to understand the code.
main function.
statements.
• Alt + F9 – Compile
• For example:
• 1. int money;
• 2. double accountBalance;
type variable_list;
• int a;
• float b;
• char c;
Variables in C
• Here, a, b, c are variables. The int, float, char are
the data types.
• float f=20.8;
• char c='A';
Variables in C
Rules for defining variables
program, for example: 10, 20, 'a', 3.4, "c programming" etc.
Syntax:
Example
#define LENGTH 10
#define WIDTH 5
Using const keyword.
Syntax:
const type var
const int LENGTH = 10;
const int WIDTH = 5;
Data Types in C
A data type specifies the type of data that
a variable can store such as integer,
floating, character
Data Types in C
EXAMPLE:
#include <stdio.h>
int main()
{
// Displays the string inside quotations
printf("C Programming");
return 0;
}
Output statement in C
➢ printf() function to display output to the user
• Output:Number = 5
• We use %d format specifier to print int types.
• Here, the %d inside the quotations will be
replaced by the value of testInteger
Example 3: float and double Output
#include <stdio.h>
void main()
{
float number1 = 13.5;
double number2 = 12.4;
printf("number1 = %f\n", number1);
printf("number2 = %lf", number2);
}
Print Characters
#include <stdio.h>
void main()
{
char chr = 'a';
printf("character = %c", chr);
}
Output
character = a
To print char, we use %c format specifier
INPUT OUTPUT (I/O) STATEMENTS
➢ scanf() function - to take input from the user,
Syntax: scanf(“%X”, &variableOfXType);
where %X is the format specifier in c
& is the address operator in C.
EXAMPLE:
#include <stdio.h>
void main()
{
int a;
// Displays the string inside quotations
printf("C Programming");
//getting input from the user
scanf(“%d”,&a);
printf(“Given data is %d”,a);
}
C Input
• In C programming, scanf() is one of the commonly used function to take
input from the user.
• The scanf() function reads formatted input from the standard input
such as keyboard
Integer Input/Output
#include <stdio.h>
void main()
{
int testInteger;
printf("Enter an integer: ");
scanf("%d", &testInteger);
printf("Number = %d“,testInteger);
}
Output
Enter an integer: 4
Number = 4
C Input
• Here, we have used %d format specifier inside the
scanf() function to take intinput from the user.
When the user enters an integer, it is stored in the
testInteger variable.
Output:
1. Thus, in the above example we find that the output result is
12 because in the result expression the user has explicitly
defined the operands (variables) as integer data type.
2. Hence, there is no implicit conversion of data type by the
compiler.If in case implicit conversion was used the result
would be 13.
C - Type Casting
• (type_name) expression
Example:
#include <stdio.h>
main() {
int sum = 17, count = 5;
double mean;
mean = (double) sum / count;
printf("Value of mean : %f\n", mean );
}
• When the above code is compiled and
executed, it produces the following result
• Value of mean : 3.400000
Integer Promotion
Integer promotion is the process by which values of integer
type "smaller" than int or unsigned int are converted either
to int or unsigned int.
#include <stdio.h>
main() {
int i = 17;
char c = 'c'; /* ascii value is 99 */
int sum;
sum = i + c;
printf("Value of sum : %d\n", sum );
}