Professional Documents
Culture Documents
UNIT 1
UNIT 1
• Functions
Flowchart
Algorithm
STEP 1: Start Flowchart
COMPUTE sum=A+B
PRINT sum
STOP
Example 2 - To print first 10 natural
numbers
STEP 1: Start
Algorithm
STEP 2: Set I=1
STEP 3: while I<=10, Repeat Step 4 and 5
Logic:
STEP 4: Print I
I=1 STEP 5: I=I+1
while I<=10 BEGIN
STEP 6: Stop
Print I SET I=1
I=I+1 WHILE I<=10
PRINT I
I=I+1
ENDWHILE
END Pseudoco
de
Programming Strategies
• Programming refers to the method of creating a sequence of instructions
to enable the computer to perform a task.
• A programming practice refers to the way of writing a program and is
used along with coding style guidelines.
• Some of the commonly used programming practices include
• Top-down programming,
• Bottom-up programming,
• Structured programming, and
• Object Oriented Programming
Top-down programming
#include<stdio.h>
int main()
{
printf("\n Welcome to the world of C ");
return 0;
}
Identifier
• Identifiers are names given to program elements such as variables, arrays and functions.
• Integers are whole numbers that can have both zero, positive and
negative values but no decimal values. For example, 0, -5, 10
• We can use int for declaring an integer variable.
• Example :int id;
• Here, id is a variable of type integer.
• You can declare multiple variables at once in C programming. For
example,
• int id, age;
Example
#include <stdio.h>
#include <stdio.h>
int main()
int main()
{ {
int a=10; int a=10,b=20,c;
int b=20; c=a+b;
printf("answer:%d",c);
int c;
return 0;
c=a+b; }
printf("answer:%d",c);
return 0;
}
Character
• Keyword char is used for declaring character type variables.
• For example,
• char test = 'h';
• The size of the character variable is 1 byte.
Example
#include <stdio.h>
int main()
{
char test = 'h';
printf("answer:%c",test);
return 0;
}
Float and Double
result = a /
Divide / a / b
b
3
result = a +
Addition + a + b
b
12
Subtracti - a - b
result = a –
6
on b
result = a %
Modulus % a % b
b
0
Relational Operator
Also known as a comparison operator, that compares two
values.
Expressions that contain relational operators are called
relational expressions.
Relational operators return true or false value, depending on
whether the conditional relationship between the two operands
holds or not.
OPERATOR MEANING EXAMPLE
< LESS THAN 3 < 5 GIVES 1
OPERATOR MEANING
A B A &&B A B A || B
A !A
0 0 0 0 0 0
0 1
0 1 0 0 1 1
1 0 0 1 0
1 0 1
1 1 1 1 1 1
Unary Operator
Unary operators act on single operands.
C language supports three unary operators. They are unary minus,
increment and decrement operators.
When an operand is preceded by a minus sign, the unary operator negates
its value.
The increment operator is a unary operator that increases the value of its
operand by 1. Similarly, the decrement operator decreases the value of its
operand by 1. For example,
int x = 10, y; y = ++x;
y = x++;
+ - Addition/subtraction left-to-right
|| Logical OR left-to-right