0% found this document useful (0 votes)
20 views88 pages

AOP Unit 2 Chapter 1

MCA CHAPTER 3 BANGALOE UNIVERSITY

Uploaded by

meghanar2910
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views88 pages

AOP Unit 2 Chapter 1

MCA CHAPTER 3 BANGALOE UNIVERSITY

Uploaded by

meghanar2910
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

THE ART OF COMPUTER

PROGRAMMING
Dr. Salini Suresh
Associate Professor ,DSCASC
Unit 2 Chapter 1 : C Programming
Getting Started, Variables and Arithmetic expressions.
Input and Output: Standard input and output, formatted output- printf,
variable length argument list, formatted inputscanf.
The Elements of C :

• Character set
• C Tokens

• Character set : The character set denotes any alphabet, digit or special symbol used to
represent information in any language. In C the character set is as follows:-

• Alphabets : A, B, C,……..Z, a, b, c,……...z

• Digits : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

• Special symbols : blank , ! @ # % & * / - + : ; ‘ { } ( ) ? = < > “ ~ . _


C TOKENS

• C tokens are the basic buildings blocks in C language which are constructed together to
write a C program.
• Each and every smallest individual units in a C program are known as C tokens.
• C tokens are of six types. They are,
• Keywords (eg: int, while),
• Identifiers (eg: main, total),
• Constants (eg: 10, 20),
• Strings (eg: “total”, “hello”),
• Special symbols (eg: (), {}),
• Operators (eg: +, /,-,*)
C TOKENS

Sample Program :

int main() main – identifier


{ {,}, (,) – delimiter
int x, y, total; int – keyword
x = 10, y = 20; x, y, total – identifier
total = x + y; main, {, }, (, ), int, x, y, total – tokens
printf ("Total = %d \n", total);
}
IDENTIFIERS IN C LANGUAGE
• Each program elements in a C program are given a name called identifiers.
• Names given to identify Variables, functions ,constants, arrays, structures, etc. are examples for identifiers.
• eg.
x=10 here x is a name given to variable.
Rules:
• The first character of an identifier should be either an alphabet or underscore, which can be followed by either alphabets or
digits.
• The length of the identifiers can be upto 32 characters.(some compilers limit the length to 8 characters).
• It can contain both uppercase and lowercase letters.(C is case sensitive)
• Special characters except underscore should not be used in identifiers and successive underscores are also not allowed.
• It should be a single word without blank space.
• Keywords or reserved words cannot be used as identifiers.

Eg for identifier: Area, area, AREA are three different identifiers. Ex: _time, num1, num_2
Invalid identifier : 4num (digit should not be first char) , int (keyword), $dollar ($spl symbol)
num 1 (space not allowed)
• Keywords –
• They are also called ‘Reserved words’. These are the predefined words with special meanings which cannot be
changed.
• The keywords cannot be used as variable names.
• There are 32 keywords available in C language.
They are :-
auto default float register static volatile
break double for return switch while
case do goto short typedef
char else if signed union
const enum int sizeof unsigned
Continue extern long struct void

• Constants: does not change during the execution of a program.
It is the location in memory, referenced by an identifier that contains a data value that cannot be
changed.
• supports several types of constants. They are
• Numeric constants
• Integer constants Ex: 426, +782, -9000, -675
• Float constants(real) Ex: 426.0, 4.1, 4.1e8, 3.2e-5
• Character constants
• Single character constants Ex: ch = ‘A’ ; (This will assign character A to variable ‘ch’)
• String constants Ex:“The best way to learn programs is through practice”
• VARIABLES

Each variable represents the name of a memory location in which a value can be stored. A
variable value can be changed during program execution. Example,

monthlyhra
pop_e_89
si_int
si
• Rules to name the variables:

• Same as identifier
VARIABLES

• There are two values associated with a variable name :


• Its data value , is the actual value stored in that particular variable name. It is sometimes referred to as a variable’s “rvalue”.
• Its location value (address) , is the address in the memory at which the variable’s data values are stored. It is referred to as a
variable’s “lvalue”

• Eg. : If we have two variables X and Y & we store the values 120 and 200 in these variables &
• It is stored at memory location 65222 and 65224 respectively.
Data types

• Data types are used to inform the type of value that can be stored in a variable.

• Before using the variables, each variable must be declared to inform the types of data it can
hold in the beginning of the program.

• Syntax:

datatype var1, var2, …… varn;

Types :

2. Primitive Types -, int, float char, and void.


3. User Defined Types – struct, union, enum and typedef
4. Derived Types – pointer, array and function pointer.
Data types:

int

Intergers are whole numbers without a decimal point or any other character.
They can be preceeded by either ‘+’ or ‘-’

Example:
1828,
-3452

The number of bytes required to store an int is a system dependent.


In 16 bit machine it is 2 bytes
In 32 bit machine it is 4 bytes

Let as consider16 bit machine,

The size of the integer variable = 2 bytes = 16 bits


The range for of the integer variable -32768 to +32767

Ex: int a = 7982;


int b = -3434; Example for Invalid data: int a = 32854;
• char : Denotes character variable

A char is a single ASCII character.

A symbol enclosed within single quote is a charater.

It occupies a single byte

Example: char myval=‘A’;

char choice=‘y’;

size of a character variable = 1 byte = 8 bit

= 2 8 - 1 bits

= 255

= -128 to 127

The value that can be stored in a character variable is -128 to +127


float Means that the variable is a real number or floating point number
The number can contain a decimal point or an exponent
It occupies 4 bytes with 6 digit precision
The minimum and maximum value that can be stored in floating point
number is 3.4 x 10 -38 to 3.4 x 10 +38

Ex : float a = 23.76;
float b=-32.9931;

double means that the variable is a double precision floating point number.
Used to hold large real number
occupies 8 bytes of memory spaces (64 bits) with 14 digit precision
-308
The minimum and maximum value that can be
+308
stored in a double is 1.7 x 10 to 1.7 x 10

Example: double d1 = 1.5e28;


Quantifiers:

Quantifiers or modifiers are keywords used to alter the basic datatype on size and sign

The quantifiers that can be applied to basic data types are


• signed
• unsigned
• short
• long

Signed and unsigned are used to specify whether the variables can store both positive and negative numbers or
only positive numbers

Syntax: <modifiers> <datatype> <var1>,<var2>,…….<varn>;

Example signed int a;


long double c,d;
Declaration of variable:

• Declaration of variable informs the compiler to reserve enough space for the variable
in the memory.

• Datatype specifies what type of value the variable can hold and the number of bytes
needs to be reserved for the variable.

• Syntax
datatype variablename;

Example int a;
int c,d,e;
float temp;
Operators
Expressions
&
Type conversion
Operator
• An operator is a symbol used to indicate a specific
operation on variables in a program.

• Example : symbol “ + “ is an add operator that adds two


data items called operands.
Expression
• An expression is a combination of operands ( constants, variables,
numbers) connected by operators and optional parenthesis.

• Example :
A + B

operator
operand
Operators
• C language is very rich in operators.

• Four main classes of operators :


• Arithmetic
• Relational
• Logical
• Bit wise
Operators
• Special operators in C :
• Assignment operator
• Increment and Decrement operator
• Conditional operator
• Comma operator
• Sizeof operator
Arithmetic operators
• Following operators are used for arithmetic operations on all built in
data types :
+ (unary plus)
- (unary minus)
+ (addition)
- (subtraction)
* (multiplication)
/ (division or quotient)
% (modulus or remainder)
-- (decrement)
++ (increment)
Binary arithmetic operators
• A binary operator requires two operands to work with.

• Addition, subtraction, multiplication, division, and


modulus or remainder operator falls in this category.

• The evaluation of binary operator is LEFT associative that is


in an expression operators of same precedence are
evaluated from left to right.
Order of evaluation
• For a complex expression it becomes difficult to make
out as to in what order the evaluation of sub expression
would take place.

• In such case we check out the precedence and


associativity of operators in the expression.
Precedence
Defines the order in which an expression is evaluated

operators precedence

*,/,% High and are on same level

+,- Lower and are on same level


Example
int x; output:
x= 7 + 3 * 5; x = 22

int x; output:
x= ( 7 + 3) * 5; x = 50

int x; output:
x= 7 / 3 * 5; x = 10
Modulus operator ( % )
• This operator has same priority as that of multiplication and division

• a % b = output is remainder after performing a / b

• Example:
7 % 10 = 7
7%1 = 0
7%2 = 1
7%7 =0
Exercise
int y;
y = 10 % 4 * 3;
Output:
6

int y; Output::
y = 3 * 10 % 4; 2
Important
• Modulus operator ( % ) : It produces remainder of an integer
division. This operator cannot be used with floating point
numbers.

int main( ){
float f_1=3.2, f_2=1.1, f_3 ;
f_3 = f_1 % f_2;
printf(“ %f”, f_3);
return 0; }

Output: error at line 3


illegal use of floating point
Invalid arithmetic expressions
• a * + b : Invalid as two operators cannot be used in
continuation.

•a( b * c ) : Invalid as there is no operator between a and


b.
Unary arithmetic operators

• A unary operator requires only one operand or data item.

• Unary arithmetic operators are:


• Unary minus ( - )
• Increment ( + +)
• decrement ( - - )
Unary minus ( - )
• It is written before a numeric value, variable or expression

• Its effect is NEGATION of the operand to which it is applied.

• Example:
- 57 - 2.933 -x

-( a * b) 8 * ( - ( a+b))
Increment operator ( ++ )
• The increment ( ++ ) operator adds 1 to its operand.
n = n +1 ; => ++ n ;

• Postfix Increment ( n ++) : It increments the value of n


after its value is used.

• Prefix Increment ( ++ n) : It increments the value of n


before it is used.
Example 1
1. x = n++ ;
2. x = ++n ;
Where n = 5;

• case 1: It sets the value of x to 5 and then increments


n to 6.
x = 5 and n= 6

• case 2: It increments the value of n and then sets the


value of x to 6.
x = 6 and n =6
Example
sum=x++; sum = ++x;

Sum = x; x=x+1;
x=x+1; Sum=x;
b = 10
a = 11
Here first value of a(i.e., 10) is
assigned to b and then value of a is
incremented. So b = 10 and a = 11 is
printed

a = 10
a = 11
Here in the first printf statement
a value gets printed after that its
value gets incremented, which is
shown in second printf statement
Decrement operator
• The decrement ( - - ) operator subtracts 1 from its operand.
j=j-1; => -- j;

• Postfix decrement ( y - -) : In this case value of operand is fetched


before subtracting 1 from it.

• Prefix decrement ( - - y) : In this case value of operand is fetched after


subtracting 1 from it.
Example
sum=x--; sum = --x;

sum = x; x=x-1;
x=x-1; sum=x;
Precedence of Arithmetic operators

Highest : ++ --
- (unary minus)
* / %
Lowest + -

Operators on same level of precedence are evaluated by the complier


from left to right.
Relational & Logical operators
• A relational operator is used to compare two values and the result of
such operation is always logical either TRUE ( 1 ) or FALSE ( 0 ).

< less than x<y


● > greater than x>y
● <= less than or equal to x <= y
● >= greater than or equal to x >= y
● == is equal to x==y
● != is not equal to x != y
Exercise
• Suppose that i, j, and k are integer variables whose
values are 1, 2 and 3, respectively.

Expression Value Interpretation


i<j 1 true
(i + j) > = k
1 true
(j + k) > (i + 5)
0 false
k!=3
0 false
j==2
1 true
Logical operator

▪ A logical operator is used to connect two relational


expressions or logical expressions.

▪ The result of logical expressions is always an integer value


either TRUE ( 1 ) or FALSE( 0 ).(67 > 5) returns 1
(67 = = 5) returns 0
&& Logical AND x && y
|| Logical OR x || y
! Logical NOT !x
Logic AND
• The output of AND operation is TRUE if BOTH the
operands are true.

Example: ( 8 < 7 ) && ( 6 > 7)

0 && 0

False ( 0 )
Example 2

(8 > 7) && (6 < 7)

1 && 1

True ( 1 )
Logical OR
• The result of a logical or operation will be true if either operand is
true or if both operands are true.

(8 < 7) | | (6 > 7) is false

(8 > 7) | | (6 > 7) is true

(8 > 7) | | (6 < 7) is true


Logical NOT

• The Logical NOT ( ! ) is a unary operator. It negates the value of the logical expression or
operand.

• If value of X = 0 !X=?
!X=1

• ! ( 5 < 6 ) || ( 7 > 7 ) = ???


! ( 1) || ( 0) = ! 1 = 0 -> false

• ! ( 5 > 3) = ??
-> 0 -> false

• !(34 >= 765) = ??


-> 1 -> True.
x = 10 and y = 25
( x > = 10 ) && ( x < 20 ) True

( x >= 10) && ( y < = 15) False

True
( x = = 10 ) && ( y > 20 )
True
( x==10) || ( y < 20)
True
( x ==10) &&( ! ( y < 20) )
Precedence & Associativity highest
!(logical NOT) ++ -- sizeof( ) Right to left P
* (multiplication) / ( division) %( Left to right R
modulus) E
C
+ - (binary ) Left to right
E
< <= > >= Left to right D
==(equal to) !=( Not equal to ) Left to right E
&&(AND) Left to right N
C
|| (OR) Left to right E
? : (conditional ) Right to left
= += - = * = /= %= Right to left
, Left to right lowest
• Suppose that
j = 7, an integer variable
f = 5.5, a float variable
c = ‘e’
Interpret the value of the following expressions:

( j >= 6) && (c = = ‘e’) 1


( j >= 6) | | ( c = = ‘e’) 1
(f < 11) && ( j > 100) 0
(c ! = ‘p’) | | ((j + f) <= 10) 1
f>5 1
!(f > 5) 0
j<=3 0
!( j <= 3) 1
j > (f +1) 1
!( j > (f +1)) 0
• Suppose that
j = 7, an integer variable
f = 5.5, a float variable
c = ‘w’
Interpret the value of the following expressions:

j + f <= 10 0
j >= 6 && c = = ‘w’ 1
f < 11 && j > 100 0
!0 && 0 | | 0 0
!(0 && 0) | | 0 1
Assignment operator

• It is used to assign the result of an expression to a variable.

• variable_name = expression (or) value;

Ex: a=20;
b=(2+5)*3;
Two cases of assignment
• Multiple assignment:
int j=k=m=0;
▪ Compound assignment:
j= j+10; this expression can be written as
j + = 10;
similarly
m= m-100; is equivalent to m - = 100;
Conditional Operators (?:)

• Conditional operators are called ternary operators as they use three


expressions. It is also called as the shorthand version of the if-else construct.

Syntax : result=exp1?exp2:exp3; or exp1?exp2:exp3;

• If exp1 is true then exp2 is evaluated else exp3 is evaluated.


• Conditional operator is also used to make an assignment.
• EX : y=(x>5?2:3);

If x is greater than 5 then 2 will be assigned to y


otherwise 3 will be assigned to x

Ex : (total>=35?printf( “PASS”):printf(“FAIL”));

• Here the condition whether total is greater or equal to 35 is checked


• and if it is true, PASS will be printed on the display
• otherwise FAIL will be displayed.
• comma operator:
Used to link the related expressions together.
syntax:
(exp1, exp2, …….expn);

Example: comma operator:


temp=a; (temp=a,a=b,b=temp);
a=b;
b=temp;
• int a, b=4, c, d;
d=(a=b+3, c=a+2);

Comma operator has lowest precedence, it is evaluated left to right.


first a=b+3 is evaluated so a becomes 7
then a+2 is evaluated c=7+2=9
which is assigned to d
sizeof()

Returns number of bytes required / used for operand specified


Syntax:
sizeof(operand);
Example:
sizeof(char); // 1 byte
sizeof(int); // 2 byte
float a;
sizeof(a); // 4 bytes
Bitwise Operators
Corresponding bits of both operands are combined by the usual logic operations.

& – AND ~ – Complement


• Result is 1 if both • Each bit is reversed
operand bits are 1
| – OR << – Shift left
• Result is 1 if either Moves the bits to the left, it discards
operand bit is 1 the far left bit and assign 0 to the
^ – Exclusive OR rightmost bit
• Result is 1 if operand
bits are different >> – Shift right
Moves the bits to the right, it
discards the far right bit and assign 0
to the leftmost bit
• If x=5 and y=3 then bitwise AND(&) operation x&y is shown below

x -> 00000101
y-> 00000011

X&y-> 00000001
• If x=5 and y=3 then bitwise OR(|) operation x|y is shown below

x -> 00000101
y-> 00000011

X|y-> 00000111
• If x=5 and y=3 then bitwise Exclusive OR (XOR ^) operation x ^ y is
shown below

x -> 00000101
y-> 00000011

x^y-> 00000110
• Bitwise compliment (~)
• If x=5 then bitwise compliment (~) operation produces one’s
compliment of that number is shown below

x -> 00000101
~x-> 11111010
• Right shift operator (>>)
• Moves the bits to the right, it discards the far right bit and assign 0 to the
leftmost bit
x>>n;
a=90;
the binary representation of a is
a -> 01011010
a=a>>3;
a-> 00001011;
• Left shift operator (>>)
• Moves the bits to the left, it discards the far left bit and assign 0 to the
rightmost bit
x<<n;
a=10;
the binary representation of a is
a -> 000010101
a=a<<3;
a-> 01010000;
Type conversion
• Used to convert a value of one datatype to another
• Two types:
• Implicit type conversion
• Explicit type conversion
• Implicit type conversion:
• Known as automatic type conversion
• Type conversion which are automatically carried out by
computer itself is known as implicit type conversion

• Example:
int a;
float b=5.0;
a=b/2; now a=2 of type int
Type conversion
• Implicit type conversion
• When the variable or constant of lower type is converted to
higher type is called promotion.
int i=5;
float f;
f=i; // i is lower type and f is higher type and value of f=5.0

• When the variable or constant of higher type is converted to


lower type is called demotion.
int i;
float f=3.14;
i=f; // i is lower type and f is higher type and value of i=3
(integer)
Type conversion
• Explicit Type conversion:

Explicitly convert the value of one type to another

Syntax: (data type)expression;

Example: x=(float) (5+4);

The expression (5+4) is explicitly converted to


float by the casting operator (float)
Input and Output Functions
Input / Output functions
Input function is used to read input from the user through standard input device (keyboard)
Output function if to display the output in the monitor

The input/ output functions in c is classified into


Formatted I / O function
Unformatted I / O function

Formatted Input function : scanf()


Formatted Output function : printf()

Unformatted Input function : getch(), getche(), getchar(), gets()


Unformatted Output function : putch(), putchar(), puts()
Input function

scanf()
• it is a formatted input function to read input through standard input device
• stores them at the address of the variable in the memory.
• It is a buffered function
i.e. data is supplied to the program only when enter key is pressed.

Syntax : scanf(“format specifiers”, addresses of variables);

e.g.: scanf(“%d”, &a);


will read an integer value to the address of the variable a.

Note : ‘&’ is known as the ADDRESS-OF operator


scanf(“%d %f”, &num1, &num2);
Input function

scanf()

Format specifiers – Format specifiers always starts with the percentage[%] sign

followed by a character to represent different data types. The list of format specifiers are:-

• %d - int

• %f - float

• %c - single character

• %s - string

• %ld - long int

• %lf - double

• %u - unsigned integer
Output function

printf()

Formatted output function- This is a function which transfers the data in various formats
to the output device (monitor).

Syntax : printf(“format string”, list of variables);


e.g.: printf(“The number is %d”, a); will print the integer stored in variable a.

format string includes


1. User specified strings which will be printed as it is

2. Format specifier like %d, %c, %f etc along with optional field width

3. Escape sequences.
Output functions
printf()

Escape sequences - it begins with back slash(\) followed by one or more character.

backslash is considered as ‘escape’ character,

it causes an escape from the normal interpretation of a string,

so that the next character is recognised as one having special meaning.

\a System Alarm
\n New line
\t Horizontal Tab
\” Double Quotes
\’ Single quotes
\0 Null (End Of String)
\\ Back Slash Character Itself.
Output function

printf()
Example:

printf(“ Good morning !!!”);

printf(“\n The value of a is %d”, a);

printf (“\n\n The value of a = %d and b= %f “ , a, b);

printf (“\n\n The value of a = %d \t b= %f “ , a, b);

• Field width specification for integer

Syntax:

%WC ( right justified ) %-WC (left justified)

W – total number of column to be printed ( total width)

C – format specifier (%d, %c, %f …..)


Output function

printf()

Example : let a= 254

printf(“%5d”, a); 2 5 4
printf(“%-5d”, a); 2 5 4

printf(“%2d”, a); 2 5 4

Let a=86.123 printf(“%7.2f”, a); 8 6 . 1 2

printf(“%-7.2f”, a); 8 6 . 1 2

printf(“%7.3f”, a); 8 6 . 1 2 3
Output function

printf()

Example : let a= “COMPUTER SCIENCE”

printf(“%s”, a); C O M P U T E R S C I E N C E
Let a=‘A’ printf(“%4c”, a);
A
printf(“%-3c”, a);
A

let a= “COMPUTER”

printf(“%s”, a); C O M P U T E R
printf(“%5s”, a); C O M P U T E Rwhen space is less, it will ignore width
printf(“%12s”, a); C O M P U T E R
printf(“%12.6s”, a); C O M P U T
printf(“%-12s”, a); C O M P U T E R
Unformatted Input function

getchar()

• This is a function which accepts only a single character from the keyboard and
assigns that to the variable.

• This function echoes the character on the screen.

• It is a buffered function i.e. data is supplied to the program only when enter key is
pressed.

• This function does not require format specifiers.


Syntax : getchar()
Example: char ch;
ch=getchar();
getchar()

Ex: getchar()
Syntax: variable=getchar();
Ex.1: int ch; Ex.2: char ch;
ch=getchar(); ch=getchar();
In Ex:1 The function getchar() accepts the ASCII value of the character pressed i.e. if A is
pressed, the value 65 is assigned to the variable ch as it is declared as int

In Ex.2 The character is assigned to ch as it is declared as char.


Unformatted Input function

getch()

C provides single character input functions getch() declared in “conio.h” header file

getch() is unformatted and unbuffered input function

i.e. this function supplies the data to the program immediately without waiting for the enter
key to be pressed.

This function does not require format specifiers

The character is not echoed on the screen with getch() function.

Syntax : getch()
Example: char val;
val = getch();
Unformatted Input function
getche()

getche() function is also a unformatted input function and declared in “conio.h” header file.

It reads a single character from the keyboard and returns it immediately without even waiting for
enter key.

The character is echoed on the screen with getche() function.

Syntax : getche()
Example: char val;
val = getche();
Unformatted output function

1. putchar(): This function is used to print one character on the screen

2. putch(): The putch() function displays single character through the standard output device like
monitor..

• Syntax : putchar(variable_name);

putch(variable_name);

Example: char choice=‘y’;

putchar(choice);

putchar(‘A’);

putch(choice);

putch(‘A’);
Variable length arguments
Variable length arguments is a programming construct that allows programmers to
pass n number of arguments to a function.
also known as variable length argument as var-args.

a function with a varying number of arguments is defined by using a trailing ellipsis


(...) in the argument list,
declaring that there may be additional arguments, number and type unspecified.

Syntax of using variable length arguments


return_type function_name(parameter_list, int num, ...);

• Return type - Specify function return type.


• Function name - Name of the function.
• argument data types must be specified in-line;
• int num –specifies the number of variable length arguments passed.
• …… is called ellipsis
e.g., int fnv(int x, ...);
Variable length arguments
The library function functions like printf() and scanf() accept any
number of arguments passed.

The prototype of printf() is:

int printf(char *format, arg1, arg2, ...);

you can pass n number of arguments to printf


Variable length arguments

< stdarg.h> -> header file defines the libraries to handle routines with
variable numbers of arguments

• Preprocessor macros included from are used to access the argument


list for this kind of function.

• va_list - Data type to define a va_list type variable.


• va_start - Used to initialize va_list type variable.
• va_arg - Retrieves next value from the va_list type variable.
• va_end - Release memory assigned to a va_list variable.
#include <stdio.h>
#include <stdarg.h>

double average(int num,...) {

va_list arguments; // declares a list that can be used to store a variable number of arguments.
double sum = 0.0;
int i;

/* initialize valist for num number of arguments */


va_start(arguments, num);

/* access all the arguments assigned to valist */


for (i = 0; i < num; i++) {
sum += va_arg(arguments, int);
}
/* clean memory reserved for valist */
va_end(arguments );

return sum/num;
}

int main() {
printf("Average of 2, 3, 4, 5 = %f\n", average(4, 2,3,4,5));
printf("Average of 5, 10, 15 = %f\n", average(3, 5,10,15));
}

You might also like