ASSIGNMENT #02

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

ASSIGNMENT # 02

ROLL# = 20BSCS-036

DATE= 30-4-2021

NAME= Mir Aslam Mubarak

SUBJECT= Programming Fundamental (p.f)

TEACHER= DR: AIJAZ AHMED

DEPARTMENT= BS(CS)

-------------------------------------------------------------------------------------------------------------------

Q.1 Describe the following


Data Typesterms with which
are the terms examples.
are used to declare the variable or any type of
values in programming.
1. DATA TYPES:-
for eg; To decleare the intiger (1,2,3,.......) we have to type " int a; " the format string of " int "is ("%d";a).

other types of data types are (Float (float a;) ("%f",a)), (Double (double a;) ("%l",a)), (Character (char
a;) ("%c",a)), (String (char a; "OR" char a[10];) ("%c",a)).

2. FORMAT SPECIFIER AND ESCAPE SEQUENCES:-


The format specifier tells the printf()
where to put a value in a string and what format o use in printing those values. The "%d" tells the
printf() to print the value as a decimal integer.

eg;

the answer will be " I HAVE 10 BALOONS".


The space sequences allows to control the output of the program.
eg;

(For New line, " ¥n "), ( For Tab, " ¥t "), (For Backspace, " ¥b "), (For Return, " ¥r "), (For Backslash," ¥¥ "),
(For Single Qautaion mark, " ¥' "), (For double Qautaion mark, " ¥" ").

3. PREPROCESSOR DIRECTIVES:-
Preprocessor directives also known as library in the
program it helps the program to read the procedure that how to perform the task.

eg; (#include<stdio.h>), (#include<conio.h>), (#include<math>).

4. ARTHEMATIC, RELATIONAL & LOGICAL OPERATORS:-


ARTHMETIC OPERATORS: Arthematic operators are the Arthmetic operations which are used for
Addition, Substraction, Division, Multiplication and other Arthmetic operations and are listed below.

RELATIONAL OPERATORS: Relational operators are the Relational operations which are used to
check the condition whether it is true or false, to check that is it greater or lesser,e.t.c and are listed
below.

Lets suppose a=6, b=7

Operator Description Example

== checks that the both operands are equal or not (a==b) is not true
if yes then condition becomes true

!= checks that the both operands are equal or not (a!=b) is true
if the values are not equal then conditin is true

> checks that the value of left operand is greater (a>b) is not true then
the value of right operand then the condition becomes true

< checks that the value of left operand is less then (a<b) is true
the value of the right operand then the condition
becomes true

>= checks that the value of left operand is greater (a>=b) is not true
then or equal to the value of right operand then
the condition becomes true

<= checks that the value of left operand is less (a>=b) is true
then or equal to the value of right operand then
the condition becomes true

LOGICAL OPERATORS:

Operator Description Example

&& called logical AND operator, if both operands are (a&&b) is false
non-zero, then condition becomes true.

|| called logical OR operator, if any of the two operands (a||b) is true


is non-zero then the condition is true

! called logical NOT operator. use to reverse the logical !(a&&b) is true
state of its operand, if a condition is true then the
logical NOT operator will makes it false.
5. SIMPLE IF, IF-ELSE & ELSE-IF STATEMENTS:-
SIMPLE IF STATEMENT: An if statement consists of a boolean expression followed by one or more
statements.

IF-ELSE STATEMENT: An if-else statement can be followed by an optional else statement, which
executes when the boolean expression is false.

ELSE-IF STATEMENT: An if-else statement can be followed by an optional else if.......else statement,
which is very useful to test various conditions.
6. SWITCH STATEMENT:-
A switch statement allows a variable to be tested for equality against a
list of values. Each value is called a case, and the variable being switched on is checked for each switch
case.

7. FOR LOOP IN C :-
A for loop is a repeatation control structure that allows you to eecute a
specific number of times.

8. WHILE LOOP IN C :-
A while loop in C programming language repeatedly executes a target
statement as long as a given condition is true.

9. DO....WHILE LOOP IN C :-
Unlike for and while loops, which test the loop condition at the top of
the loop, the do....while loop in C programming language checks its condition at the bottom of the
loop.

A do...while loop is simillar to a while loop, except that a do...while loop is guaranteed to execute at
least one time.
10. ARRAY (Declearing, Initializing, Accessing) :-
An Array is used to store a collection of data, but it is often more useful
to think of an array as a collection of variables of the same type.

DECLARATION OF AN ARRAY:

Its syntax is:

Data_type of array_name[size];

int a[10];

INITIALIZATION OF AN ARRAY:

After decleration element of local array has garbage value.

If it is global or static array then it will be automatically initialize with zero.

An explicity it can be initialize that

int a[5]={20,30,40,50,60}

ACCESSING OF ARRAY ELEMENTS:

printf("%d",a[0]);

OR

for(i=0;i<5;i++)

printf("%d",a[i]);

}
THE END

You might also like