0% found this document useful (0 votes)
46 views17 pages

Logic Building With Computer Science

Uploaded by

ansh09119
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views17 pages

Logic Building With Computer Science

Uploaded by

ansh09119
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Logic Building with Computer Science

Lecture 1
Q. Programming & Coding Difference

• Coding- Coding involves translating natural language to computer script while


programming entails building an intricate sequence between system
• Coding is the act of translating instructions for a computer from human language to
machine language.
• This code tells the computer how to behave & what action to perform.
• The programming is the process of creating the instructions that will tell the computer
how to perform a particular task given to it.
• Coding aims to provide communication between human & computer programming
involves creating an outline & structure for the programs code that follows certain
standard.
• For coding we use text editors, e.g.: Notepad, VS code, atoms.
• As a programmer we perform document reviews a lot of perform, lot of planning,
thinking about design to perform such task program required advanced code editor,
analyses tool, debugger, modelling framework, assemblers, modelling Algorithms.

Q. Level of knowledge of programmer & programming?

• Coder:
To become a coder, you need a basic knowledge of programming language & its syntax.

To have a good skill to learn & read a code.

To develop a skill to write an actual code but if you want to become a programmer, you
need to learn higher level language.

As a programmer to know learn to create & work with Algorthims.

Have knowledge to design a website you should have a good knowledge how to debug &
your code.

Good knowledge to implement, manage the project.

IInd Phase:
Computing & Computer:

Calculator – Single purpose desire performs authentic operation in a duration.

Computer – Desire that is have vastly expanded capabilities, General Purpose


Computing Device, Computer is a Huge electrical circuit.
Lecture 2

Q. what is a computer

• It is a huge electrical circuit


• We feed Data to it
• Data can be accepted from External World, and it is possible to remember the things
• We can process the feed data
• We can return the result to external world

Q. What do you mean by DATA?

• It is raw facts and figures.


• We collect the data and then we process the data for the output as per our needs.

Q. What is a program.

• A program is a set of instructions


• The precise Description of steps that perform on Data.

Q. How will you make the Triangle?

• Forward (30)
• Left (120)
• Forward (30)
• Left (120)
• Forward (30)
• Wait (T)

Q. How will you make the Hexagon?

• Forward (90)
• Right (60)
• Forward (90)
• Right (60)
• Forward (90)
• Right (60)
• Forward (90)
• Right (60)
• Forward (90)
• Right (60)
• Forward (90)

Q. How will you make the decagon?

• Forward (90)
• Right (36)
• Forward (90)
• Right (36)
• Forward (90)
• Right (36)
• Forward (90)
• Right (36)
• Forward (90)
• Right (36)
• Forward (90)
• Right (36)
• Forward (90)
• Right (36)
• Forward (90)
• Right (36)
• Forward (90)
• Right (36)
• Forward (90)

Q. How about a picture that looks like a circle?

• Repeat (360)
• Forward (1)
• Right (1)

Lecture 3

Q. The Computing Machine

• A computer is made up of a processor and a memory


• The Memory can be thought of as a series of locations to store information.
• A program is a sequence of instructions assembled for some given task
• Most instructions operate on data.
• Some instructions control the flow the operations.

➢ Von Neuman Architecture (A brief look in the history)


Input Devices (data) >> Central Processing Unit (main/internal memory) >> (data)
Output Devices

o From Abacus to Apple


▪ Counting frame.
▪ One of the earliest forms of calculator
▪ Still used by kids to d fast simple arithmetic.
▪ Followed by mechanical calculators by B. Pascal (1642),
G.W. Leibniz (1671).
✓ Used cogs / interlocking gears
✓ Performed +, -, %, * and root.
✓ Leibniz is credited of creating the binary system.
o Jaquard Looms (1804)
o Charles Babbage (1791-1871)
▪ Regarded as the “Father of Computer”
▪ Conceived of a machine that has all parts of a Morden computer,
input, a memory, a processor and an output (1850).
o Difference Engine (1850)
▪ Difference Engine built from Babbage’s design (London Science
Museum)
o Ada Lovlace (1815-1852)
▪ “Wrote” the description of the mechanical computer of Babbage
▪ Regarded as the first programmer ever
▪ The programming language ADA is named after her
o Alan Turning (1912-1954)
▪ Father of Theoretical Computer Science (TCS) and Artificial
Intelligence (AI)
▪ Turning machine -a model for a general-purpose computer.
▪ Turing test – how intelligent is a machine?
o First Electronic Computer: ENIAC 1946
▪ ENIAC – Electronic Numerical Integrator and Calculator.
▪ 50,000 vacuum tubes, diodes, relays, resistors, capacitors.
▪ 5 million hand-soldered joints.
▪ Weighed 27 tons.
▪ Covered 167 m2 area.
▪ Consumed 150 kW of Power.
o 1946 – 1976
▪ Transistors
▪ Integrated Circuits
▪ Apple Macintosh
o Core i7 Processor
▪ 2008-15: Intel Core i7 Processor
▪ Clock Speed > 2.5 GHz
▪ No. of Transistors: 0.731-1.3B
▪ Doubles every two years (Moore’s law)
▪ Technology: 45-22nm CMOS
▪ Area: 263 – 181 mm2
▪ Nowadays: Multicore (as clock speed increased) with cooling units
Q. How does a computer represent data?

• To store: Numbers, text, graphics and images, video, audio, program instructions
• In some way, all information is digitalized – broken down into pieces and
represent and represent as a number.
• Example: Representing Text Digitally.
o Every character is stored as a number, including spaces, digits and
punctuation
o Corresponding upper- and lower-case letters are separate characters
Q. The ASCII Table
AMERICAN STANDARD CODE FOR INFORMATION INTERCHANGE

Q. How does number get stored?

• Number Systems
• Decimal (base 10 – uses 10 symbols (0-9)).
• Unary (base 1-uses 1 symbol. (1,11,111,111….))
• Binary (base 2)-uses 2 symbols. (0,1))
Ex: 0,1,10,11,100,101,110….
• Octal (base 8-uses 8 symbols (0-7)
Ex: 0,1,2,3,4,5,6,7,10,11,12,13
• Hexadecimal (base 16-uses A-F for 10-15)
Ex: 0, 1, …., 9, A, B, C, D, E, F, 10, 11, …., 19, 1A, 1B, …
Q. Quick primer on Number System: Base n

• Take every “digit” and multiply by increasing powers of n and add.


o 329 >> 102 101 100 >> 3x100 + 2x10 + 9x1 = 329
o (most significant digit)1-0-1 (least significant image)
101 >> 22 21 20 >> 1x4 + 0x2 >> 1+1 = 5

Q. Converting from Decimal to Binary

• Converting the decimal number 39 to binary (base 2)


39 = 2*19 + 1
=2*(2*9 +1) +1
=22*9 +21*1 +1
=22*(2*4+1) +21*1+1
=23*4+22*1+21*1+1
=23*(2*2+0) +22*1+21*1+1
=24*2+23*0 +22*1+21*1+1
=24*(2*1+0) +…
=25*1+24*0+23*0+22*1+21*1+1
(100111)2 = (1 X 20) + (1 X 21) +(1 X 22) +(1 X 23) +(1 X 24) +(1 X 25) = (39)10

Q. Which Number System? Binary!

• Devices that store and process information are cheaper and more reliable if they
have to represent only two states.
• A single bit can represent two possible states like a light bulb that is either on (1)
or off (0). Hence representable by even voltage levels in wires.
• The other number system can be “encoded in” binary
Octal, Hexadecimal, etc.

Q. Representing values in Binary?

• If we have m bits, we can represent 2m unique different values.

Q. Representing negative numbers

• Sign Magnitude notation


o Use one bit for sign, others for magnitude of the number
o Using n bits: -(2n-1 -1) … (2n-1 -1)
o Zero has two representations.
• Ones complement notation
o For a negative number n, represent the number by the bit complement of its
binary rep. using k bits.
o Using n bits: -(2n-1 -1) … (2n-1 -1).
o Zero has two representations.
o Not very widely used representation.
• A neat trick
o Two complement notations
▪ For a positive number n, represent the number by its binary rep. using k
bits
▪ For a negative number -n, represent the number as 2k -n.
▪ Using n bits: -(2n-1 -1) … (2n-1 -1).
▪ Widely used representation.

Q. The case of 4 Bits

• Overflow Detection Rule:


If two numbers with the same sign (both positive or both negative) are added, then
overflow occurs if and only if the binary representation of the results has the opposite
sign.

Q. What to do?

• How to Detect it?


The technique of overflow detection is easily implemented in electric circuitry, and it is a
standard feature in digital adder circuit.
• How to Prevent it?
Use more bits!

Q. What are tokens?

• The token Is the smallest individual unit of the c program, that is meaning full to
compiler, token is the fundamental building block from which c program constructed.
Whether the c compiler process the source code its first break down into these tokens.

Q. What are Keywords?

• Keywords are presented as reserve words that are predefined. There are 32 keywords in
C. Example: printf, scanf, try, case, do.

Q. What are identifiers?


• Identifier is a use defined name given to various program element such as variable, Function, array and
structure.

GOALS:
• Edit, Compile and execute the first C program.
• Get simple yet useful tasks done via C programs.
o Add a set of numbers.
o Find roots of a quadratic equation.
o Multiply 2 polynomials.
• Learn the syntax of C language
o Basics – structure of a C program, using standard library.
o How to store data – variables, data types.
o How to get inputs, how to print outputs?
• Learn about the working environment (Linux based OS).
o Editors – gedit and others.
o Compiler – gcc
o Executing a compiler program.
Lecture 4
Tokens: The smallest individual unit of a program is knowns as tokens (Just like atoms)

• TYPES OF TOKENS :-
1. Identifiers: The place holder that stores value is known as the identifiers.
Rules for naming identifiers:
1. Can only start with the underscore or an alphabet
2. Cannot start from number
3. Must have only underscore as a special character, A-Z, a-z, 0-9.

2. Constants: It cannot be changed and It is Immutable for the whole program, IT represent
the fixed value, In C programming there are:
o Integer Constant
o Floating point constant
o Character constant
o String Literal Constant
<Example: Const int x = 10;>

3. Operator: They are the symbols that are used to perform operations on 1 or more
operands. <Example: +, -, *, /, %, etc.> ( Modules % only applies on integer)

o Logical Operators: AND &, OR ||, NOT ! (Truth Table reference)

o Assignment Operator: = is the assignment operator that can assign values to the
variables. (== is the comparing operator not the assignment operator both are different)
We can use all the arithmetic operators with assignment operator in a code.

o Relational or Comparison operator (>,<,==,=>,=<, !=): Gives the answer in binary


(Boolean test mechanism).

4. Special Symbol/punctuator: That is used to organize and structure the code.


(), {}, [], ’’, ””, etc.

Q. Add two numbers and store result in another variables ?

#include <stdio.h>

int main(void){

int a=2;

int b=3;

int c=a+b;

printf(“%d”,c);

return 0;

}
Q. Add two numbers and store result in another variables ? (User defined)

#include <stdio.h>

int main(void){

int a;

int b;

printf(“Enter the value of 1st variable: “);

scanf(“%d”, &a);

printf(“Enter the value of 2nd variable: “);

scanf(“%d”, &b);

int c=a+b;

printf(“%d”,c);

return 0;

Q. make practical file and do program for all the athematic operators

• ADDITION

• SUBTRACTION
• MULTIPLICATION

• DIVISION

• MODULAS
Q. consider X as c program marks, Y as Data science marks (weightage of X is 30% and Y is
70%), formula Z=(30.0/100.0)*x+(70.0/100.0)*y?

Q. Swap 2 numbers?

* With a 3rd variable*

*Without a 3rd variable*


Lecture 5 (15/09/2025)
• #include <stdio.h> is called preprocessor directive.
• void is like none of python.
• Variable in the system assigned to the main () will refer to its initial variable memory.
• int (signed int) can store +,- both and can have only 2 byte for 32-bit system and 4 byte for 64-bit
system. and unsigned int can only store the +ve value.
• Write a program to calculate circumference of circle.

• Write a program to calculate the area of square.

Lecture 6 (17/09/2025)
Q. Write a program to print ASCII value of the given character?

Q. Type Conversation of Data Type?

• Implicit
conversation of a low space taking data type to a high space taking data type it goes
easily, that is through a type specifier (%c to %d)
• Explicit
conversion of a high space taking data type to a low space taking data type it goes not so
easily, that is through type casting (%f to %d it provides some garbage value without a type casting
int m = (int)f ).
Q. What is Control Statement?

• That controls the flow of program and don’t go to the default structure of flow by
breaking the regular flow of program using decision making statement or selection
statement.
• Type of Selection statement ( Program to check if number is greater or lesser than 0 )
o Single selection
▪ if statement
syntax: if (condition){ }

o Double selection
▪ if else statement
syntax: if (condition){ }
else { }

o Multi Selection
▪ if elseif else statement
syntax: if (condition){ }
else if (condition){ }
else { }
Q. Write a program to check it the day is are correct or not. (Using multiple selection statement)\

Q. Write a program to check that are you eligible for vote or not. (1st you have to check for citizenship (if
you Indian eligible))
Q. Nested Statement
• If you use a conditional statement inside an already written condition statement.
• if you use if ( ) if ( ) if ( ), rather than else if or else, that is called ladder

Lecture 7 (19/09/2025)
Q. Write a program to check if given character is vowel or is it consonant?

Lecture 8 (21/09/2025)
Q. Write a program to calculate total salary of employee:
TS = B.S + DA + TA + HRA

If basic salary <= 35000 then

DA is 2% of bs

TS is 3% of bs

HRA is 4% of bs

If basic salary >75000 && <=80000 then

DA is 3% of bs

TS is 4% of bs

HRA is 7% of bs

If basic salary < 80000 then DA is 4% of bs

TS is 6% of bs
HRA is 9% of bs

Q. Switch Statement?

• When we have to do multiple selections, we use switch statement.


• It is limited by if and else cause we can only use == not any gate like && or ||.
• Used for direct comparison not checking any &&, || gates and statements.
• Syntax:
Switch(day)
{
case1: Monday;
Break;
case2: Tuesday;
Break;
last case: default;
Invalid Response;
}
Q. Write a program to check which day of the week is it?

You might also like