0% found this document useful (0 votes)
15 views32 pages

C Notes

The document provides an introduction to the C programming language, detailing its structure, programming rules, character set, keywords, identifiers, constants, variables, data types, and expressions. It emphasizes the importance of functions, the main() function, and user-defined functions in C programs. Additionally, it outlines the syntax for declaring and initializing variables, as well as the various operators used in C programming.

Uploaded by

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

C Notes

The document provides an introduction to the C programming language, detailing its structure, programming rules, character set, keywords, identifiers, constants, variables, data types, and expressions. It emphasizes the importance of functions, the main() function, and user-defined functions in C programs. Additionally, it outlines the syntax for declaring and initializing variables, as well as the various operators used in C programming.

Uploaded by

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

Introduction to Programming

Introduction:

⮚ C is a popular general purpose programming language. C language has been designed and developed by Dennis Ritchie at Bell Laboratories in 1972.

⮚ This language is associated closely with Unix operating system. The source code for the Unix operating system is coded in C.

⮚ C runs under a number of operating system includes MS DOS. C programs are efficient, fast and highly portable i.e.

⮚ C programs written on one computer can run on another with little or no modifications. C functions are building blocks in which all programming activities are incorporated.

1. Structure of a c program:
Each C program contains a number of several building blocks know as functions. Each function of it performs task independently. A function is subroutine that may consist of one or more
statements.
An C program comprises of the following section

Include header file section

Global Declaration section

/* Comments */
main( ) function name
{
/* Comments */
Declaration part
Executable part
}
user_defined functions
{
/* Comments */
Declaration part
Executable part
}

⮚ Include header file section: C program depends upon some header files for function definition that are used in program. Each header file by default is extended with .h . The file

should be included using # include directive as given below.


Ex: - #include<stdio.h>
#include<conio.h>
#include<math.h>

⮚ Global declaration: This section declares some variables that are used in more than one function. These variables know as global variables. These variables must be declared outside

of all the functions.

⮚ Function main: Every program written in C language must be contain main() function. Empty parentheses after main are necessary. The function main () us the starting point of every

‘C’ program. The Execution of the program always begins with the function main (). The program execution start with the opening brace “ { “ and end with the closing “ } “. Between these two
braces the programmer should declare the declaration ad the executable part.

⮚ Declaration part: The declaration part declares the entire variables that are used in executable part. The initializations of variables are also done in this section. The initialization

means providing initial value to the variables.

⮚ Executable part: This part contains the statements following the declaration of the variables. This part consists a set of statements or a single statement. These statements are enclosed

between the braces.

⮚ User defined functions: The functions defined by the user are called user-defined functions. These functions are generally defined after the main () function. They can also be defined

before main () function. This portion is not compulsory.

Page | 1
Introduction to Programming

⮚ Comments: Comments are not necessary in the program. However, to understand the flow of program the programmer can include comments in the program. Comments are to be

inserted by the programmer.


The comments are nothing but some kind of statements which are placed between the delimiters “/* ….. */” . The compiler does not execute comments.
Single line comments //……..
Ex:
/ * simple C program */
#include<stdio.h> /* include file section */
void main() /* main function */
{
/* first C program its follows the structure */ /* comments */
printf(“\n welcome to c “); /* statements */
printf(“\n first c program “);
}
2. PROGRAMMING RULES:
A programmer while writing a program should follow rules.
All statements should be written in lower case letters. Upper case letters are only used for symbolic constants.

Blank spaces my be inserted between the words. The improves the readability of statements. However, it is not used while declaring a variable, key words, constant and function.

It is not necessary to fix the position of statement in the program in the program i.e. the programmer can write the statement any where between the two braces following the

declaration part. The user can also write one or more statements in one line separating them with a semicolon “ ; “ . Hence, it is often called a free from language. The following statements are
valid.
a=b+c;
d=b*c;
or
a=b+c; d=b*c;
in c programming language every statement end with ;
The opening and closing braces should be balanced i.e for example, if opening braces are five then closing braces should also be five.

3. THE C CHARACTER SET
The characters used to form words; numbers and expressions depend upon the computer on which the program runs. The characters in C are classified in the following categories.
letters ( Cap A to Z small a to z)

digits ( all decimal digits 0 to 9 )

white spaces (blank, horizontal tab, vertical tab, new line, from feed)

special characters

Special Characters
, Comma & Ampersand . period or dot
^ caret ; semi-colon * asterisk
: colon - minus ` apostrophe
+ plus “ quotation mark < less than
! exclamation mark > grater than Vertical bar |
/ slash ( ) parenthesis left/right [ ] bracket left/right
\ back slash { } braces left/right ~ tilde
% percent _score # number sign or hash
$ dollar = equal to ? question mark
@ at the rate
DELIMITERS: language pattern of C uses special kind of symbols, which are called as delimiters. They are given bellow

Page | 2
Introduction to Programming

Delimiters Use

: colon Useful label

; semi colon Terminates statement

( ) parenthesis Used in expression and function

[ ] square bracket Used for array declaration

{ } curly brace Scope of statement

# hash Preprocessor directive

, comma Variable separator

4. MTHE C KEYWORDS
The C keywords are reserved words by the compiler. All the C keywords have been assigned fixed meaning. The keywords cannot be use as variable names because they have been assigned fixed
jobs. However, few C compilers allow to construct variable names, which exactly coincides with the keywords. It is suggested not to mix up keywords with variable names. The C keywords are
listed in table.

auto break case char const continue

default do double else enum extern

float for goto if int long

register return short signed sizeof static

struct switch typedef union unsigned void

volatile while

Additional keywords for Borland C

asm cdecl far huge interrupt near pascal

IDENTIFIERS
Identifiers are names of variables, functions, and arrays. They are user-defined names, consisting of sequence of letters and letters and digits, with the letter as the first character. Lowercase case
letters are preferred. The upper case letters are also permitted. The “ _ “ under score symbol can be used as an identifier.
Ex:
#define N 10
#define a 15
Here, ‘N’ and ‘a’ are user-define identifiers.
5. CONSTANTS
The Constants in C are applicable to the values, which do not change during the execution of a program. There are several types of constants in C. they are classified in to the following groups as
given in table.
A.
Numerical Constants
1. C decimal
Integer constants: These are the sequence of numbers from 0 to 9 without constants
points or fractional part or any other symbols; it requires minimum two bytes and maximum four
bytes. Integer constants could either be positive or negative or my be zero.
Ex: 24, 30, +40, -13
2. Real constant: Real constants are often known as floating point constants. Integer constants are unfit to represent many quantities. Many parameters or quantities are defined not only in
integers but also in real numbers. For example, length, prize, distance. Are measure in real numbers.
|Ex: 2.6, 5.234, 3.14 etc., Numerics Constants Character Constants
B.
Character Constant
1. Single character constant: A character constant is a single character. They are also represented with single digit or a single special symbol or white space enclosed with in a pair of
single quote marks
Integer constants Single Character
Ex: ‘b’, ‘9’, ect.,
Real constants String Constants
2. String constant: String constants are sequence of characters enclosed within a double quote marks. The string may be a combination of all kind of symbols.
String Constants
Ex: “hello”, “india”, “567”, “a”

Page | 3
Introduction to Programming

Creating constants in C

In a c programming language, constants can be created using two concepts...

1. Using the 'const' keyword


2. Using '#define' preprocessor

Using the 'const' keyword

We create a constant of any datatype using 'const' keyword. To create a constant, we prefix the variable declaration with 'const' keyword.
The general syntax for creating constant using 'const' keyword is as follows...

#define CONSTANTNAME value

const int x = 10 ;

Here, 'x' is a integer constant with fixed value 10.

Example Program :

#include<stdio.h>
#include<conio.h>
void main(){
int i = 9 ;
const int x = 10 ;
i = 15 ;
x = 100 ; // creates an error
printf("i = %d\nx = %d", i, x ) ;
}

The above program gives an error because we are trying to change the constant variable value (x = 100).

Using '#define' preprocessor

We can also create constants using '#define' preprocessor directive. When we create constant using this preprocessor directive it must be defined at the beginning of the program (because all the
preprocessor directives must be written before the global declaration).
We use the following syntax to create constant using '#define' preprocessor directive...

#defind CONSTANT NAME value

Example

#define PI 3.14

Here, PI is a constant with value 3.14

Example Program

#include<stdio.h>
#include<conio.h>
#defien PI 3.14
void main(){
int r, area ;
printf("Please enter the radius of circle : ") ;
scanf("%d", &r) ;

Page | 4
Introduction to Programming

area = PI * (r * r) ;
printf("Area of the circle = %d", area) ;
}

Variables :
When a program is executed, may operations are carried on the data. The data types are integers, real or character constants. These data are stored in the memory and at the time of execution
different operation are performed on them. Variable is name given to the memory location.
A variable is data name used to storing a data value. Its value may be changed during the program execution. The value of the variable keeps on changing during the execution of a
program. A variable name may be declared based on the meaning of the operation. Some meaningful variable names are height, average, sum, add, mul, div etc.,
Rules for defining variables:
● They must begin with a character without spaces but underscore to permit.
● The length of the variable varies from compiler to compiler. Generally most of compilers support 8 characters excluding extension.
● The variable should not be a C keyword
● The variable names may be a combination of uppercase and lowercase characters. For example suM and sum but both are not same.
● The variables name should not start with a digit.

6. DATA TYPES
All compilers offer different data types. This enable the programmer to select the appropriate data type as per the need of application. Generally data is represented using numbers or characters. The
numbers may be the integer or real. The different compilers supports the different data types Those are given bellow

s.no Data type Keyword Size in bytes Format specifier Range

1 character char 1 %c -128 to 127

2 Signed character signed char 1 %c -128 to 127

3 Unsigned character unsigned char 1 %c 0 to 255

4 Integer int 2 %d -32768 to 32767


(10)10=(1010)2

5 Signed integer signed int 2 %d -32768 to 32767

6 Unsigned integer unsigned int 2 %u 0 to 65535

7 Short integer short int 2 %i or %d -32768 to 32767


(10)10=(1010)2

8 Long long 4 %ld -2147483648 to 2147483647


-38
9 Float float 4 %f or %g 3.4 e to
+38
3.4 e
-308 e +302
10 double Double 8 %lf 1.7 e to 1.7
-4932 +4932
11 Long double long double 14 %lf 3.4 e to 1.1 e
7.
DECLARING VARIABLES:
The declaration of variables should be done in the declaration part of the program. The variable must be declared before they are used in the program. Declaration provided two things 1) compiler
obtains the variable name 2) it tells to the compiler data type of the variable being declared and helps in allocating the memory. The syntax of the declaring a variable is as follows
Syntax: data_type variable_name;
Ex: int age; float average; char a;
int a,b,c; float sum,mul,div; char a,b,c;

8. INITIALIZING VARIABLES
Variable declared can be assigned or initialized using a assignment operator “= “. The declaration and initialization can also be done in the same line.
Syntax :- variable_name=constant;
Data_type variable_name=constant;
Example:
int y=2; y is a variable, its integer type, and it stores value 2
int x=y=z=1;

9. EXPRESSIONS
An expression is a combination of operators and operands which reduces to be a single value. An operator indicates an operation to be performed on data that yields a value.
a.
Primary Expressions: In C the operand in the primary expression can be a name, a constant or an parenthesized Expression.
Name is any identifier for a variable. A constant is the one whose value can be changed during program execution. Any value enclosed within parenthesis must be reduced to single value.

Page | 5
Introduction to Programming

Example: (3*5+8);
(C=a=5*c);
b.
prefix: the operator used before the operand is called pre increment/decrement
Ex: + a b it is equal to a+b
c.
postfix: the operator used after the operand is called post increment/decrement.
Ex: a b + it is equal to a+b
d.
Unary Expressions: An unary expression is like a prefix expression consists of one operand and one operator and the operand comes after the operator.
Ex: ++a=a+1, -c, b++ =b+1
e.
Binary expressions: Binary expressions are the combinations of two operands and an operator. Any two variables added, subtracted, multiplied or divided is a binary expression.
Ex; a*b; c%d;
f.
Ternary Expressions: Ternary expression which consists of a ternary operator pair “? :”
Ex: exp1? exp2:exp3; => (a>b)?a=max:b=max;
In the above example, if exp1 is true exp2 is executed else exp3 is executed.

10. OPEARTORS:
In order to perform different kinds of operations, C uses different kinds of operator. An operator indicates an operation to be performed on data that yields a value. Using various operators in C one
can link the variable and constants. An operand is a data item in which operators perform the operations. Table shows the operators in C.

S.no Type of Operator Symbolic Representations

1 Arithmetic operators + , - , * , / , and %

2 Relational operators < . > , == , >= ,<= , and !=

3 Logical operators && , || , and !

4 Increment and decrement operator ++ and --

5 Assignment operator =

6 Bitwise operator &, | , ^ , >> , <<, and ~

7 Comma operator ,

8 Conditional operator ?:
a.
Comma Operator:- The comma operator is used to separate two or more expressions. The comma operator has the lowest priority among all the operators.
Ex: a=5,a=b%c;
The bellow program illustrates the use of comma operator
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
//comma operator can also used for separate the variables.
clrscr();
printf("\nread a & b values : ");
scanf("%d %d",&a,&b);
//comma operator used in scanf function
c=a+b;
//comma operator used in printf function
printf("\n a = %d, b = %d, c = %d",a,b,c);
getch();
}
Output:
read a & b values : 12 24
a = 12, b = 24, c = 36
b.
Conditional operator(? :) The conditional operator contains a condition followed by two statements or values. If the conditions is true the first statement is executed otherwise second
statement. The conditional operator (?) and (:) are sometimes called ternary operators because they take three arguments. The syntax of conditional operator is as given bellow.
Syntax: condition?(expression1):(expression2);
The bellow program illustrates the use of conditional operator

Page | 6
Introduction to Programming

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,max;
clrscr();
printf("\n enter a and b values : ");
scanf("%d %d",&a,&b);
//use of the ternary operator
max=(a>b)?a:b;
printf(" maximum value is : %d",max);
getch();
}
Output 1: enter a and b values : 6 7
maximum value is : 7
Output 2: enter a and b values : 20 8
maximum value is : 20
C.
Arithmetic Operators: there are two types of arithmetic operators. They are 1. Binary operators and 2. Unary operators.
I.
Binary operators: These operators are commonly used in most of the computer languages. These arithmetic operators are used for numerical calculations between the two constant
values. They are also called as Binary Arithmetic Operators. Table shows the arithmetic operators declared in the program.

Arithmetic operators Operator Explanation Examples

+ Addition 2+4=6

- Subtraction 5-4=1

* Multiplication 2*5=10

/ Division 6/3=2

% Modular division 12%5=2(remainders 2)


12/5=2.4
4%7=4
12%7=5

Program to illustrate the arithmetic operations


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,mod;
float sum,sub,mul,div;
clrscr();
printf("program to implement the arithmetic operatios");
printf("\nenter a value : ");
scanf("%d",&a);
printf("\nenter b value : ");
scanf("%d",&b);
sum=a+b;
sub=a-b;
mul=a*b;
div=(float)a/(float)b;
mod=a%b;
printf("\n addition of two numbers is : %f",sum);
printf("\n subtraction of two numbers is : %f",sub);
printf("\n multiplication of two numbers is : %f",mul);
printf("\n division of two numbers is : %f",div);

Page | 7
Introduction to Programming

printf("\n modulus of two numbers is : %d",mod);


getch();
}
Output:-
program to implement the arithmetic operatios
enter a value : 7
enter b value : 4
addition of two numbers is : 11.000000
subtraction of two numbers is : 3.000000
multiplication of two numbers is : 28.000000
division of two numbers is : 1.750000
modulus of two numbers is : 3
II.
Unary Arithmetic Operators: Unary operators are increment operator (++) , decrement (--) and (-). (+) These operators and their examples given bellow.

Operator Description or action example Equaling

+ plus x+=10 x=x+10

- minus x-=10 x=x-10

Program to illustrate the Unary operations


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nprogram to illustarate the unary operators");
printf("\nenter a & b values :");
scanf("%d %d",&a,&b);
a+=b; //a=a+b
printf("\nvalue of a+=b : %d",a);
b-=a; //b=b-a
printf("\nvalue of b-=a : %d",b);
getch();
}
Output:
enter a & b values :4 5
value of a+=b : 9
value of b-=a : -4
c.
Incremental and Decrement Operators: - The C compilers produce very fast, efficient object codes for increment and decrement operations. The operator ++ adds one to its operand,
where as operator - - subtracts one from the operand.

Operator Description or action example equivalent

++ Increment x++ x=x+1

-- Decrement x-- x=x-1

. prefix: the operator used before the operand is called pre increment/decrement
Ex: ++a or --a
. postfix: the operator used after the operand is called post increment/decrement.
Ex: a-- or a++
Program to illustrate the increment and decrement operators:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;

Page | 8
Introduction to Programming

clrscr();
printf("\nprogram to implement the increment and decrement operators");
printf("\n enter the values of a and b ");
scanf("%d %d",&a,&b);
printf("before the change value of a :%d",a);
c=a++;
printf("\n afer the post increment of a, value of c = %d",c);
printf("\n after postincrement a= %d",a);
c=++a;
printf("\n after the preincrement of a, value of c = %d",c);
printf("\n after the preincremnt of a= %d",a);
printf("\n***decrement***");
printf("before the change value of b : %d",b);
c=b--;
printf("\n afer the post decrement of a, value of c = %d",c);
printf("\n after post decrement b= %d",b);
c=--b;
printf("\n after the pre decrement of a, value of c = %d",c);
printf("\n after the pre decrement of b= %d",b);
getch();
}
output :
program to implement the increment and decrement operators
enter the values of a and b 4 5
before the change value of a :4
afer the post increment of a, value of c = 4
after post increment a= 5
after the pre increment of a, value of c = 6
after the pre incremnt of a= 6
***decrement***before the change value of b : 5
afer the post decrement of a, value of c = 5
after post decrement b= 4
after the pre decrement of a, value of c = 3
after the pre decrement of b= 3
d.
Relational Operators: These operators are used to distinguish between two values depending on their relation. These operands provide the relation between the two expressions. If the
relation is true then it return a value “1”, otherwise “0 “for the false relation. Table shows the relation operators in C.

Operator Description or Action Example True/ False Return value

> Greater than 5>4 True 1

< Less than 5<4 False 0

<= Less than or equal 5<=5 True 1

>= Greater than or equal 5>=5 True 1

== Double Equal to 2==3 False 0

!= Not equal to 2!=3 True 1

Program to illustrate the relational operators:


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\nCondtion : return values\n");
printf("\n10!=10 : %3d",10!=10);

Page | 9
Introduction to Programming

printf("\n10==10 : %3d",10==10);
printf("\n10>=10 : %3d",10>=10);
printf("\n10<=100 : %3d",10<=100);
printf("\n10!=9 : %3d",10!=9);
getch();
}
output:
Condtion : return values
10!=10 : 0
10==10 : 1
10>=10 : 1
10<=100 : 1
10!=9 : 1
e.
Logical Operator: The logical relationships between the two expressions are checked with logical operators. Using these operators two expressions can be joined. After checking the
conditions it provides logical true “1” or false “0” status. Table shows the logical operators in C.

operator Description Example Return value

&& Logical AND 5>3 && 4<6 1

|| Logical OR 5>3 || 5<3 1

! Logical NOT 8!=8 0

From the above table following rules can be followed for logical operators.
i. The logical AND (&&) operator true “1” when both the expressions are true otherwise “0’.

Expression A Expression B A&&B Return

T T T 1

F T F 0

T F F 0

F F F 0

ii. The logical OR (||) operator false “0” when both the expression are false otherwise “1”.

Expression A Expression B A||B Return

T T T 1

F T T 1

T F T 1

F F F 0

iii. The logical NOT (!) provides “0” if the condition is true otherwise “1”

Expression A !A Return

T F 0

F T 1

Progam to implement the logical operators:


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();
printf("\nprogram to implement logical operations; ");
printf("\nenter a ,b, c values : ");
scanf("%d %d %d",&a,&b,&c);
d=((a>=b)&&(a>=c));
printf("\n Logical AND d: %d",d);
d=((a>=b)||(a>=c));
printf("\n Logical OR d: %d",d);

Page | 10
Introduction to Programming

d=!(a>=b);
printf("\n Logical NOT d: %d",d);
getch();
}
output 1:
program to implement logical operations;
enter a ,b, c values : 12 10 13
Logical AND d: 0
Logical OR d: 1
Logical NOT d: 0
output 2:
program to implement logical operations;
enter a ,b, c values : 20 10 08
Logical AND d: 1
Logical OR d: 1
Logical NOT d: 0
output 3:
program to implement logical operations;
enter a ,b, c values : 12 15 12
Logical AND d: 0
Logical OR d: 1
Logical NOT d: 1
f.
Bitwise Operators: - C supports a set of bitwise operators as listed in the table. C supports six bit operators. These operators can operate only on an integer operands such as int, char,
short, long etc.,

operator Meaning Example Result

>> Right shift 7>>=1 3

<< Left shift 7<<=1 14

^ Bitwise XOR (exclusive OR) 5^6 3

~ One’s Complement

& Bitwise AND 5&6 4

| Bitwise OR 5|6 7

Program to illustrate the bitwise operators:


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\nprogram to implement bitwise operations ");
printf("\nenter a ,b values : ");
scanf("%d %d",&a,&b);
c=a&b;
printf("\n bitwise AND c: %d",c);
c=a|b ;
printf("\n bitwise or c: %d",c);
c=a^b;
printf("\n bitwise XOR c: %d",c);
c=a<<=2;
printf("\n left shift c: %d",c);
c=b>>=1;
printf("\n right shift c: %d",c);

Page | 11
Introduction to Programming

getch();
}
11.
List of Operators with Precedence:
Operator Operation Associativity Precedence

() Function call

[] Array expression or square bracket st


Left to right 1
-> Structure Operator

. Structure Operator

+ Unary plus

- Unary minus

++ Increment

-- Decrement

! Not operator nd
Right to left 2
~ Ones complement

* Pointer operator

& Address operator

Sizeof Size of an object

type Type cast

* Multiplication
rd
/ Division Left to right 3

% Modular division

+ Addition th
Left to right 4
- Subtraction

<< Left shift th


Left to right 5
>> Right shift

< Less than

<= Less than or equal to th


Left to right 6
> Grater than

>= Greater than or equal to

== Equality th
Left to right 7
!= Inequality
th
& Bitwise AND Left to right 8
th
^ Bitwise XOR Left to right 9
th
| Bitwise OR Left to right 10
th
&& Logical AND Left to right 11
th
|| Logical OR Left to right 12
th
?: Conditional operator Right to left 13
th
=, *=, - =, &= +=, |=, <<=, >>= Assignment operators Left to right 14
th
, Comma operator Left to right 15

12. Data Input and Output Standards


a.
Generating the Output:
The most important aspect of the computer operation is designing the required output of any problem. The solution once it is prepared had to be projected through a proper recognizable output
device, for which proper functions should be available. To make the process.
i.
printf() Function:
▪ It is a precompiled library function in C language prototyped in stdio.h
▪ Used to display formatted string of characters on the standard output device.
▪ By using proper conversion specifications it can be used to output, characters, numbers & strings.
▪ The information that is being printed can be formatted using proper format specifications or also called as escape sequences.

Syntax Diagram for printf() form 1:

Page | 12
Introduction to Programming

printf
“ MESSAGE “
(
Ex: printf(“My first C program “);
) ;
printf(“Let us check what c is ….”);
Syntax Diagram for printf() form 2:
printf FORMAT SPECIFIER
“ MESSAGE “ v.n )
Steps to be followed in(printf , ;
⮚ plan the actual design of the output
⮚ plan the format specifications where necessary.
⮚ FORMAT
Replace the data with designated conversion specifications. ,
b. SPECIFIER
Data Input Standards
Syntax diagram for scanf function
⮚ “scanf” It is a precompiled library function in C language prototyped in stdio.h
⮚ Used to scan data from the standard input device.
⮚ Proper conversion specifications should be used to input, characters, numbers and strings.
⮚ It is a function, which scans the data of various types that is properly recognized by C syntax and semantics.
⮚ The scanned data is placed in the proper memory location for which the address, address is supplied using the address operator, which is a unary operator represented as ‘&’

scanf Format specifier


“ “ &v.n )
13. (
Backslash Character Constants:
, ;

C supports some special backslash character constants that are used in output functions. For example the symbol ‘\n” stands for new-line character. A list of such backslash character constants is
given in table. Note that each one of them represents one character, although they consist of two characters. These character combinations are known as escape sequences.

S.no Constant Meaning ,


1 \a Audible alert (bell)

2 \b Back space

3 \f Form feed

4 \n New line

5 \r Carriage return

6 \t Horizontal tab

7 \v Vertical tab

8 \’ Single quote

9 \” Double quote

10 \? Question mark

11 || Backslash

12 \0 null

What is an algorithm?
An algorithm is a step by step procedure to solve a problem. In normal language, the algorithm is defined as a sequence of statements which are used to perform a task.
Algorithms are used to convert our problem solution into step by step statements. These statements can be converted into computer programming instructions which form a program. This program
is executed by a computer to produce a solution. Here, the program takes required data as input, processes data according to the program instructions and finally produces a result as shown in the
following picture.

Specifications of Algorithms
Every algorithm must satisfy the following specifications...
1.
Input - Every algorithm must take zero or more number of input values from external.
2.
Output - Every algorithm must produce an output as result.

Page | 13
Introduction to Programming

3.
Definiteness - Every statement/instruction in an algorithm must be clear and unambiguous (only one interpretation).
4.
Finiteness - For all different cases, the algorithm must produce result within a finite number of steps.
5.
Effectiveness - Every instruction must be basic enough to be carried out and it also must be feasible.
Flowchart is a diagrammatic representation of sequence of logical steps of a program. Flowcharts use simple geometric shapes to depict processes and arrows to show relationships and
process/data flow.

Symbol Symbol Name Purpose

Start/Stop Used at the beginning and end of the algorithm to show start and end of the program.

Process Indicates processes like mathematical operations.

Input/ Output Used for denoting program inputs and outputs.

Stands for decision statements in a program, where answer is usually Yes or No.
Decision

Shows relationships between different shapes.


Arrow

14. Decision statement:

A program is nothing but the execution of sequence of one or more instructions. Quire often it is desirable to alert the sequence of the statements in the program depending upon certain
circumstances. In practical applications there are a number of situations where one has to change the order of the execution of statements based on the conditions.

These conditions can be placed in the program using decision-making statements. C-language supports the control statements as listed below.
a. Simple if
b. If else
c. else if
d. switch statements

a.
Simple if statement: In a simple ‘if’ statement, a condition is tested. If the condition is true, sets of statements are executed. If the condition is false, the statements are not executed
and the control goes to the next statement that immediately follows.

Syntax:
if (condition)
{
statement (s);
}
next statement

Page | 14
Introduction to Programming

Flowchart representing an if statement

False True
Start
Example program: program to implement the simple if statements, to find the given number is +ve or not
#include<stdio.h>
#include<conio.h>
void main() Input values

{
int n;
clrscr();
printf(“\n program to find the given number is +ve or not”); Condition

printf(“\n enter n value : “);


scanf(“%d”,&n);
if(n>=0)
{
printf(“\ngiven number is +ve “); Statements

}
printf(“***over***”);
getch();
} Statements

output 1:
program to find the given number is +ve or not
enter n value 24
given number is +ve stop

***over***
output 2:
program to find the given number is +ve or not
enter n value -24
***over***
b.
if else :- In simple “if” statements, when the condition is true, a set of statements are executed. But when if it is false,
there is no alternate set of statements. The statement ‘else’ provided the same. The if…else statement takes care of true as well as false conditions. It has two blocks. One block is for ‘if” and it
executed when the condition following “if” is true. The other conditions block is of “else” and it is executed when the condition is false. The “else” statement cannot be used without “if”. No
multiple else statements are allowed with one “if”.
Syntax:
if(the condition is true)
Execute the statements1;
else
Execute the statements 2;
Flowchart representing an if….else statement

False True
Start

Program to find maximum and minimum of two numbers by using if else


#include<stdio.h>
#include<conio.h>
Input values
void main()
{
int a,b;
clrscr();
Condition
printf("\nEnter a and b values :");
scanf("%d %d",&a,&b);
if(a>=b)
{
printf("\na is maximum value, a : %d",a); Statements
Statements

Page | 15
Introduction to Programming

printf("\nb is minimum value, b : %d",b);


}
else
{
printf("\nb is maximum value, b: %d",b);
printf("\na is minimum value, b: %d",a);
}
getch();
}
Output1:
Enter a and b values: 34 46
b is maximum value, b: 46
a is minimum value, b: 34
output2:
Enter a and b values: 25 12
a is maximum value, a : 25
b is minimum value, b : 12
c.
NESTED if..else Statement or if else if or if else ladder:- In this kind of statements number of logical conditions are checked for executing various statements. Here, if any logic
condition is true the compiler executes the block followed by if condition otherwise its skips and executed else block. In if.. else statement else block is executed by default after failure of condition.
In order to execute the else block depending upon certain condition we can add repetitively if statements in else block. This kind of nesting will be unlimited.
Syntax of if..else..if ladder is as follows.
If(condition)
{
Statement 1;
Statement 2;
}else if(condition)
{
Statement 3;
Statement 4;
}else
{
Statement 5;
Statement 6;
}
Note: condition doesn’t contain semicolon

Page | 16
Introduction to Programming

Flow chart of if..else..if ladder is as follows:


True False false false
true true true

Program to find maximum of three numbers


#include<stdio.h>
condition condition condition
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
statements Statements
printf("\nEnter a,b,c values "); statements
ents
scanf("%d %d %d",&a,&b,&c);
statements
printf("\nto find maximum of three numbers");
if(a>=b&&a>=c)
{
printf("\na is maximum value, a : %d",a); statements
}
else if(b>=c)
{
printf("\nb is maximum value, b : %d",b);
}
else
{
printf("\nc is maximum value, c : %d",c);
}
getch();
}
Output:
Enter a,b,c values 12 34 24
to find maximum of three numbers
b is maximum value, b : 34
p) W.a.p. to enter basic salary and calculate HRA and DA below basis and find gross salary.
-> HRA 13% of B.S.
-> DA 28% of B.S. */
#include<stdio.h>
#include<conio.h>
void main()
{
int s;
float gs,hra,da;
clrscr();
printf("\nEnter salary:");
scanf("%d",&s);
hra=(float)13*s/100;
da=(float)28*s/100;
gs=hra+s+da;
printf("\nHRA is :%0.2f",hra);
printf("\nDA is :%0.2f",da);
printf("\nGross Salary is :%0.2f",gs);
getch();
}

Page | 17
Introduction to Programming

Output:
Enter Salary: 5000
HRA is : 650.00
DA is : 1400.00
Gross Salary is : 7050.00

The Break Statement:


The keyword break allows the programmer to terminate the loop. The break skips from the loop or block in which it is defined. The control the automatically goes to the first statement after the
loop or block. The break is associated with all conditional statements. We can also use break statements in the nested loops.

The Continue Statement:


The continue statements is exactly opposite to break. The continue statement is used for continuing next iteration of loop statement. When it occurs in the loop it does not terminate, but it skips the
statements after this statement. It is useful when we want to continue the program without executing any part of the program.

The goto Statement:


This goto is also a keyword, this statement doesn’t require any condition. This statement passes control anywhere in the program i.e. control is transferred to another part of the program without
testing any condition. This user has to defined goto statement as follows.
goto lable;
---- /* this statements are skip from the control of
---- execution */
lable:
------ /* this statements will execute immediate after finding the
------ lable*/
Here label is the position where the control is to be transferred.
Program to implement the goto statement
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("\n Enter a character ");
scanf("%c",&ch);
if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))
{
printf(" Given character is Alphabet");
if(ch>='A'&&ch<='Z')
{
printf("\nGiven character is Upper case character");
printf(" ch : %c",ch);
}
else
{
printf("\nGiven character is Lower case character");
printf(" ch : %c",ch);
}
goto xx;
}
printf("\n Given character is not a alphabet");
printf("\n Given character may be a digit or special character");
xx:
printf("\n***over***");
getch();
}

Page | 18
Introduction to Programming

Output:
Enter a character a
Given character is Alphabet
Given character is Lower case character ch : a
***over***
Enter a character A
Given character is Alphabet
Given character is Upper case character ch : A
***over***
Enter a character 9
Given character is not a alphabet
Given character may be a digit or special character
***over***
d.
The switch statement:
Design a program using if statement to control the selection. However, the complexity if such program increases dramatically when the number of alternatives increases. The program becomes
difficult to read and follow. At times, it may confuse even the person who designed it. C has a built-in multi way decision statement known as a switch. The switch statement tests the value of a
given variable (0r expression) against a list of case values and when a match is found, a block of statements associated with that case is executed. The syntax of switch as follows.
Syntax:
Switch(variable or expression)
{
case constant A:
statements;
break;
case constant B:
statements;
break;
default:
statement;
}
The expression is an integer expression or characters. Value-1, value-2 .. are constants or constant expressions (valuable to an integral constant) and are know as case labels. Each of these
values should be unique within a switch statement block-1, block-2… are statement lists and may contain zero or more statements. There is no need to put braces around the blocks. Note that
case labels and with a colon (:).
When the switch is executed, the value of the expression is successively compared against the values value-1, value-2,… if a case is found whose value matches with the value of the expression,
then the block of statements that follows the case are executed.
The break statement at the end of each block signal the end of a particular case and causes an exit from the switch statement, transferring the control to the statement-x following the switch.
The default is an optional case. When present, it will be executed if the value of the expression does not match with any case values. If not present, no action takes place if all matches fail and
the control goes to the statement-x.
Program to perform the arithmetic operations using switch statements
#include<stdio.h>
#include<conio.h>
void main()
{ char ch;
int a,b,mod;
float add,sub,mul,div;
clrscr();
printf("\n1.Adition to press + ");
printf("\n2.subtraction to press -");
printf("\n3.multiplication to press *");
printf("\n4.division to press /");
printf("\n5.modulus to press %");
printf("\n**************");

Page | 19
Introduction to Programming

printf("\n***Enter Options***");
printf("\nEnter an arthmetci operator ");
scanf("%c",&ch);
printf("\n***Enter Options***");
printf("\nEnter an arthmetci operator ");
scanf("%c",&ch);
printf("\nenter a and b values :");
scanf("%d%d",&a,&b);
switch(ch)
{
case '+':
printf("\n**performing addition operation** ");
add=a+b;
printf("\nAddition of two numbers is :%.2f",add);
break;
case '-':
printf("\n**performing subtraction operation** ");
sub=a-b;
printf("\nsubtraction of two numbers is :%.2f",sub);
break;
case '*':
printf("\n**performing multiplication operation** ");
mul=a*b;
printf("\nMultiplication of two numbers is :%.2f",mul);
break;
case '/':
printf("\n**performing division operation** ");
div=(float)a/(float)b;
printf("\nDivision of two numbers is :%.2f",div);
break;
case '%':
printf("\n**performing modulus operation** ");
mod=a%b;
printf("\nmodulus of two numbers is :%d",mod);
break;
default :
printf("\n you had choicen non arithmatic chatacter ");
}
getch();
}
Output :
1.Adition to press +
2.subtraction to press -
3.multiplication to press *
4.division to press /
5.modulus to press %
**************
***Enter Options***
Enter an arthmetci operator %
enter a and b values :27
4

Page | 20
Introduction to Programming

**performing modulus operation**


modulus of two numbers is :3
15.
LOOP CONTROL STATEMENTS:

What is a Loop?
A loop is defined as a block of statements which are repeatedly executed for certain number of times.
Steps in loop:
Loop variable: it is a variable used in the loop.
Initialization: it is the first step in which starting and final value is assigned to the loop variable. Each time the update value is checked by the loop itself
Increment/ Decrement: it is the numerical value added or subtract to the variable in each round of the loop.
The C-language supports three types of loop control statements. They are given bellow with the syntax

for while Do while

for(expression1;condition; Expression/initialization; Expression;


expression2) While(condition) Do
{ { {
Statements; Statements; Statements;
} Expressions; Expressions;
} }while(condition);

While loop:
The while is a loop condition statement, it test condition may be any expression. The loop statements will be executed till the condition is false i.e. the test condition is evaluated and if the condition
is true, then the body of the loop is executed. When the condition becomes false the execution will be come out from the loop.
Syntax of while:
Expression/initialization;
while(condition)
{
Statements;
Expressions;
}
Steps in while loop:
1. The test condition is evaluated and if it is true, the body of the loop is executed.
2. On the execution of body, test condition is repetitively checked and if it is true the body is executed.
3. The process of execution of the body will be continuing till test condition becomes false.
4. If the condition is false then the control is transferred out of the loop.
The execution of the while loop can be followed by the following flow chat

True False
Test
Condition

Body of loop

Statements

Page | 21
Introduction to Programming

Example program on while loop:


p)Write a program to print the string “ this is c-program using while loop” 9 times using while loop?
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
i=1;
while(i<10)
{
printf("\nthis is c-program using while loop");
i++;
}
getch();
}
output:
this is c-program using while loop
this is c-program using while loop
this is c-program using while loop
this is c-program using while loop
this is c-program using while loop
this is c-program using while loop
this is c-program using while loop
this is c-program using while loop
this is c-program using while loop

p)Write a program to calculate factorial of a given number. Using while loop?


#include<stdio.h>
#include<conio.h>
void main()
{
int n,fact;
clrscr();
fact=1;
printf("\Enter n value : ");
scanf("%d",&n);
while(n>1)
{
fact=fact*n;
n--;
}
printf("\n factorial of a number is : %d",fact);
getch();
}
output
Enter n value : 6
factorial of a number is : 720

n Fact Condition fact n--


n>1

5 1 T 5 4

4 5 T 5*4=20 3

Page | 22
Introduction to Programming

3 20 T 20*3=60 2

2 60 T 60*2=120 1

1 120 F

p)Write a program to calculate of sum of consecutive even and odd integer separately?
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,eve,odd;
clrscr();
printf("\nEnter n value :");
scanf("%d",&n);
i=0;
eve=0;
odd=0;
while(i<=n)
{
if(i%2==0)
{
eve=eve+i;
}
else
{
odd=odd+i;
}
i++;
}
printf("\n sum of even numbers is : %d",eve);
printf("\n sum of odd numbers is : %d",odd);
getch();
}
output:
Enter n value : 30
sum of even numbers is : 240
sum of odd numbers is : 225

p)Write a program to find given number is palindrome or not?


#include<stdio.h>
#include<conio.h>
void main()
{
int n,rem,rev,temp;
clrscr();
printf("\nEnter n value ");
scanf("%d",&n);
temp=n;
rev=0;
while(n!=0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;

Page | 23
Introduction to Programming

}
printf("\n Reverese of a number given number is :%d",rev);
if(rev==temp)
{
printf("\ngiven number is palindrom");
}
else
{
printf("\ngiven number is not palindrom");
}
getch();
}
output:
Enter n value 2112
Reverese of a number given number is :2112
given number is palindrome

The Do.. while loop control statement:


The while loop makes a test of condition before the loop is executed. Therefore, the body of the loop may not be executed at all if the condition is not satisfied at the very first attempt. On some
occasions it might be necessary to execute the body of the loop before the rest is performed.
On reaching the “do” statement, the proceeds to evaluate the body of the loop first. At the end of the loop, the test-condition in the while statement is evaluated. If the condition is true, the program
continues to evaluate the body of the loop once again. This process continues as long as the condition is true.
When the condition becomes false, the loop will be terminated and control goes to the statement that appears immediately after the while statement.
Syntax of do..while:
Expression;
do
{
Statements;
Expressions;
}while(condition);
Example programs using do while
p)Write a program to find sum of positive and negative values until number is 0
#include<stdio.h>
#include<conio.h>
void main()
{
int pos,nev,n;
clrscr();
pos=0;
nev=0;
do
{
printf("\nEnter n value : ");
scanf("%d",&n);
if(n>0)
{
pos=pos+n;
}
else
{
nev=nev+n;
}

Page | 24
Introduction to Programming

}
while(n!=0);
printf("\nsum of positive integers : %d",pos);
printf("\nsum of nagative integers : %d",nev);
getch();
}
output:
Enter n value : 10
Enter n value : -10
Enter n value : 20
Enter n value : -20
Enter n value : 30
Enter n value : -30
Enter n value : -40
Enter n value : 0
sum of positive integers : 60
sum of nagative integers : -100

p)Write a program to print the entered number in reverse order. Use do while loop, also perform sum and multiplication with their digits
#include<stdio.h>
#include<conio.h>
void main()
{
int rem,sum,mul,n;
clrscr();
printf("\nEnter n value :");
scanf("%d",&n);
sum=0;
mul=1;
do
{
rem=n%10;
sum=sum+rem;
mul=mul*rem;
n=n/10;
}while(n!=0);
printf("\nsum of digits : %d",sum);
printf("\nmultiplication of digits : %d",mul);
getch();
}
output:
Enter n value :3425
sum of digits : 14
multiplication of digits : 120
321=3+2+1=6
321=3*2*1=6

The for loop:


for loop allows to execute a set of instructions until a certain conditions is satisfied. Condition may be predefined or open-ended.
Syntax:
for(initialize; condition; increment/decrement/expression)
{
Statements;

Page | 25
Introduction to Programming

Statements;
}
1. The initialize the variable sets a loop to an initial(starting) value. This statement is executed only once.
2.
The test condition is a relational expression that determines the number of iterations desired or t0 determines when to exit from the loop . The ‘for’ loop continues to execute as long as
conditional test is satisfied, when the conditions becomes false the control of the program exits from the body of to ‘for’ loop and executes next statement after the body of the loop.
3. The increment/decrement/expression parameter decides how to make changes in the loop (increase or decries operations are to be used).
4. The body of the loop may contain either a single statement or multiple statements. In case there is only one statement after the ‘for’ loop braces may not be necessary.
Various formats of ‘for’ loop

Syntax Output Remarks

for(;;) Infinite loop No arguments

for(a=0;a<=10;) Infinite loop ‘a’ is neither increased nor decreased.

for(a=0;a<=10;a++) Display value from 0 to 10 ‘a’ is increased from 0 to 10. Curly braces are not necessary. Default
Printf(“%d”.a); scope of the ‘for’ loop is one statement after for loop.

for(a=10;a>=0;a--) Display value from 10 to 0 ‘a’ is decreased from 10 to 0.


Printf(“%d”.a);

p) print the squares of the consecutive integers up to n


#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf("\nEnter n value : ");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
printf("\n%d-->%d",i,i*i);
}
getch();
}
Output:
Enter n value : 10
0-->0
1-->1
2-->4
3-->9
4-->16
5-->25
6-->36
7-->49
8-->64
9-->81
10-->100
p)print the ASCII Values of all keys
#include<stdio.h>
#include<conio.h>
void main()
{
int i,t;
clrscr();
t=0;

Page | 26
Introduction to Programming

printf("\n\n\n");
for(i=0;i<=127;i++)
{
if(t==6)
{
printf("\n\n");
t=0;
}
printf("%d--%c\t",i,i);
t++;
}
getch();
}
Output:
0--> 1-->☺ 2-->☻ 3-->♥ 4-->♦ 5-->♣
6-->♠ 7--> 8-- 9--> 10-->
11-->♂
14-->♫ 15-->☼ 16-->► 17-->◄
18--> 19--> 20-->¶ 21-->§ 22--> 23-->

24--> 25--> 26-->27--> 28--> 29-->

30-->▲ 31-->▼ 32--> 33-->! 34-->" 35-->#


36-->$ 37-->% 38-->& 39-->' 40-->( 41-->)
42-->* 43-->+ 44-->, 45-->- 46-->. 47-->/
48-->0 49-->1 50-->2 51-->3 52-->4 53-->5
54-->6 55-->7 56-->8 57-->9 58-->: 59-->;
60-->< 61-->= 62-->> 63-->? 64-->@ 65-->A
66-->B 67-->C 68-->D 69-->E 70-->F 71-->G
72-->H 73-->I 74-->J 75-->K 76-->L 77-->M
78-->N 79-->O 80-->P 81-->Q 82-->R 83-->S
84-->T 85-->U 86-->V 87-->W 88-->X 89-->Y
90-->Z 91-->[ 92-->\ 93-->] 94-->^ 95-->_
96-->` 97-->a 98-->b 99-->c 100-->d 101-->e
102-->f 103-->g 104-->h 105-->i 106-->j 107-->k
108-->l 109-->m 110-->n 111-->o 112-->p 113-->q
114-->r 115-->s 116-->t 117-->u 118-->v 119-->w
120-->x 121-->y 122-->z 123-->{ 124-->| 125-->}
126-->~ 127-->

Nested for loops:


Nested for loops, that is one for statement within another for statement, is allowed in C for example, two loops can be nested as follows.
for(i=0;i<n;i++)
{
--------
--------
Outer for loop for(j=0;j<m;j++)
{
------- inner for loop
------
}
}
Every i value j will repeat m times

Page | 27
Introduction to Programming

i repeat n times then inner loop statements repeats n*m times


Example programs using nested for loops
p. program to print range of prime numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,t;
clrscr();
printf("\n enter a number : ");
scanf("%d",&n);
printf("\n2");
for(i=3;i<=n;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
{
t=1;
break;
}
else
t=0;
}
if(t==0)
printf("\t%d",i);
}
getch();
}
output:
enter a number : 50
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47

p. program to display numbers as given bellow


1
12
123
1234
12345
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("\nEnter n value : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{

Page | 28
Introduction to Programming

printf("%d",j);
}
printf("\n");
}
getch();
}
output:
Enter n value : 6
1
12
123
1234
12345
123456

p. program to display numbers as given bellow


12345
2345
345
45
5
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
{ printf("%d",j);
}
printf("\n");
for(k=1;k<=i;k++)
{
printf(" ");
}
}
getch();
}
Output:
12345
2345
345
45
5

p. Write a program to print given pattern


54321
4321
321
21
1

Page | 29
Introduction to Programming

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf("%d",j);
}
printf("\n");
for(k=5;k>=i;k--)
{
printf(" ");
}
}
getch();
}
OUTPUT
54321
4321
321
21
1

Write a program to print as given pattren


A
AB
ABC
ABCD
ABCDE
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,t=64;
clrscr();
for(i=1;i<=5;i++)
{
t=65;
for(j=1;j<=i;j++)
{
printf("%c",t);
t++;
}
printf("\n");
}
}
OUTPUT
A

Page | 30
Introduction to Programming

AB
ABC
ABCD
ABCDE

Page | 31
Introduction to Programming

p. write a program to display the given pattern


1234554321
1234 4321
123 321
12 21
1 1
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,p,x;
clrscr();
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
if(i==5)
{
printf("");
}
else
{
x=2*(5-i);
for(p=1;p<=x;p++)
{
printf(" ");
}
}
for(k=i;k>=1;k--)
{
printf("%d",k);
}
printf("\n");
}
getch();
}
Output:
1234554321
1234 4321
123 321
12 21
1 1

Page | 32

You might also like