0% found this document useful (0 votes)
36 views

C Notes (Data Planet)

This document discusses algorithms and flowcharts. It provides examples of different flowchart symbols like terminator, data, process, decision, connector, and arrow. It also includes various algorithms and their flowcharts like addition of two numbers, calculating gross salary based on policies, checking even-odd, and divisible by 7. Further, it discusses different programming concepts like loops, patterns, functions, arrays, strings and more.

Uploaded by

Akash Shinde
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

C Notes (Data Planet)

This document discusses algorithms and flowcharts. It provides examples of different flowchart symbols like terminator, data, process, decision, connector, and arrow. It also includes various algorithms and their flowcharts like addition of two numbers, calculating gross salary based on policies, checking even-odd, and divisible by 7. Further, it discusses different programming concepts like loops, patterns, functions, arrays, strings and more.

Uploaded by

Akash Shinde
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 184

WAP to read two integers and swap their values

without using third variable.


Algorithms &
Flowcharts
Algorithm
“Algorithm is a step by step procedure to
solve the problem in finite amount of
time with finite amount of data”

KEDAR KABRA SIR


Flowchart
“Flowchart is a pictorial representation
of an algorithm”

KEDAR KABRA SIR


 Each step in algorithm is represented by particular
symbol in flowchart.
 Flowchart symbols are linked together by arrows
showing the flow of process.
 Flowcharts play vital role in programming to help
understanding the logic of complicated and lengthy
problems
 Once flowchart is drawn, it becomes easy to write
program

KEDAR KABRA SIR


Terminator
An oval shape is used to indicate start or
end of the flowchart

Start/End

KEDAR KABRA SIR


Data
A parallelogram is used to indicate input
or output

Input/Ouput

KEDAR KABRA SIR


Process
A rectangle is used to indicate
normal/generic statement or expression

Expression

KEDAR KABRA SIR


Decision
A Diamond is used to indicate decision
or branching in flowchart.
Yes No
Condition

KEDAR KABRA SIR


Connector
A small labelled circle is used to indicate
jumps or connection in flowchart.

KEDAR KABRA SIR


Arrow
Arrows are used to show flow of the
process.

KEDAR KABRA SIR


Program for addition of two integers
Flowchart
Algorithm Start

1. Declare three variables x, y,sum Declare variables


x,y,sum
2. Read two numbers in x and y
Read x and y
3. Calculate addition sum=x+y
4. Print value of sum Calculate sum=x+y

Print sum

Stop
WAP to read basic salary of employee and calculate gross salary as per below
policy
1. If basic salary is less than 1500 then HRA=10% of basic and DA=25% of
basic
2. If basic salary is 1500 or above then HRA=500 and DA=50% of basic
WAP to read an integer and check if it is even or odd

WAP to read an integer and check if it divisible by 7 or not.

WAP to read two integers and check if first is divisible by second or not.
Bank has introduced an incentive policy as follows:
Every account holder will get bonus =2% of balance.
In case of female account holder, 5% of balance will be given only if her
balance > 5000.
WAP to read gender and balance then determine bonus.
Truth Table
Truth Table

WAP to read an integer and check if it is single digit


number or not
WAP to read a number and check if it between 100 to
200 or not.

WAP to read three integers and find out largest.

WAP to read four integers and find out smallest.


WAP to read a character and check if it is vowel or not

Note: Every OR logic can be replaced by ladder but not every


ladder with logical OR

WAP to read a character and print appropriate


message as follows
Character Message
‘r’ or ‘R’ Red
‘g’ or ‘G’ Green
‘b’ or ‘B’ Blue
any other Black

WAP to read year and check if it is leap year or not.


logic for Leap year is basically that:
1. A year is a leap year if it is divisible by 4 but not
by 100.
2. If a year is divisible by both 4 and by 100, then it
can only be a leap year if it is also divisible by 400.
WAP to read a character and print appropriate
message as follows
Character Message
A Excellent
B Good
C Fair
D Poor
F Fail
WAP to read a number and print appropriate message
as follows
Character Message
1 Milk
2 Tea
3 Coffee
Any other Water
WAP to read a digit and print it in words
for ex-
If input is 7 then output should be Seven

WAP to read a month number and print it in words


for ex-
If input is 5 then output should be MAY

Home Work

WAP to read a character and check if it is vowel or not


by using switch case
WAP to read a character and print appropriate
message as follows by using switch-case
Character Message
‘r’ or ‘R’ Red
‘g’ or ‘G’ Green
‘b’ or ‘B’ Blue
any other Black
Home Work
WAP to print following menu
1.Addition
2.Subtraction
3.Multiplication
4.Division
Read choice and numbers then perform appropriate
operation.
WAP to read two integers and find out maximum by
using conditional operator
Every non zero value is True

Every relational operation is


evaluated to either 1 or 0
WAP to read two integers and find out maximum by
using switch-case

case 1 is true part of given


condition & case 0 is false part
Execution
WAP to print “Hello World” 10 times table

WAP to print integers from 1 to 10


WAP to print integers from 10 to 1 (Home Work)
WAP to print multiplication table of 4

WAP to print multiplication table of given number


(Home Work)

WAP to calculate sum of integers from 1 to 10


Execution
table

WAP to calculate sum of integers from 1 to n.


Read value of n from user.
(Home Work)
WAP to read a number and calculate its factorial.
Execution
table

WAP to read x & y then calculate power .


WAP to print all integers from 100 to 200 that are
divisible by 7.

WAP to count all integers from 100 to 200 that are


divisible by 7.
WAP to find sum of all integers from 100 to 200 that
are divisible by 7.
Home-Work

WAP to calculate sum of even integers and sum of odd


integers between 1 to 100
WAP to read a number and print all its factors

}
WAP to read a number and check if it is prime number
or not

WAP to read a number and check if it is perfect


number or not.
Number is perfect if sum of its factors excluding
number is equal to number itself.
WAP to read two integers and find their G.C.D (HCF)

WAP to print Fibonacci series up to 20 terms


0 1 1 2 3 5 8 13 ...
WAP to calculate sum of following series

Working
WAP to print “Hello World” 10 times by using while
loop
WAP to read a number and find sum of its digits.

.
WAP to read a number and find product of its digits.
WAP to read a number and count occurrences of 5 in it

Take number of your choice


and fill execution table by

WAP to read a number and a digit then count


occurrences of digit in given number
Home Work
WAP to read a number and find largest digit in it.

Take number of your choice


and fill execution table by

WAP to read a number and find smallest digit in it.


Home Work
WAP to read a number and check if it is Armstrong
number or not.
A number is Armstrong if sum of cube of digits is equal
to number itself
for ex = 153

WAP to read a number and find its reverse number

Take number of your choice


and fill execution table by
WAP to read a number and check if it is palindrome
number
A number is palindrome if it is same from both side
(original & reverse)
Home Work
Working
WAP to read integers repeatedly from user and keep
adding them. Stop when negative number is entered.
Print addition of positive numbers entered by user.
WAP to print following menu
1.Addition
2.Subtraction
3.Multiplication
4.Division
Read choice and numbers then perform appropriate
operation.
Repeat until user enters exit choice.
For ex:
Execution
table
WAP to print 10 X 10 pattern of ‘*’

WAP to print multiplication chart from 1 to 10

WAP to print following pattern


*
**
***
****
*****
WAP to print following pattern
*****
****
***
**
*

WAP to print following pattern


1
12
123
1234
12345
Home-Work
WAP to print following pattern
12345
1234
123
12
1
Home-Work
WAP to print following pattern
1
22
333
4444
55555
Home-Work
WAP to print following pattern
55555
4444
333
22
1
Home-Work
WAP to print following pattern
*
**
***
****
*****
WAP to print following pattern
*
**
***
****
*****
****
***
**
*
Home-Work
WAP to print following pattern
*****
****
***
**
*
**
***
****
*****
Home-Work
WAP to print all Armstrong numbers between 1 to 500

WAP to print all Palindrome numbers between 1 to 500


Home-Work

WAP to print all prime numbers between 2 to 500


Home-Work
WAP to read a number and check if it is prime number
or not.
Write output of program on your own

Write output of program on your own


WAP to print hello world 10 times without using loop

WAP to print following pattern by using ‘goto’


statement
*
**
***
****
Home-Work
*****
Calculate & write
ranges from
video lecture
WAP to print ASCII table
WAP to print alphabets from A-Z

WAP to read character and check if it is Upper case,


Lower case, digit or symbol

WAP to print following pattern by using


A
AB
ABC
ABCD
ABCDE
WAP to print following pattern by using
ABCDE
ABCD
ABC
AB
A
WAP to print following pattern by using
A
BB
CCC
DDDD
EEEEE
WAP to print following pattern by using
EEEEE
DDDD
CCC
BB
A
WAP to read 10 integers in array and print them in
output
WAP to read 10 integers in array and replace each by
its square

WAP to read 10 integers in array and increment value


of each integer by 5
-Home Work

WAP to read 10 integers in array and calculate their


addition as well as average.
WAP to read 10 integers in array and count
occurrences of number 15 in it.

WAP to read 10 integers in array and a number then


count occurrences of given number in array.
-Home Work
WAP to read 10 integers in array then count positive,
negative, even and odd integers.
WAP to read 10 integers in array and search given
element.

WAP to read 10 integers in array and sort them in


ascending order. (Sorting is discussed in detail in Data
structure subject)
WAP to read 10 integers in array and find largest
element.

WAP to read 10 integers in array and find smallest


element – Home Work
WAP to read a number and print its binary equivalent.
 WAP to read a number and print its octal equivalent.
– Home Work

 WAP to read a number and print its hexa-decimal


equivalent – Home Work

 WAP to read a number and print it in words.


for ex – 123  one two three – Home Work
WAP to read 3X3 matrix and print it in output.

 WAP to read 3X3 matrix and find sum of all elements


– Home Work
 WAP to read 3X3 matrix and find sum of diagonal
elements – Home Work
WAP to read 3X3 matrix and find its transpose.

WAP to read two 3X3 matrices and calculate addition


matrix.
 WAP to read two 3X3 matrices and find subtraction.
– Home Work
WAP to read two 3X3 matrices and find multiplication.
WAP to read a string and print the same.
WAP to read a string and find out its length.

WAP to read a string and print it in reverse


WAP to read a string and count occurrences of ‘p’ in it

WAP to read a string and count number of words in it.


– Home Work Hint – Count space
WAP to read a string and a character then count
occurrences of that character in given string.
WAP to read a string and count number of vowels in it.

WAP to read a string and count upper case, lower


case, digits and special symbols in it.
WAP to read a string then convert all lower case to
upper case and vice-versa.
WAP to read a string and copy it into another string.

WAP to read two strings and concatenate them into


third string.
WAP to read 10 strings and print them
WAP to define a function which takes character (ch)
and integer (n) as parameter then prints ch – n times.
WAP to define a function for addition of two integers.

WAP to define a function for area of circle.


– Home Work
 WAP to define a function for subtraction of two
integers.
 WAP to define a function for multiplication of two
integers.
 WAP to define a function for division of two
integers.
 WAP to define a function for area of rectangle.
(Think of return type properly)
WAP to define a function to calculate factorial of given
number.

WAP to define a function to calculate power of given


parameters.
WAP to define a function to calculate sum of digits of
given number.

WAP to read a character and print it in both cases.


define functions for conversions.
WAP to define a function to check if given integer is
even or not

WAP to define a function to check if given integer is


prime number or not
WAP to define a function to check if given number is
Armstrong number or not

WAP to define a function to check if given number is


palindrome number or not – Home Work
WAP to define a function to check if given alphabet is
lower case or not
Calculate Factorial through recursive function

Calculate power through recursive function

– Home Work
Calculate multiplication through recursive function
Calculate sum of digits through recursive function
WAP to read a string and find its length by using
library function

WAP to swap contents of two strings


WAP to read two strings and concatenate in third

WAP to read a string and check if it is palindrome


WAP to read a number and calculates its square root
Example to demonstrate life of static variable

Write output of both programs


In above program, contents of header file stdio.h are
imported before compilation of actual code.
identifier
value
address
Example-1

Example-2
Swapping through pointers

To watch this lecture - https://youtu.be/azIrW8rGhAU


To watch this lecture - https://youtu.be/a6cn1rDfVHk
To watch this lecture - https://youtu.be/AyJY28-d034
Modification & displaying array through functions

Defining a function to copy string.

To watch this lecture - https://youtu.be/AyJY28-d034


To watch this lecture - https://youtu.be/OrE5GuSE9nY
Example-1
Example-2

Example-3
Example
Sorting of integers by using qsort

Sorting of characters in a string by using qsort – Home Work


Sorting of strings by using qsort – Home Work

To watch this lecture - https://youtu.be/M0Hsd5rsXTA


Example-1

Example-2

WAP to read dimension of matrix from user and create


array dynamically at run-time
Try to draw memory representation of above allocation
To watch this lecture - https://youtu.be/MgHkZ7fCV08
WAP to pass command line arguments. Print count and arguments.

To create or open-source file in notepad++ editor

compilation

execution with command-line arguments

WAP to add two integers passed as command-line parameters


HWWAP to add all integers passed as command-line parameters –

To watch this topic - https://youtu.be/LeokMFCLPYk


size of int is taken as 2 bytes
and padding is ignored
-Home Work

You might also like