Fundamentals of Computer Science
Fundamentals of Computer Science
proceeding:
This document is confidential and intended solely for the educational purpose
of RMK Group of Educational Institutions. If you have received this document
through email in error, please notify the system manager. This document
contains proprietary information and is intended only to the respective group
/ learning community as intended. If you are not the addressee you should
not disseminate, distribute or copy through e-mail. Please notify the sender
immediately by e-mail if you have received this document by mistake and
delete this document from your system. If you are not the intended recipient
you are notified that disclosing, copying, distributing or taking any action in
reliance on the contents of this information is strictly prohibited.
FUNDAMENTALS
OF
COMPUTER SCIENCE
LIST OF EXPERIMENTS:
1. Algorithm and flowcharts of small problems like GCD
2. Structured code writing with:
i. Small but tricky codes
ii. Proper parameter passing
iii. Command line Arguments
iv. Variable parameter
v. Pointer to functions
vi. User defined header
vii. Make file utility
viii. Multi file program and user defined libraries
ix. Interesting substring matching / searching programs
x. Parsing related assignments
TOTAL: 30 PERIODS
Course
Outcomes
Upon completion of the course, the students will be
able to
Apply problem solving techniques to simple computational
problems K3
Understand the syntax and constructs of C language K1
Develop structured programs using basic constructs in C K3
Understand pointers and arrays in C K2
Understand Unix system interface K1
Apply various programming methods K4
CO – PO/PSO
Mapping
POs/PSOs
CO1 3 3 3 3 3 1 1 1 2 2 3 3 3 2 2
CO2 3 2 2 2 3 1 1 1 1 2 2 3 3 2 2
CO3 3 2 2 2 3 1 1 1 1 2 2 3 3 2 2
CO4 3 2 2 2 3 1 1 1 1 2 2 3 3 2 2
CO5 3 2 2 2 3 1 1 1 2 2 3 3 3 2 2
C06 3 2 2 2 3 1 1 1 2 2 3 3 3 2 2
Prerequisites
Prerequisites
1. Introduction to Computers
https://drive.google.com/file/d/1LShECakErVJelpHyFzc4X3r8rSrb64dh
/view?usp=sharing
2. Computer Architecture
https://drive.google.com/file/d/1M7I2BTaFkpT1r3sKnq-
C8LIldALq_cSs/view?usp=sharing
UNIT I
GENERAL PROBLEM
SOLVING CONCEPTS
AND INTRODUCTION
TO C
LECTURE PLAN
UNIT – I
Schedule Actual Date
S. No. of Mode of Taxonom
Topic d of CO
No. Periods Delivery y Level
Date Completion
General problem Solving
concepts: Algorithm, and
Video/
1 Flowchart for problem 2 CO1 K1
PPT
solving with Sequential
Logic Structure,
Decisions and Loops.
Imperative languages:
Introduction to
PPT/
2 imperative language; 1 CO1 K1
Demo
syntax and constructs
of a specific language
(ANSI C)
Types Operator and
Expressions with
discussion of variable
naming and Hungarian
PPT/
3 Notation: Variable 2 CO1 K2
Names, Data Type and Demo
Sizes (Little Endian Big
Endian), Constants,
Declarations
Arithmetic
Operators,
Relational
Operators, Logical
Operators, Type
Conversion,
Increment
PPT/
4 Decrement 2 CO1 K3
Operators, Bitwise Demo
Operators,
Assignment
Operators and
Expressions,
Precedence and
Order of Evaluation
Control Flow with
discussion on structured
and unstructured
programming:
Statements and Blocks,
PPT/
5 If-Else-If, Switch, Loops 2 CO1 K2
– while, do, for, break Demo
and continue, goto
labels, structured and
un- structured
programming.
Activity Based
Learning
UNIT – I
Topic Activity
Operators Questioning
It is also a precise rule (or set of rules) specifying how to solve a problem.
An algorithm is a sequence of finite instructions, often used for calculation
and data processing.
Characteristics of Algorithm
The algorithm should be written in sequence.
Properties of an Algorithm
An algorithm is not a program, as they cannot be executed by a computer.
It is an ordered sequence of finite, well defined unambiguous instructions
for completing a task.
Steps must be ordered, unambiguous and finite
termination.
Step 5: Stop
Example #2
Problem Statement : Calculate the area & circumference of a
circle
Step 1: Start
Step 2: Read
r
Step 5: Stop
Flowchart
Definition: Flowchart is a pictorial representation of an algorithm in which
the steps are drawn in the form of different shapes of boxes and the
logical flow is indicated by interconnecting arrows.
Or
❖Only one flow line should enter a decision symbol. Two or three flow lines may
leave the decision symbol.
Guidelines for preparing Flowcharts
(Continued…)
Only one flow line should be used with a terminal symbol.
Use annotation symbol to describe data or process more clearly.
Benefits of Flowcharts
Makes Logic Clear:
The pictorial representation helps in understanding the logic clearly.
Assists in finding the key elements of a process by drawing clear flow lines.
Communication: It encourages communication among programmers and
users
Effective Analysis:
It reveals redundant or misplaced steps
It helps in analysing the logic of the program by other persons who may
or may not know programming techniques.
It establishes important areas for monitoring or data collection
It identifies areas for improvement.
Useful in Coding:
It ensures that no steps are missed while coding.
Coding can be done faster.
Proper testing and Debugging:
It helps in detecting errors.
Test the logic with normal/unusual data.
Appropriate Documentation:
It serves as a good program documentation tool.
It helps in knowing what the program does and how to use the program.
Efficient Program Maintenance
The maintenance of operating program becomes easy with the help
of flowchart.
It helps the programmer to put efforts more efficiently on that part.
Limitations
Complex
It is laborious to draw flow chart for larger programs
For large programs it continues to pages making difficult to understand.
Costly
Difficult to Modify
Any changes or modification to a flowchart usually require redrawing
the entire logic again.
It is not easy to draw thousands of flow lines and symbols, especially for
a large complex program.
No update
Usually programs are updated regularly but corresponding update
of flowcharts may not take place, especially in case of large
programs.
As a result, the logic used in the flowchart may not match with the
actual program's logic.
Control flow
Sequence
Selection /
decision
Repetition / Iteration
Functions
1. Instructions / Statements
Instructions are the statements of actions which are to be performed in
a sequential order.
A statement is a unit of code/instruction that has an effect, like creating
a variable or displaying a value.
Examples:
Example 1: Set your age as 18.
Example 2: Print "RAIDERS ARE CHAMPS" 39 times.
Example 3: If you were born in California, print "NATIVE",
otherwise print "RESIDENT".
2. State of an algorithm
A state provides the value of a variable at a particular instant in time.
Programmers generally choose names for their variables that are
meaningful—
they document what the variable is used for.
Flowchart
3.2 Selection / Decision Flow diagram
Statements are used when the outcome of the0
process depends on some condition.
A condition in this context may evaluate either
to a true or false value.
The statement will be executed when the
Example: Accept two numbers, Display the first number if greater than
the second.
Algorithm
step1. Start
step2. Accept two numbers and store the variables in A and B.
step3. If (A > B) then Display A is greater than B.
step5. Else Display B is greater than A
step6. Stop
Flowchart
3.3 Repetition Flow diagram
Repetition involves in executing one
or more steps for a number of times.
These statements execute one or more
steps until some condition is true.
History of C
The root of all modern languages is ALGOL, introduced in 1960. ALGOL was the
first computer language to use a block structure.
In 1970, Ken Thompson created a language using many features of BCPL and
called it simply B.
C was evolved from ALGOL, BCPL and B by Dennis Ritchie at Bell Laboratories in
1972 and it was known as “traditional C”.
The language became more popular after publication of the book ‘The C
Programming Language’ by Brian Kerningham and Dennis Ritchie in 1978. The
language came to know as “K&R C”.
C is a robust language whose rich set of built in functions and operators can be
used to write any complex program.
C has the ability to extend itself. We can continuously add our own functions to
the existing library functions.
C is a middle level language, i.e. it supports both the low level language and high
level language features.
C language allows dynamic memory allocation i.e. a program can request the
operating system to allocate or release memory at runtime.
C language allows manipulation of data at the lowest level i.e., bit level
manipulation. This feature is extensively useful in writing system software
program.
Documentation section:
It consists of comment lines giving the name of the program, author & other
details which the programmer would like to use.
Comments are not necessary in the program.
It is useful for documentation.
Comments are non executable statements which are placed between the
delimiters /* */ for multi line comments and started with // for single line
comments.
The complier does not execute comments
Link section:
It provides instruction to the compiler to link functions from the system library.
Program depends upon some header files for function definition that are used in
program.
Definition section:
Function main
Every program written in C language must contain main() function.
The execution of the program always begins with the function main().
Declaration part:
The declaration part declares the entire variables that are used in executable part.
The initialisations of variables are done in this section. Initialisation means
providing initial value to the variables.
Executable part:
This part contains a set of statements or a single statement.
These statements are enclosed between the braces ({}).
They can also be defined before main() function. This portion is not compulsory.
Programming Rules
All statements should be written in lower case letters. Upper case letters are only
used for symbolic constants.
Blank spaces may be inserted between the words.
The program statements can written anywhere between the two braces following
the declaration part.
The opening and closing braces should be balanced. eg., if opening braces are
four, then closing braces should be four.
Sample C Program
Example
#include<stdio.h>
void main()
{
printf(“HELLO”);
}
Character
Set
A character denotes any alphabet, digits, white spaces or special symbol used to
represent information.
Letters A to Z and a to z
Digits 0 to 9
C Tokens
are,
Keyword
Identifier
Constants
Operators
Keyword:
The c keywords are reserved words by the
compiler. The keywords cannot be used as variable
name.
All keywords must be written in lower case.
Keywords areauto double
predefined and have standard int struct
Rules
A variable name can be any combination of alphabets, digits and underscore.
Variable should not start with a digit.
The first character must be an alphabet or an underscore ( _ ).
The value of a certain variable remains the same or remains unchanged during the
execution of a program. It can be done by declaring the variable as a constant.
The keyword const is added before the declaration.
Example: const int m=10;
Volatile Variable
The volatile variables are those variables that are changed at any time by program.
Example: volatile int d;
Basic Data Types
C language provides very few basic datatypes. The datatypes are specified by a
standard keyword. The data types are used to define the type of data for
particular variable. Various data types that are used in C is enlisted in the following
table.
https://www.youtube.com/watch?v=bS6uNMmIoQ
0
Sizes (Little Endian Big
Endian)
Endian:
The term endian refers to the order of storing bytes in computer memory.
Endian
#define PI 3.14159
#define service_tax 0.12
Scanf() requires conversion symbol to identify the data to be read during the
execution of a program.
Conversion symbol represents the field format in which the data is to be entered.
name);
+ Addition A+B
- Subtraction A-B
* Multiplication A*B
/ Division A/B
% Modulus A%B
operation.
#include<stdio.h>
#include<conio.h>
void main() Output:
{ a++ = 11
int a = 10, b=3;
b-- = 2
printf("a++ = ", (a ++) );
printf("a - - = " , (a - -) );
}
Relational Operators
Relational operators are used to test condition and results true or false
value, The following table lists relational operators
#include<stdio.h>
#include<conio.h>
void main()
Output:
{
int a = 10, b=20; a == b = false
printf("a= = b=", (a ==b) ); a != b = true
printf("a !=b= " , (a!=b) ); a > b = false
printf(“a>b=”,(a>b)); a < b = true
printf(“a>=b=”,(a>=b)); b >= a = true
printf(“a<b=”,(a<b)); b <= a = false
printf(“a<=b=”,(a<=b))
}
Logical Operators
Logical operators are used to combine more than one condition.
The following table lists logical operators
Example
#include<stdio.h> Output:
void main()
a && b = false
{
boolean a = true; a || b = true
boolean b = false; !(a && b) = true
printf("a && b = " + (a&&b) );
printf("a || b = " + (a||b) );
printf("!(a && b) = " + !(a && b)
);
}
Assignment Operator
Simple Assignment
=, assigns right hand side value to left hand side variable
Ex:
int a;
a = 10;
Compound Assignment
+=, -=, *=, /=, %=, &=, |=, ^=, >>=, <<=, assigns right
hand side value after the computation to left hand side variable
Ex:
int a;
int b;
a += 10; // means a = a + 10;
a &= b; // means a = a & b;
Bitwise Operators
Bitwise operator act on integral operands and perform binary operations. The
lists of bitwise operators are
Bitwise AND
The & operator compares corresponding bits between two numbers and if
both the bits are 1, only then the resultant bit is 1. If either one of the bits
is 0, then the resultant bit is 0.
5-> 0101
9-> 1001
Example : 0001
int x = 5; int y = 9; x & y = 1
Bitwise OR
The | operator will set the resulting bit to 1 if either one of them is 1.
It will return 0 only if both the bits are 0.
Example :
int x = 5; 5-> 0101
int y = 9; 9-> 1001
x | y = 13 1101
Bitwise EXOR
The ^ operator compares two bits to check whether these bits are
different. If they are different, the result is 1.Otherwise, the result is 0.
This operator is also known as XOR operator.
Example :
int x = 5; 5-> 0101
int y = 9;
9-> 1001
x | y = 12
1110
#include<stdio.h>
void main()
{
int x = 5;
int y = 9; Output:
int a = x & y; int b = x | y; int c = x ^ y;
x&y=1
printf("x & y = "+a);
printf(" x | y = "+b); x | y = 13
printf("x ^ y = "+c); x^y=
} 12
Bitwise NOT
The negation ~ operators complements all the bits, 1 are converted to 0
and 0s are converted to 1s.
For Eg.
int a =5;
~a = -5
5 -> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
~5 - > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0
Shift Operators
The shift operators (<< and >>) shift the bits of a number to the left
or right, resulting in a new number. They are used only on integral
numbers (and not on floating point numbers, i.e. decimals).
Shift Right
For Eg.
int x = 16; x = x >> 3;
right shift operator >>, divides by 2 to the power of number specified
after the operator. In this case, we have 3 as the value after the right
shift operator. So, 16 will be divided by the value 2 to the power of 3,
which is 8.
The result is 2.
When we represent 16 in binary form, we will get the following binary value :
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
When we apply >> which is the right shift operator, bit represented by 1 moves by
the positions to the right (represented by the 3 right shift operator). After
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
x=2
Shift Left
Eg.
int x = 8;
x = x << 4;
left shift operator <<, multiplies by 2 to the power of number specified
after the operator. In this case, we have 4 as the value after the left shift
operator. So, 8 will be multiplied by the value 2 to the power of 4, which is
16.
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
When we apply << which is the left shift operator, bit represented by
1 moves by
the positions to the left (represented by the number right shift 4 After
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
X=128
#include<stdio.h>
Output:
Void main()
The original value of x is 8
{ After using << 2, the new value is 2
int x =8; After using >> 4, the new value is 128
printf("The original value of x is “,x);
printf("After using << 2, the new value is “,x << 2);
printf("After using >> 4, the new value is “, x >> 4);
}
PRECEDENCE AND ASSOCIATIVITY OF
OPERATORS
An expression is a combination of constants, variables and operators.
Hence (b*c) will be evaluated first. This result will then be added to a.
Expression
An expression is a formula in which operands are linked to each other by the
use of operators to compute a value. An operand can be a function reference, a
variable, an array element or a constant.
chInitial : char
nSize : integer
iSize : integer
fpPrice: floating-point
dbPi : double
Example
x=10;
i++;
printf(…..);
Example
Statement blocks
if( i == j)
{
printf(“C Programming \n");
}
The decision making statement checks the given condition and then executes its sub block.
The decision statement decides the statement to be executed after the success or failure of
a given condition.
Decision making statements are classified into (i) if statement (ii)switch statement
Simple if statement
syntax :
if(Booleanexpressio)
{
statement–block;
}
Next statement;
#includ<stdio.h>
void main()
{
int n=5;
if(n<25)
{
printf(“This is if statement”); Output:
} This is if statement
}
if .. else statement
Syntax
if(boolean expression)
{
True-block statements;
}
else
{
False-block statements;
}
Next statement;
#include<stdio.h>
void main()
{
int age;
printf(“Enter the age”);
scanf(%d”,&age);
if(age>18)
{
printf(“Eligible to vote”);
}
else
{
printf(“Not eligible to vote”);
}
}
Cascading if..else
Syntax:
if (condition1)
{
statement-1
}
….
else if(conditio-n)
{
statement-n
}
else
{
default statement
}
next statement
#include<stdio.h>
void main()
{
int n1,n2,n3;
printf(“Enter the number”);
scanf(“%d%d%d”,&n1,&n2,&n3)
; if(n1>n2 && n1>n3)
{
printf(“%d is largest number”,n1);
}
else If(n2>n3)
{
printf(“%d is the largest number”,n2);
}
else
{
printf(“%d is the largest number”,n3);
}
}
Switch Statement
The switch-case conditional construct is a more structured way of testing
for multiple conditions rather than resorting to a multiple if statement
Syntax:
switch(expression)
{
case 1: case 1 block
break;
case 2: case 2 block
break;
default: default block;
break;
}
statement;
#include<stdio.h>
Void main()
{
int w;
printf(“Enter the week”);
scanf(“%d”,&w);
switch(w)
{
case 1:
printf(“Sunday”);
break;
case 2:
printf(“Monday”);
break;
case 3:
printf(“Tuesday”)
; break;
case 4:
printf(“Wednesday”);
break;
case 5:
printf(“Thursday”);
break;
case 6:
printf(“Friday”);
break;
/* This is an example of a for loop */
#include<stdio.h>
void main()
{
int i;
for(i=0;i<=5;i++)
{
printf(“i:”,i);
}
Output:
i: 1
i: 2
i: 3
i: 4
i: 5
While Loop
It’s a entry controlled loop, the condition in the while loop is evaluated,
and if the condition is true, the code within the block is executed. This
repeats until the condition becomes false
Syntax
while(condition)
{
Body of the
loop
}
#include<stdio.h>
void main()
/* This is an example for a while loop */
{
int i = 0;
while (i < 5)
{
printf("i: “,i);
i = i + 1;
}
}
Output:
i: 0
I: 1
i: 2
i: 3
i: 4
do.. while Loop
It’s a exit controlled loop, the body of the loop gets executed first
followed by checking the condition. Continues with the body if the condition is
true, else loops gets terminated.
Syntax
do
{
body of the loop
}
while(Boolean expression);
#include<stdio.h>
void main()
{
int i=5;
do
{
println("i: “,i);
i = i + 1;
}
while (i < 5);
}
Output:
I: 5
for Loop
Syntax
for(initialization;condition; increment/decrement)
}
/* This is an example of a for loop */
#include<stdio.h>
void main()
{
int i;
for(i=0;i<=5;i++)
{
printf(“i:”,i);
}
Output:
i: 1
i: 2
i: 3
i: 4
i: 5
Break statement
A break statement terminates the loop, and the control then automatically passes
to the first statement after the loop.
Break can be associated with all conditional statements.
Syntactic form :
break;
Program
main( )
{
int num, i; scanf(“%d”, &num); i=2;
while(i<=num-1)
{
if (num%i==0)
{
printf(“The number %d is not a prime number”, num); break;
}
i++;
}
if(i= = num)
printf(“The number %d is a prime number”, num);
}
In this, if num%i=0, then the message not prime number is printed and control
breaks the while loop and the control will reach outside the while loop.
break, breaks the control only from the loop in which it is placed.
The Continue Statement
It is used for continuing next iteration of
loop statements.
When it occurs in the loop, it does not terminate but
skips the statements after this statement.
Write a C program to find the product of 4 integers entered by
a user. If user enters 0 skip it.
//program to demonstrate the working of continue statement in
C programming
# include <stdio.h>
int main()
{
int i,num,product;
for(i=1,product=1;i<=4;++i
)
{
printf("Enter num%d:",i);
scanf("%d",&num);
if(num==0)
continue; / *In this program, when num equals to zero, it skips the
statement product*=num and continue the loop. */
product*=num;
}
printf("product=%d",product); return 0;
}
Output
Enter num1:3
Enter num2:0
Enter num3:5
product = 15
goto Statement:
It is an unconditional branching statement.
This statement does not require any condition.
goto statement passes control anywhere in the program, ie., the control is
transferred to another part of the program without testing any condition.
General Form:
Goto Label;
-
-
Label: Statement;
Label: may be anywhere in the program.
Example:
int main()
{
int age; Vote:
printf("you are eligible for voting"); NoVote:
printf("you are not eligible to vote");
Modules are functions are a set of statements which perform a sub task.
As each task is a separate module, it is easy for the programmer to test and debug.
While changing the code the programmer has to concentrate only on the specific
module.
Unstructured Programming
Here the codes is written as a single whole block. The whole program is taken as a
single unit. It is harder to do changes in the program. This paradigm was used in earlier
versions of BASIC , COBOL and FPRTRAN.
}
Assignment Questions
CO 1 Develop C program solutions to simple computational problems
1. Write a C program to check whether the number is palindrome number or not K2 CO1
a palindrome number.
Test Data :
Input a three digit number : 121
Expected Output :
The given number is :
121
The given number is palindrome number
Test Data :
Input the given number :5
Expected Output :
The factorial of a given number is : 120
Part A
Question & Answer
Part A
Question & Answer
Part
A
1. Define an algorithm. (CO1)(K2)
Be precise
Be unambiguous
After the algorithm gets terminated, the desired result must be obtained.
The following are the primary factors that are used to judge the quality of an
algorithm,
Time
Memory
Accuracy
Sequence
Flowchart
Pseudocode
Programming languages
5. What are the various control flow structures in an algorithm? (CO1)(K2)
Sequence
Selection
Repetition
Statements are used when the outcome of the process depends on some
condition.
Difficult to Modify
Cannot be updated frequently
Complex to design for larger
programs Costly
Less
14. What is looping? (CO1)(K2)
Parallelism
Looping is a sequence of instructions that is continually repeated until a certain
condition is reached.
15. Define Problem Solving. (CO1)(K2)
Problem solving means the ability to formulate problems, think creatively about
solutions, and express a solution clearly and accurately.
16. Write an algorithm for interchanging / swapping two values. (CO1)(K2)
Step1: Start
Step2: Read the two numbers as a and
Step7:
Stop
17.Write an algorithm to find whether a number is even or odd. (CO1)(K2)
Step1: Start
End if
Step4: Stop
18. Write the algorithm to find the average of three numbers. (CO1)(K2)
Step 1: START
Step1: Start
Step2: Read the number.
fact=1
Step5: fact=fact*i
Fals
e
Tru
e
21. What are the Features and Application of C Language? (CO1)(K2)
C is a general purpose, structured programming language.
C is highly portable.
C has the ability to extend itself. We can continuously add our own functions to
the existing library functions.
C is well suited for writing system software as well as application software.
C tokens are classified into (i)Keywords (ii) Identifiers (iii) constant (iv)Operators
(v)String (vi) special characters.
25. List the rules that are to be followed while declaring variable? (CO1)(K2)
A variable name can be any combination of alphabets, digits and underscore.
The first character must be an alphabet or an underscore ( _ ).
No commas or blank space are allowed within a variable name.
No special symbol can be used in a variable.
26. what is variable and write syntax of the variable? (CO1)(K2)
A variable is an identifier.
A variable may take different values at different times during the execution.
Syntax: Data_ type
c+=(a>0&&a<=10)?++a:a/b
c+= (50>0&&50<=10)?++50:50/10
c+=5
c=c+5
c=20+5=25
31. List out the Operators in C? (CO1)(K2)
Arithmetic Operators
Relational operators
Assignment Operators
Logical operators
Bitwise Operators
Conditional or Ternary Operators
Special operators
i) 4+8/2*7+4
=4+4*7+4
=4+28+4
=32+4
=36
ii) 4%3*5/2+(5*5)
=4%3*5/2+25
=1*5/2+25
=5/2+25
=2.5+25
=27.5
34.Define formatted input and output functions? (CO1)(K2)
scanf( )
int scanf(“Control-String”,
&a);
printf( )
It specifies print formatted and is used to display a message.
The syntax is Printf(“Control-string”, argument-list);
Control string consists of ,
Messages to be printed on the screen.
Format specifiers to define the format for the values to be displayed.
Escape sequence characters like \n, \t etc.
Example: printf(“%d”,a);
switch(expression)
{
case constant1: block 1;
break;
case constant2: block 2;
break;
......
.....
default: default block;
break;
}
Example: for(i=10;i>=1;i--)
{
printf(“%d”,i);
}
38. Write the syntax of nested if ..else statement.
CO1)(K2)
if(condition 1)
{
if(condition2)
{
True statement1;
}
else
{
False statement 1;
}
}
else
{
False statement2;
}
39. Write the syntax of do..while statement. CO1)(K2)
do
{
Body of the loop;
}while(test condition);
40.. What are all decision control statement in C? (CO1)(K2)
There are 3 types of decision making control statements in C language. They are,
1. if statements
2. if else statements
3. nested if statements
41. What will happen if break statement is not used in switch case in C? (CO1)(K2)
∙ Switch case statements are used to execute only specific case statements
based on the switch expression.
∙ If we do not use break statement at the end of each case, program will execute
all consecutive case statements until it finds next break statement or till the
end of switch case block.
9.. What is the difference between while and do…while loop in C? (CO1)(K2)
∙ While loop is executed only when given condition is true.
∙ Whereas, do-while loop is executed for first time irrespective of the condition.
After executing while loop for first time, then condition is checked.
Part B
Questions
Part B
10. Draw a flowchart, write an algorithm to check the given number is palindrome
or not.
12. Describe the features of primitive data types and user defined data types in C.
19. Write a program using for loop to calculate factorial of a number. (CO1)(K1)
20. Write a program to check whether the given number is Armstrong or not.
(CO1)(K3)
21. Write a program to find the sum of a digit. (CO1)(K1)
22. Write a program to find the given number is positive or negative or zero.
(CO1)(K2)
23.Write a program if the word is “Programming in C” display it in reverse manner.
(CO1)(K1)
24.. Write a program to display the month in order using switch case.
(CO1)(K2)
25Write a program to print the following pattern (CO1)(K1).
*
**
***
****
26. Write a menu driven program to find the area of different shapes.
(CO1)(K2)
27. Write a program to find the sum of even number. (CO1)(K3)
Supportive Online
Certification
Certification Courses
NPTEL
Problem solving through Programming in C
https://nptel.ac.in/courses/106/105/106105171/
Coursera
1)C for Everyone: Structured Programming
https://www.coursera.org/learn/c-structured-programmin
1. Operating Systems
2. Development of New Language
3. Computation Platforms
4. Embedded Systems
5. Graphics and Games
Content beyond
syllabus
Content beyond
syllabus
Problem Solving and Algorithms
Learn a basic process for developing a solution to a problem. This process can
be used to solve a wide variety of problems.
❖ C – Sololearn
❖ https://www.coursera.org/
❖ https://www.udemy.com/
❖ https://unacademy.com/
❖ https://www.sololearn.com/
❖ https://www.tutorialspoint.com/cprogramming/index.htm
❖ https://www.w3schools.in/c-tutorial/
❖ https://www.geeksforgeeks.org/c-language-set-1-introduction
/
❖ https://www.programiz.com/c-programming
Real Time
Applications
Content beyond
syllabus
Analysis of algorithms
over time.