Sei sulla pagina 1di 3

Q.

1 Write algorithm for the following :

a) to check whether an entered number is odd / even.


b) to calculate sum of three numbers.

Answer 1)a . This is algorithm for checking whether an enter number is


odd/even.

Step 1: take the number from the user .


Step 2: if the number is fully division by 2 and remainder equal to zero
then display
then enter number as even .
Step 3: if the number is not fully division by 2 and remainder not equal to
zero then
display number as odd.

Answer 1)b . This is algorithm for for calculating the sum of 3


number
3
The formula for the sum of 3 number can be sum=∑number i
I=1
Step 1: let the sum be initially set to 0 .
Step 2: let I be initially 1
Step 3: take the ith number from the user
Step 4: add the ith number to the sum
Step 5: increase the value at I by 1.
Step 6: check if the value of I is less than or equal to 3 ; then go to
step 4.
All 3 number are similarly entered by the user , until I
becomes greater than 3 . than go to step 7.
Step 7: output the sum .
Q. 3 Write short notes on the following :

a) C Variables b) C data types

a) VARIABLES :

A variables is a data name that may be used to store a data value . unlike
constant that remain unchanged during the execution of a program , a
variables may take different values at different times during execution .

A variable name can be chosen by programmer in a meaningful way as to


reflect its function or nature I the program .

Some example :-

Average , height, total , counter_1 , class_ strength .

Variables names may consist of letters, digits and underscore ( _ ) character ,


subject to the following condition .

1. they must be began with letter . some system permit underscore as the
first letter .
2. ANSI standard recognizes a length of 31 character . however the
length should not be normally more than eight character . since only
the first eight character are treated as significant by many compiler .
3. uppercase and lower case are significant . that is the variable Total is
not the same as total or TOTAL .
4. the variable name should not be a keyword .
5. white space is not allowed .

some example of valid variable names are :

johan , value , t_raise , delhi , x ] , ph_value , mark , sum1 .


invalid example include :

.123 , ( are) , % , 25th

b) DATA TYPES

C language is rich in its data types . storage representation and machine


instruction to handle constant differ from machine to machine . the variety
of data types available allow the programmer to select the type
appropriate to the needs of the application as well as the machine ANCI C
supports for classes of data types :

1. primary ( or fundamental ) data type .

2. user defined data type .

3. derived data types.

4. empty data type .

1. primary ( or fundamental ) data type :-

INTEGRAL TYPE

Potrebbero piacerti anche