You are on page 1of 4

TechTics Club

RoboProbot

Robotics
Lab 2
Lab Objective: Standard IOs: PRINTF( ) and SCANF( ) plus Operators
Section: _____________ Lab Date: _________________
Student Name (ID): ______________________________________
Checked by: ____________________________ Checked Date: __________________
Remarks: ____________________________________________________________________
_____________________________________________________________________________

Objective:
1. Make student familiar with standard output and input functions in C.
2. Make student understand the use of variables and constants in programming.
3. Make student differentiate between numeric and alpha-numeric data types.
4. Make student learn different operators and their precedence rules.

Data types:

A data type is a set of values and a set of operations on those values.

Knowledge of the data type of an item (a variable or value) enables the C compiler to correctly
specify operations on that item.

int var1;
float var2;
double var3;
char var4;
Rules for writing variable name in C:

 An identifier must consist only of letters, digits, and underscores.


 An identifier cannot begin with a digit.
 A C reserved word cannot be used as an identifier.
 An identifier defined in a C standard library should not be redefined.

In C programming, you have to declare variable before using it in the program.

Variables and Constants:

If the value of an item is to be changed in the program then it is a variable. If it will never
change then that item is a constant.
A variable declaration begins with an identifier (for example, int, float, char) that tells the C
compiler which type of data stored in a particular variable.
int a = 1;
char b = ‘2’;

If we put a const keyword before a variable name in declaration, it will become a constant, as
shown
below:
const int a = 1;
const char b = ‘2’;

Format Specifiers:

The various format specifiers used in standard functions are:

Escape Sequences:

Character combinations consisting of a backslash (\)


followed by a letter or by a combination of digits are called
"escape sequences." To represent a newline character,
single quotation mark, or certain other characters in a
character constant, you must use escape sequences.
Standard Output Function:
The most common function to display something on monitor screen is printf( ).

Example:

Standard Input Function:


The input from user can be taken by the following functions: scanf( ).

Operators:
There are various types of operators that may be placed in different categories:
Example

Lab Task:
Write a program to take input a and b and display output x, where x = a2 + 2ab + b2

Home Task:

1. Write a program to calculate area (A=pi*r2) and circumference (C=2 *pi*r) of a circle,
where “r” is taken as input and “pi” must be declared as a constant.
2. Write a program to perform basic arithmetic operations which are addition, subtraction,
multiplication and division of two numbers. Prompt user about two numbers and display
results to user once calculated.

You might also like