1
Chapter - 01 : “Variables, Constants & Expressions”
1 HISTORY OF C LANGUAGE :
Around 1960 many languages come in the field of computer like COBOL, PASCAL, BASIC etc. At this stage programmer community started thinking that instead of learning and using so many languages, why not use only one language, which can perform all possible operations. An international committee was set up to develop such a language and language named ALGOL – 60 was developed. But this language was proved very lengthy. Again a new language was developed which was called CPL (Combine Programming Language). But this language was very specific and vast. Now another language developed BCPL. But it also turned out to be less powerful. At the same time Ken Thomsen wrote a language at AT&T’s Bell Labs that was called B-Language. But it was also turned out to be very specific.
It was the Dennis Ritchie that inherited the features of B and BCPL, and added some of his own and developed a new language C-Language.
C-Language is very powerful and compact, so it is called one-man-language.
1 STRUCTURE OF C PROGRAM :
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
printf("Hello");
getch();
}
#include : is a preprocessor directive. It is a indication for the C compiler to add the particular header file inside the program.
stdio.h : standard input output header file conio.h : console input output header file
void : means empty or null. i.e. the function is not returning any value.
main( ) : is a function necessary for C program. Every C program must contain atleast one function main().
clrscr( ) : It is a library function defined inside conio.h header file and it is used to clear the screen.
getch( ) : This function is also a library function define inside conio.h header file and it is used to get character from the keyboard for output.
2
printf( ) : Standard output function used to display given data.
{ : indicates the beginning of the function } : indicates the end of the function.
; : Statement terminator used to terminate a C-statement.
2 C Character Set :
A Character denotes any alphabet, digit or special symbol used to represent information. Following table shows the valid alphabets, numbers and special symbols allowed in C:
Alphabets A, B, C, ………..,Y, Z
a, b, c,………, y, z Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special Symbols ~ ` ! @ # $ % ^ & * ( ) _ - + =
| \ { } [ ] : ; “ ‘ < > , .
? /
2 Constants, Variables And Keywords :
The alphabets, numbers and special symbols when properly combined form constants, variables and keywords.
3 Constants :
A Constant is a quantity that doesn’t change. This quantity can be stored at locations in the memory of the computer.
Types of C Constants:
C constants can be divided into two major categories:
(a) Primary Constants (b) Secondary Constants
These constants are further categorized as follows:
Primary Constants :
(a) Integer constants : Integer constants are whole number without any decimal part. Variables can be declared as integers in the following ways :
int x=5 , y=6;
3 short int x =3, y=10;
long int x=21 , y=636;
(b) Floating point constants : Floating point number are the numbers containing decimal points (Real numbers). They may be written in one of the two forms called fractional form or exponent form.
A real number in fraction form consists of signed or unsigned digits including a decimal point between digits. The following are some real numbers in fractional form:
2.0, 17.5, - 13.0, - 0.00625
A real number in exponent form consists of two parts : mantissa and exponent. For instance 5.8 can be written as 0.58 x 101. The following are some real numbers in exponent form:
152E05, 1.52E07, 0.152E08, 152.0E08, 152E+8, 1520E-04
(c) Character constant : Character constant is single character enclosed in single quotes, as in ‘f’. For example,
‘A’ , ‘a’ , ‘:’ , ‘+’
Declaration of the character variables : char x;
char x, y, z;
The char stands for the character datatype for declaring the character constants.
(d) String constant : String constant is a sequence of zero or more characters enclosed between double quotes. Following are some examples from string constants.
(1) “The result =”
(2) “Rs. 2000.00”
(3) “This is test program by Ravi”
Derived Data Types in C-Language
Type Range Size Format
signed char -128 to +127 1 Byte %c
Unsigned char 0 to 255 1 Byte %c
short int or int
or short signed int
-32768 to +32767 2 Bytes %d
short unsigned int 0 to 216 2 Bytes %u
4 i.e. 0 to 65536
long signed int -231 to (231-1) 4 Bytes or 32 bits
%ld
long unsigned int 0 to (232 – 1) 4 Bytes or 32 bits
%lu
float -231 to (231-1) 4 Bytes %f
double (long float) -263 to (263-1) 8 Bytes %lf
long double -279 to +(279-1) 10 Bytes %Lf
Note: - float, double and long double are always signed.
1 VARIABLE
“A Variable is a named location in a memory that holds a data value.”
The contents of a variable can change. For example in the equation
3X + Y = 20
Since 3 and 20 cannot change, they are called constants, whereas the quantities X & Y can vary or change hence they are called variables.
All variables must be declared before they can be used. The general form of a variable declaration is
datatype variablename
Here datatype must be a valid data type and variablename may consist of one or more variable names separated by commas. For example
int i , j , k ; // Integer variables declaration
float per ; // Floating point number variables declaration
double balance, profit, loss ; // double variables declaration char nm1, nm2; // Character variables declaration char name[100]; // String declaration
In C, the name of a variable has nothing to do with its type.
5
2 IDENTIFIER
In C, the names of variables, functions, labels and various other user-defined items are called identifiers. The length of these identifiers can vary from one to several characters. The first character must be a letter or an underscore, and subsequent characters must be either letters, digits, or underscores. Some of the correct and incorrect identifier names are given below :
Correct Incorrect
count 1count
test23 hi!there
high_bal high…balance
In an identifier, uppercase and lowercase are treated as different. Hence, count, Count and COUNT are three separate identifiers.
3 KEYWORDS
Keywords are the reserved words whose meaning has already been explained to the C compiler. The keywords cannot be used as variable names because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer. There are 32 keywords available in C. The complete list of keywords in C are given below :
auto double if static
break else int struct
case enum long switch
char extern near typedef
const float register union
continue far return unsigned
default for short void
do goto signed while
3 Operators :
An operator is a symbol or letter which causes the compiler to take an action and yield a value. The operations being carried out are represented by operators. An operator acts on different data items/entities called Operands.
6
Types Of Operators
1. Arithmetic Operators 2. Relational Operators 3. Logical Operators 4. Ternary Operators
5. Increment and Decrement Operators 1. Arithmetic Operators
Arithmetic operators are those operators which perform arithmetic operations.
Arithmetic operators are considered as basic operators and known as binary operators as they require two variables to be evaluated. For e.g. if we want to multiply two numbers, one has to enter or feed the multiplicand and the multiplier.
That is why it is considered as a binary operator. There are mainly five types of arithmetic operators used in C language.
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo(Remainder of an integer division)
Addition Operator(+) int a = 4, b = 2, c;
c = a + b;
Output : c = 6
Subtraction Operator(-) int a = 4, b = 2, c;
c = a - b;
Output : c = 2
Multiplication Operator(*) int a = 4, b = 2, c;
c = a * b;
Output : c = 8 Division Operator(/)
7 int a = 5, b = 2, c;
c = a / b;
Output : c = 2
Modulus Operator(%) int a = 5, b = 2, c;
c = a % b;
Output : c = 1
Prog. 1 : A simple hello program
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
printf("Hello to C-programming");
getch( );
}
// : Single line comment
#include : preprocessor directive. It is an indication for the C-compiler to add the
particular header file inside C-program.
stdio.h : standard input output header file. It is used for all input output predefined functions.
conio.h : console input output header file. It is used for all console window related predefined functions.
void : void means empty or null. It means that the function is not returning
any value.
main( ) : main( ) is the most important function of C-programming because the
program execution always started with main( ) function.
{ : It indicate the start of a particular block.
} : It indicate the end of a particular block.
clrscr( ) : This function is used to clear the previous console window.
printf( ) : Standard output function.
getch( ) : This function is used to get character from keyboard
; : Statement terminator
8
Prog. 2 : WAP to use special characters '\n' and '\t'
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
printf("Name : Himani Madan");
printf("\nAddress : #1261/12,Pkl");
printf("\nPhone : 9417565720");
printf("\n\nNAME\tADDRESS\t\tPHONE");
printf("\nSurbhi\t#1211/14,Pkl\t8712828");
getch( );
}
Prog. 3 : WAP for Integer Initialization
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int num = 27;
printf("Given integer is : %d",num);
getch( );
}
Prog. 4 : WAP for Integer Input from user
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int num;
printf("Enter any integer : ");
scanf("%d",&num); // & stands for memory address of variable printf("\nGiven integer is : %d",num);
getch( );
}
9
Prog. 5 : WAP for Floating point number Initialization
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
float price;
price = 500.75;
printf("Given price is : %.2f",price);
getch( );
}
Prog. 6 : WAP for Floating point number Input from user
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
float price;
printf("Enter price : ");
scanf("%f",&price);
printf("\nGiven price is : %.2f",price);
getch( );
}
Prog. 7 : WAP for character initialization
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
char ch;
ch = 'A';
printf("\nGiven character is : %c",ch);
getch( );
}
10 Prog. 8 : WAP for character input from user
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
char ch;
printf("Enter any character value : ");
scanf("%c",&ch);
printf("\nGiven character is : %c",ch);
getch( );
}
Prog. 9 : WAP for string initialization
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
char name[20] = "Sandeep Sangwan";
printf("%s",name);
getch( );
}
Prog. 10 : WAP for string input from user
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
char name[20];
printf("Enter name : ");
gets(name);
printf("\nMy name is : %s",name);
getch( );
}
11
Prog. 11 : WAP to accept two integers and display their sum, difference, product, quotient and remainder
#include<stdio.h>
#include<conio.h>
void main() {
clrscr( );
int a,b;
printf("Enter two numbers : ");
scanf("%d%d",&a,&b);
printf("\nSum is : %d",a+b);
printf("\nDifference is : %d",a-b);
printf("\nProduct is : %d",a*b);
printf("\nQuotient is : %d",a/b);
printf("\nRemainder is : %d",a%b);
getch( );
}
Prog. 12 : WAP to accept the name, basic salary, HRA and DA of an employee. Calculate and display the gross salary of employee.
gs = bs+hra+da
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
char name[20];
float bs,hra,da,gs;
printf("Enter name of employee : ");
gets(name);
printf("Enter basic salary, HRA and DA of %s : ",name);
scanf("%f%f%f",&bs,&hra,&da);
gs = bs+hra+da;
printf("\nGross salary of %s is : %.2f",name,gs);
getch( );
}
Prog. 13 : WAP to accept the name & basic salary of an employee.
Calculate and display the gross salary of employee acc. to conditions given below :
HRA = 40% of basic salary.
DA = 30% of basic salary.
gs = bs+hra+da
12
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
char name[20];
float bs,hra,da,gs;
printf("Enter name of employee : ");
gets(name);
printf("Enter basic salary of %s : ",name);
scanf("%f",&bs);
hra = bs*((float)40/100);
da = bs*0.3;
gs = bs+hra+da;
printf("\nGross salary of %s is : %.2f",name,gs);
getch( );
}
Prog. 14 : WAP to display the area and perimeter of a rectangle
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int l,b;
float area,perimeter;
printf("Enter length and breadth of rectangle : ");
scanf("%d%d",&l,&b);
area = l*b;
perimeter = 2*(l+b);
printf("\nArea of rectangle is : %.2f",area);
printf("\nPerimeter of rectangle is : %.2f",perimeter);
getch( );
}
Prog. 15 : WAP to display the area and circumference of a circle
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
13 float rad,area,cmf,pi;
pi = (float)22/7;
printf("Enter radius of circle : ");
scanf("%f",&rad);
area = pi*rad*rad;
cmf = 2*pi*rad;
printf("\nArea of circle is : %.2f",area);
printf("\nCircumference of circle is : %.2f",cmf);
getch( );
}
Prog. 16 : WAP to accept the marks of a student in 5 different subjects and display the aggregate and total percentage (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int eng,hin,math,sc,comp;
float agg,per;
printf("Enter marks of 5 subjects : ");
scanf("%d%d%d%d%d",&eng,&hin,&math,&sc,&comp);
agg = eng+hin+math+sc+comp;
per = agg/5;
printf("\nAggregate marks are : %.2f",agg);
printf("\nTotal percentage is : %.2f",per);
getch( );
}
Prog. 17 : Mathematical functions (Square root)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( ) {
clrscr( );
float num;
printf("Enter number : ");
scanf("%f",&num);
printf("\nSquare root of %.2f is : %.2f",num,sqrt(num));
getch( );
}
14 Prog. 18 : Mathematical function (Power)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( ) {
clrscr( );
int n,p;
printf("Enter number and its power : ");
scanf("%d%d",&n,&p);
printf("\n%d raised to the power %d is : %.2f",n,p,pow(n,p));
getch( );
}
Prog. 19 : Mathematical function (Absolute value of integer & floating pt.
number)
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( ) {
clrscr( );
// Absolute value of Integer int n;
printf("Enter an integer : ");
scanf("%d",&n);
printf("\nAbsolute value of %d is : %d",n,abs(n));
// Absolute value of Floating pt. number float num;
printf("\n\nEnter a floating pt. number : ");
scanf("%f",&num);
printf("\nAbsolute value of %.2f is : %.2f",num,fabs(num));
getch( );
}
15
Prog. 20 : WAP to determine the area of a triangle by using Hero's formula.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( ) {
clrscr( );
float a,b,c,s,area;
printf("Enter three sides of a triangle : ");
scanf("%f%f%f",&a,&b,&c);
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("\nArea of triangle is : %.2f",area);
getch( );
}
Prog. 21 : WAP to accept the temperature in Fahrenheit and convert it into Centigrades
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
float f,c;
printf("Enter temperature in Fahrenheit : ");
scanf("%f",&f);
c = (f-32)/1.8;
printf("\nEqu. temperature in Centigrade is : %.2f",c);
getch( );
}
Prog. 22 : WAP to swap two numbers. (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int a,b,temp;
printf("Enter two numbers a and b : ");
16 scanf("%d%d",&a,&b);
printf("\nBefore swapping\n");
printf("a : %d\tb : %d",a,b);
temp=a;
a=b;
b=temp;
printf("\n\nAfter swapping\n");
printf("a : %d\tb : %d",a,b);
getch();
}
17
oo
Chapter - 02 : “Decision Making Statements”
1 RELATIONAL OPERATORS
Relational (Comparison) operators compare values to see if they are equal or if one of them is greater than or less than the other and so on.
Comparison operators in C produce only a one or zero result. They are often specified as “true” or “false” respectively. The following operators are used to perform the relational or comparison operations of the two variables or expressions
Operator Meaning
< Less than
> Greater than
< = Less than or equal to
> = Greater than or equal to
= = Equal to
! = Not equal to
The relational(comparison) operators are represented in the following syntax : expression_1 realtional_operator expression_2
For e.g.
Expression Result
3 > 4 False
6 < = 2 False
10 > -32 True
(23 * 7) > = (-67 + 89) True
8 = = 6 False
7 ! = 4 True
Difference between Equality (= =) and Assignment(=) Operators
The Equality operator = = is used to test check the equality of the given expression or a statement whereas Assignment operator = is used to assign the value of the variable or expression on the RHS to the LHS. For example, the expression
value = = 3
tests whether value is equal to 3 ? . The expression has the boolean value true if the comparison is true and boolean false if it is false. But the expression
18 value = 3
assigns 3 to the value. The whole expression, in this case, has the value 3 because that’s the value of the LHS.
2 DECISION MAKING STATEMENTS :
C language must be able to perform different sets of actions depending upon the circumstances. C has two major decision making (conditional) statements :
(i) The If-else statement (ii) The Switch statement
IF ELSE STATEMENT
There are five types of If Else Statements used in C : 1.
1.
1.
1. Simple If StatementSimple If StatementSimple If StatementSimple If Statement 2.2.
2.2. If Else StatementIf Else StatementIf Else StatementIf Else Statement 3.
3.
3.
3. Nested If StatementNested If StatementNested If StatementNested If Statement 4.4.
4.4. Nested If Else StatementNested If Else StatementNested If Else StatementNested If Else Statement 5.
5.
5.
5. Nested If Else Ladder (if else if statement)Nested If Else Ladder (if else if statement)Nested If Else Ladder (if else if statement)Nested If Else Ladder (if else if statement)
Simple If Statement
The general form of simple If statement look like this : if (condition)
Satement;
In this syntax, if the condition is true then only the statement inside if is executed, otherwise no execution takes place. For example,
int a=5;
if(a= =5)
printf(“%d”,a);
The above printf statement will print the value 5, because in this case, a is initialized as 5. Take another example,
int a=8;
if(a= =5)
printf(“%d”,a);
The above printf statement cannot executed, because in this case, condition is false because a is initialized as 8.
19 Program 1 : Simple If Statement
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int a=5;
if(a= =5)
printf("a : %d",a);
getch();
}
Program 2 : WAP to display the greatest out of three numbers using simple if statement
#include<stdio.h>
#include<conio.h>
void main() {
int a,b,c,max;
clrscr();
printf("Enter three numbers : ");
scanf("%d%d%d",&a,&b,&c);
max=a;
if(max<b) max=b;
if(max<c) max=c;
printf("\nLargest number is : %d",max);
getch();
}
3 LOGICAL OPERATORS
Logical operators are those operators which perform logical operations.
There are three different types of logical operators used in C language :
(a) Logical AND (b) Logical OR (c) Logical NOT
20 1 Logical AND operator ( && )
The Logical AND operator is used in the following manner : expression1 && expression2
The results of the logical AND operator are :
Situation Results True && True True True && False False False && True False False && False False For e.g.
if a = 4, b= 5 and c=6, then
(a < b) && (b<c) results in true because both expressions are true.
2 Logical OR operator ( || )
The Logical OR operator is used in the following manner : expression1 || expression2
The results of the logical OR operator are : Situation Results
True || True True True || False True False || True True False || False False For e.g.
if a = 4, b= 5 and c = 6, then
(a < b) || (b>c) results in true because first expression is true and second is false.
3 Logical NOT operator ( ! )
The Logical NOT operator is used in the following manner:
! (expression1)
The results of the logical operators are : Situation Results
! (True) False
! (False) True For e.g.
! (4 > 6) results in true because (4>6) is false.
! (5 = = 5) results in false because (5 = = 5) is true.
21
Program 3 : Logical Operators (Logical AND, logical OR & Logical NOT)
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int a=5,b=10,c=15;
printf("a : %d\tb : %d\tc : %d",a,b,c);
// Logical AND Operator
printf("\n\nLogical AND Operator\n");
printf("\n (a<b) && (b<c) : %d",(a<b) && (b<c));
printf("\n (a<b) && (b>c) : %d",(a<b) && (b>c));
printf("\n (a>b) && (b<c) : %d",(a>b) && (b<c));
printf("\n (a>b) && (b>c) : %d",(a>b) && (b>c));
// Logical OR Operator
printf("\n\nLogical OR Operator\n");
printf("\n (a<b) || (b<c) : %d",(a<b) || (b<c));
printf("\n (a<b) || (b>c) : %d",(a<b) || (b>c));
printf("\n (a>b) || (b<c) : %d",(a>b) || (b<c));
printf("\n (a>b) || (b>c) : %d",(a>b) || (b>c));
// Logical NOT Operator
printf("\n\nLogical NOT Operator\n");
printf("\n!(a==b) : %d",!(a==b));
printf("\n!(a!=b) : %d",!(a!=b));
getch();
}
Program 4 : WAP to display the greatest out of three numbers using logical operators
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int a,b,c;
printf("Enter three values :");
scanf("%d%d%d",&a,&b,&c);
if((a>b) && (a>c))
printf("\n%d is greater than %d and %d",a,b,c);
22 if((b>a) && (b>c))
printf("\n%d is greater than %d & %d",b,a,c);
if((c>a) && (c>b))
printf("\n%d is greater than %d & %d",c,a,b);
getch();
}
If Else Statement
The general form of If Else statement is : if (condition)
Statement-1;
else
Statement-2;
In the above syntax, if condition is true, then Statement-1 will be executed and if condition is false then Statement-2 will be executed. For e.g.
if(a>b)
printf(“%d is greater than %d”,a,b);
else
printf(“%d is greater than %d”,b,a);
In above example, the printf statement under if will be executed, if the value of a is greater than b, otherwise the printf statement under else will be executed.
Program 5 : WAP to display the greatest out of two numbers (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int a,b;
printf("Enter two numbers : ");
scanf("%d%d",&a,&b);
if(a>b)
printf("\n%d is greater than %d",a,b);
else
printf("\n%d is greater than %d",b,a);
getch();
}
23
Program 6 : WAP to accept the age of a person and display whether the person is eligible to vote or not ?
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int age;
printf("Enter age : ");
scanf("%d",&age);
if(age>=18)
printf("\nPerson is eligible to vote ");
else
printf("\nPerson is not eligible to vote ");
getch();
}
Program 7 : WAP to accept an integer from keyboard and display whether the given number is even or odd ? (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int n;
printf("Enter the value of n : ");
scanf("%d",&n);
if(n%2==0)
printf("\n%d is even",n);
else
printf("\n%d is odd",n);
getch();
}
Program 8 : WAP to accept an year from the keyboard and display whether the given year is a leap year or not ? (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main() {
24 clrscr();
int yr;
printf("Enter the year : ");
scanf("%d",&yr);
if(yr%4==0)
printf("\n%d is leap year",yr);
else
printf("\n%d is not leap year ",yr);
getch();
}
4 TERNARY OPERATORS OR CONDITIONAL OPERATORS ( ? : )
C programming offers a Conditional operator (? :) that stores a value depending upon a condition. This operator is called Ternary operator i.e. it requires three expressions. The general form of the Ternary Operator ?: is as follows :
Expression 1 ? Expression 2 : Expression 3
IF Expression 1 evaluates to true i.e. 1, then the value of the whole expression is the value of the Expression 2, otherwise, the value of the whole expression is the value of the Expression 3. For Example:
max = (a >b) ? a :b ;
The value of ‘a’ variable will be assigned to variable ‘max’ if the test expression a>b evaluates to true otherwise the value of variable ‘b’ will be assigned to variable ‘max’.
Program 9 : Program for Ternary operator to determine the greatest out of two numbers
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int a,b,max;
printf("Enter two numbers : ");
scanf("%d%d",&a,&b);
25
max=(a>b)?a:b; // Expression1 ? Expression2 : Expression3 printf("\nGreatest number is : %d",max);
getch();
}
Nested If statement :
The general form of nested If statement is :
if(condition-1) {
if(condition-2) Statement-1;
else
Statement-2;
}
There is no limit for nested if statements. We can nest if inside if and further if inside that if and so on.
Program 10 : WAP to accept three numbers and display them in sorted order
For example, If numbers are 6,9,2 then sorted order (Ascending) : 2,6,9 sorted order (Descending) : 9,6,2
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int a,b,c,max,med,small;
printf("Enter three numbers :");
scanf("%d%d%d",&a,&b,&c);
max=a;
if(max<b) max=b;
if(max<c) max=c;
if(max==a) {
if(b>c) {
26 med=b;
small=c;
} else {
med=c;
small=b;
} }
if(max==b) {
if(a>c) {
med=a;
small=c;
} else {
med=c;
small=a;
} }
if(max==c) {
if(a>b) {
med=a;
small=b;
} else {
med=b;
small=a;
} }
printf("\nSorted order (asending) : %d %d %d ",small,med,max);
printf("\nSorted order (decending) : %d %d %d",max,med,small);
getch();
}
Nested If Else Statement :
Different ways of constructing a Nested if-else statement are : (i) if (condition 1)
27 {
if(condition 2) statement 1;
else
statement 2;
} else
statement 3;
(ii) if(condition 1)
statement 1;
else {
if(condition 2) statement 2;
else
statement 3;
}
(iii) if(condition 1) {
if(condition 2) statement 1;
else
statement 2;
} else {
if(condition 3) statement 3;
else
statement 4;
}
Program 11 : WAP to display the greatest out of two numbers and also display if both numbers are equal.
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int a,b;
28 printf("Enter two numbers : ");
scanf("%d%d",&a,&b);
if(a==b)
printf("%d is equal to %d",a,b);
else {
if(a>b)
printf("%d is greater than %d",a,b);
else
printf("%d is greater than %d",b,a);
}
/*
OR
if(a!=b) {
if(a>b)
printf("%d is greater than %d",a,b);
else
printf("%d is greater than %d",b,a);
} else
printf("%d is equal to %d",a,b); */
getch();
}
Program 12 : WAP to display the greatest out of three numbers using nested if else statement (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int a,b,c;
printf("Enter three values :");
scanf("%d%d%d",&a,&b,&c);
if(a>b) {
if(a>c)
printf("%d is greatest ",a);
29 else
printf("%d is greatest ",c);
} else {
if(b>c)
printf("%d is greatest",b);
else
printf("%d is greatest",c);
} getch();
}
Nested If-Else Ladder :
The general form of a Nested if else Ladder is :
if(condition 1) Statement-1;
else
if(condition 2) Statement-2;
else
if(condition 3) Statement-3;
else
…………..
……….
else
Statement-n;
There is no limit of nested else statements in nested If-Else Ladder.
Program 13 : WAP to accept a day number [1-7] and display its equivalent day. For example, 1 for Sunday, 2 for Monday,……, 7 for Saturday.
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int dayno;
30 printf("Enter day number [1/2/3/4/5/6/7] : ");
scanf("%d",&dayno);
printf("\n");
if(dayno==1) printf("Sunday");
else
if(dayno==2) printf("Monday");
else
if(dayno==3) printf("Tuesday");
else
if(dayno==4)
printf("Wednesday");
else
if(dayno==5)
printf("Thursday");
else
if(dayno==6) printf("Friday");
else
if(dayno==7)
printf("Saturday");
else
printf("Invalid day number entered");
getch();
}
Program 14 : WAP to display the result of a student acc. to grades given below :
Grade Result
A First class with distinction
B First class
C Second class
D Conditionally passed
For all other grades Failed
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
31 char grade;
printf("Enter the grade [A/B/C/D] :");
scanf("%c",&grade);
printf("\n");
if(grade=='A')
printf("First class with distinction");
else
if(grade=='B')
printf("First class");
else
if(grade=='C')
printf("Second class");
else
if(grade=='D')
printf("Conditionally passed");
else
printf("Failed");
getch();
}
Program 15 : WAP to accept the basic salary of an employee and display the gross salary of employee acc. to conditions given below :
HRA DA
If BS>=10000 40% of BS 30% of BS 7500-9999 30% " " 20% " "
5000-7499 20% " " 10% " "
BS<5000 10% " " 0% " " (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
float bs,hra,da,gs;
printf("Enter basic salary of employee : ");
scanf("%f",&bs);
if(bs>=10000) {
hra=bs*((float)40/100);
da=bs*((float)30/100);
} else
if(bs>=7500) {
32 hra=bs*((float)30/100);
da=bs*((float)20/100);
} else
if(bs>=5000) {
hra=bs*((float)20/100);
da=bs*((float)10/100);
} else
if(bs<5000) {
hra=bs*((float)10/100);
da=0;
}
printf("\n HRA : %.2f \n DA : %.2f",hra,da);
gs=bs+hra+da;
printf("\n Gross Salary : %.2f",gs);
getch();
}
Program 16 : WAP to accept the total percentage of a student and display the result of the student acc. to conditions given below :
TOTAL PERCENTAGE RESULT
Percentage>=75% First class with distinction
60-74.9% First class
50-59.9% Second class
40-49.9% Conditionally Passed
Percentage<40% Fail
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
float per;
printf("Enter total percentage of student : ");
scanf("%f",&per);
printf("\n");
if(per>=75)
printf("First class with distinction");
else
33 if(per>=60)
printf("First class");
else
if(per>=50)
printf("Second class");
else
if(per>=40)
printf("Conditionally passed");
else
printf("Failed");
getch();
}
Program 17 : WAP to display the roots of a quadratic equation and also display whether the roots are real and equal, real and unequal or complex and imaginery.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
clrscr();
float a,b,c,d,r1,r2;
printf("Enter the cofficent's a,b,c of a quadratic equation : ");
scanf("%f%f%f",&a,&b,&c);
d=((b*b)-(4*a*c));
if(d==0) {
r1=r2=-b/(2*a);
printf("\nRoot-1 : %.2f\nRoot-2 : %.2f",r1,r2);
printf("\nRoots are real and equal");
} else if(d>0) {
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("\nRoot-1 : %.2f\nRoot-2 : %.2f",r1,r2);
printf("\nRoots are real and unequal");
} else
printf("\nRoots are complex and imaginery");
34 getch();
}
Switch Statement Switch Statement Switch Statement Switch Statement
C language provides a multiple-branch selection statement known as switch. This selection statement successively tests the value of an integer or character variable against a list of integer or character constants. When a match is found , the statements associated with that constant are executed. When no match is found then the statements associated with default case are executed.
The syntax of switch statement is as follows:
switch(int or char variable) {
case constant 1 : statement 1;
break;
case constant 2 : statement 2;
break;
case constant 3 : statement 3;
break;
………….
………….
case constant n-1 : statement n-1;
break;
default : statement n;
}
Program 1 : WAP to accept a day number [1-7] and display its equivalent day
(M.
Imp.)
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
35 int dayno;
printf("Enter day number [1/2/3/4/5/6/7] : ");
scanf("%d",&dayno);
printf("\n");
switch(dayno) {
case 1 : printf("Sunday");
break;
case 2 : printf("Monday");
break;
case 3 : printf("Tuesday");
break;
case 4 : printf("Wednesday");
break;
case 5 : printf("Thursday");
break;
case 6 : printf("Friday");
break;
case 7 : printf("Saturday");
break;
default : printf("Invalid day no. entered");
}
getch();
}
Program 2 : WAP to accept the grade of a student and display the result of student acc. to conditions given below :
GRADE RESULT
A First class with distinction
B First class
C Second class
D Conditionally passed For all other grades Failed
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
char grade;
printf("Enter grade [A/B/C/D] : ");
36 scanf("%c",&grade);
printf("\n");
switch(grade) {
case 'A' : printf("First class with distinction");
break;
case 'B' : printf("First class");
break;
case 'C' : printf("Second class");
break;
case 'D' : printf("conditionally passed");
break;
default : printf("Failed");
}
getch();
}
Program 3 : WAP to accept an alphabet from the keyboard and display whether it is a vowel or a consonant
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
char alpha;
printf("Enter an alphabet : ");
scanf("%c",&alpha);
printf("\n");
switch(alpha) {
case 'A' : case 'E' : case 'I' : case 'O' : case 'U' : case 'a' : case 'e' : case 'i' : case 'o' :
case 'u' : printf("%c is a Vowel",alpha);
break;
default : printf("%c is a Consonant",alpha);
}
37 getch();
}
Program 4 : WAP to accept two numbers and also accept one operator [+ , - , * , / , %] . Display the arithmetic operation of numbers acc. to arithmetic operator entered by the user.
(M. Imp.)
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int a,b;
char op;
printf("Enter two numbers :");
scanf("%d%d",&a,&b);
printf("Enter operator[+,-,*,/,%] :");
fflush(stdin);
scanf("%c",&op);
printf("\n");
switch(op) {
case '+' : printf("Sum of %d and %d is : %d",a,b,a+b);
break;
case '-' : printf("Difference of %d and %d is : %d ",a,b,a-b);
break;
case '*' : printf("Product of %d and %d is : %d",a,b,a*b);
break;
case '/' : if(b==0)
printf("Divide by zero error. Enter divisor other than zero");
else
printf("Quotient of %d and %d is : %d",a,b,a/b);
break;
case '%': if(b==0)
printf("Divide by zero error. Enter divisor other than zero");
else
printf("Remainder of %d and %d is : %d",a,b,a%b);
break;
default : printf("Invalid operator");
}
getch();
}
38
Program 5 : WAP to display the area acc. to choices given below : 1. Area of a rectangle
2. Area of a circle
3. Area of a square
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int choice;
printf(" AREA'S");
printf("\n---");
printf("\n1. Rectangle");
printf("\n2. Circle ");
printf("\n3. Square ");
printf("\n---");
printf("\nEnter your choice [1/2/3] : ");
scanf("%d",&choice);
printf("\n");
switch(choice) {
case 1 : int l,b,ar1;
printf("Enter length and breath of rectangle : ");
scanf("%d%d",&l,&b);
ar1=l*b;
printf("\nArea of rectangle is :%d",ar1);
break;
case 2 : float rad,ar2;
printf("Enter radius of circle :");
scanf("%f",&rad);
ar2=((float)22/7)*rad*rad;
printf("\nArea of circle is :%.2f",ar2);
break;
case 3 : int len,ar3;
printf("Enter length of square :");
scanf("%d",&len);
ar3=len*len;
printf("\nArea of square is :%d",ar3);
break;
default : printf("\nInvalid option");
39 }
getch();
}
Difference between switch-case and multiway if-else structure
Switch If-else
switch can only test for equality. if-else can evaluate a relational or
logical expression i.e. multiple conditions.
The switch statement selects its branches
by testing the value of same
variable(against a set of constants).
if-else construction lets you use a series of expressions that may involve unrelated variables and complex expressions.
40
Chapter - 03 : “Looping”
1 Increment ( + + ) And Decrement ( – – ) Operators
C provides ++ and -- operators. These operators are called increment and decrement operators. The increment operator ++ adds 1 to its operand.
++ x means x = x + 1 x ++ means x = x + 1 - - x means x = x – 1 x - - means x = x – 1
These operators exist in 2 types (i) Prefix
(ii) Postfix
Prefix means before its operand. For example ++ x
- - x
Postfix means after its operand. For example x ++
x - -
Prefix increment or decrement operators (For e.g. ++x or --x) follow the FIRST CHANGE THEN USE rule. They first change the value of their operand and then use a new value for the expression. For Example take the following expression :
int x,y = 5;
x = ++y;
In this example, in the first statement the value of y is assigned as 5. In the second statement, this value of y is first incremented by 1 and then the incremented value of y is assigned to x. After the second statement, the values of x and y are
x = 6;
y = 6;
Postfix increment or decrement operators (For e.g. x++ or x--) follow the FIRST USE THEN CHANGE rule. They first use the value of the operand in the expression and then increment or decrement the value of the operand. For Example take the following expression :
int x,y = 5;
x = y++;
In this example, in the first statement the value of y is assigned as 5. In the second statement, this value of y is first assigned to x and then the value of y is incremented by 1. After the second statement, the values of x and y are
x = 5;
41 y = 6;
Program 1 : Increment and Decrement operators
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int a=10,b=20;
printf("Original values \n a : %d \t b : %d",a,b);
printf("\n\n Prefix operators (First Change then use) :\n");
printf("\n++a : %d",++a);
printf("\n--b : %d",--b);
a=10;
b=20;
printf("\n\n Postfix operators (First use then Change) :\n");
printf("\na++ : %d",a++);
printf("\nb-- : %d",b--);
printf("\n\na : %d\tb : %d",a,b);
getch( );
}
Looping
There are some situations in C programming in which a particular set of statements are repeated again and again. To avoid the repetition of the statements, C allows a set of instructions to be performed repeatedly until a certain condition is fulfilled by using looping. The main advantage of using loops in C is that it reduces program size and complexity of the program. Looping consists of mainly three parts :
(a) Initialization (b) Test Condition
(c) Incrementer or Decrementor
Accordingly, there are three types of loops available in C.
(i) while loop (ii) for loop
(iii) do-while loop
42
2 While Loop
Syntax:
initialization;
while(condition) {
statement(s);
inc./dec.;
}
Program 2 : WAP to display a welcome message ten times using while loop
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i;
i=1;
while(i<=10) {
printf("\nWelcome to while loop");
i++;
}
getch( );
}
Program 3 : WAP to display the following series using while loop : 1 2 3 4 5 6 7 8 9 10
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i;
i=1;
while(i<=10 ) {
printf("\t%d",i);
43 i++;
}
getch( );
}
Program 4 : WAP to display the following series using while loop : 10 9 8 7 6 5 4 3 2 1
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i,j;
i=1;
j=10;
while(i<=10) {
printf("%d\t",j);
i ++;
j - -;
}
getch( );
}
Program 5 : WAP to display the following even series using while loop : 2 4 6 8 10 12 14 16 18 20
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i,j;
i=1;
j=2;
while(i<=10) {
printf("%d\t",j);
j=j+2;
i++;
}
44 getch( );
}
Program 6 : WAP to display the following odd series using while loop : 1 3 5 7 9 11 13 15 17 19
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i,j;
i=1;
j=1;
while(i<=10) {
printf("%d\t",j);
j=j+2;
i++;
}
getch( );
}
Program 7 : WAP to display the sum of digits of a given number
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int n,m,rem,sum=0;
printf("Enter number : ");
scanf("%d",&n);
m=n;
while(n>0) {
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf("\nSum of digits of %d is : %d",m,sum);
getch( );
45 }
Program 8 : WAP to display the reverse of a given number (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int n,m,rem,rev=0;
printf("Enter number : ");
scanf("%d",&n);
m=n;
while(n>0) {
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
}
printf("\nRev of digits of %d is : %d",m,rev);
getch( );
}
Program 9 : WAP to accept a number from keyboard and display whether the given number is palindrome or not (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
long int n,m,rem,rev=0;
printf("Enter number : ");
scanf("%ld",&n);
m=n;
while(n>0) {
rem=n%10;
rev=(rev*10)+rem;
n=n/10;
}
if(m= =rev)
printf("\n%ld is palindrome",m);
46 else
printf("\n%ld is not palindrome",m);
getch( );
}
Program 10 : WAP to accept a number from the keyboard and display whether it is an Armstrong number or not
For e.g. 3 3 3
153 = 1 + 5 + 3 = 1 + 125 + 27 = 153
Armstrong numbers are 1, 153, 370, 371 & 407 (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int n,m,rem,sum=0;
printf("Enter number : ");
scanf("%d",&n);
m=n;
while(n>0) {
rem=n%10;
sum=sum+(rem*rem*rem);
n=n/10;
}
if(sum= =m)
printf("\nNumber is armstrong");
else
printf("\nNumber is not armstrong");
getch( );
}
3 For Loop
Different forms of for loop :
(i) for(initialization ; condition ; inc./dec.) {
statement(s);
47 }
(ii) for(init.1, init.2, ... ; condition ; inc.1/dec.1, inc.2/dec.2, ...) {
statement(s);
}
(iii) for( ; condition ; inc./dec. ) {
statement(s);
}
(iv) for( ; condition ; ) {
statement(s);
}
(v) for( ; ; ) {
statement(s);
}
Program 1 : WAP to display a welcome message ten times using for loop
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i;
for(i=1;i<=10;i++)
printf("\nWelcome to looping");
getch( );
}
Program 2 : WAP to display the following series : 1 2 3 4 5 6 7 8 9 10
#include<stdio.h>
#include<conio.h>
void main( ) {
48 clrscr( );
int i;
for(i=1;i<=10;i++) printf("%d\t",i);
getch( );
}
Program 3 : WAP to display the following series : 10 9 8 7 6 5 4 3 2 1
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i;
for(i=10;i>=1;i--) printf("%d\t",i);
getch( );
}
Program 4 : WAP to display the following series : 1 10
2 9 3 8 4 7 5 6 6 5 7 4 8 3 9 2 10 1
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i,j;
for(i=1,j=10;i<=10;i++,j--) printf("%d\t%d\n",i,j);
getch( );
}
49
Program 5 : WAP to display the following even series : 2 4 6 8 10 12 14 16 18 20
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i,j;
for(i=1,j=2;i<=10;i++,j+=2) printf("%d\t", j);
getch( );
}
Program 6 : WAP to display the following odd series : 1 3 5 7 9 11 13 15 17 19
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i,j;
for(i=1,j=1;i<=10;i++,j+=2) printf("%d\t",j);
getch( );
}
Program 7 : WAP to display the following even series using for loop : 1 -1 1 -1 1 -1 1 -1 1 -1
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i,j;
for(i=1, j=1; i<=10; i++) {
printf("%d\t",j);
j=j*(-1);
}
getch( );
50 }
Program 8 : WAP to display the following even series using for loop : 1 - 2 3 - 4 5 - 6 7 - 8 9 -10
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int i,j,k;
for(i=1 , j=1 ; i<=10 ; i++) {
k=i*j;
printf("%d\t",k);
j=j*(-1);
}
getch( );
}
Program 9 : WAP to display the fibonacci series :
0 1 1 2 3 5 8 13 21 34 (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int pr=0,nx=1,nw,i;
printf("%d\t%d",pr,nx);
for(i=1;i<=8;i++) {
nw=pr+nx;
printf("\t%d",nw);
pr=nx;
nx=nw;
}
getch( );
}
Program 10 : WAP to accept a number and display its table (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main( )
51 {
clrscr( );
int n,j,k;
printf("Enter number :");
scanf("%d",&n);
for(j=1;j<=10;j++) {
k=n*j;
printf("%d * %d = %d\n",n,j,k);
}
getch( );
}
Program 11 : WAP to display the factorial of a number (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
long int n,fact=1,i;
printf("Enter number : ");
scanf("%ld",&n);
for(i=1;i<=n;i++) fact=fact*i;
printf("\nFactorial of %ld is : %ld",n,fact);
getch( );
}
Program 12 : WAP to accept a number and display whether it is prime or not
(M. Imp.)
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int n,i,f=0;
printf("Enter a number : ");
52 scanf("%d",&n);
for(i=2;i<n;i++) {
if(n%i==0) {
printf("\n%d is non prime",n);
f=1;
break;
} }
if(f= =0)
printf("\n%d is prime",n);
getch( );
}
1 Break Statement
The break statement enables a program to skip over part of the code. A break statement terminates the smallest enclosing while, do-while, for or switch statement. For example :
for(i=1,j=7 ; i<=10 ; i++) {
if(i = =5) {
printf(“%d”,j);
break;
}
printf(“%d”,i);
}
A break statement skips the rest of the loop and jumps over to the statement following the loop.
2 Continue Statement
The continue statement is another jump statement like the break statement as both the statements skip over a part of the code. But the difference between the break statement and continue statement is that the continue statement skips the rest of the loop statements and causes the next loop statements to be executed. For example :
void main()
53 {
clrscr( );
int num,deno;
float quot;
for(num=9,i =1; i<=10;i++) {
printf(“Enter denominator : ”);
scanf(“%d”,&deno);
if(deno= =0) {
printf(“The denominator cannot be zero. Enter again”);
continue;
} else
quot = (float)num/deno;
printf(“Quotient : %.2f\n”,quot);
}
getch( );
}
3 Go To Statement
The goto statement is used to change the program execution sequence by transferring the control to some other part of the program. The general syntax of the goto statement is :
goto label;
where label is a valid C++ identifier used to label the destination such that control could be transferred. For example :
void main() {
clrscr();
int a,b;
printf(”Enter two numbers : “);
scanf(“%d%d”,&a,&b);
if(a>b)
goto output1;
else
goto output2;
output1 :
54 printf(“Largest value : %d“,a);
goto stop;
output2 :
printf(“Largest value : %d“,b);
goto stop;
stop : getch();
}
4 Nested For Loops
Syntax of Nested for loop :
(i) for(initialization-1 ; condition-1 ; increment-1/decrement-1) {
for(initialization-2 ; condition-2 ; increment-2/decrement-2) {
………
statement(s);
………
} }
Program 13 : WAP to display the armstrong numbers between 1 and 1000
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( ) {
clrscr( );
int n,m,rem,sum=0;
for(n=1;n<=1000;n++) {
for(m=n,sum=0;m>0;m=m/10) {
rem=m%10;
sum=sum+pow(rem,3);
}
if(n= =sum) printf("%d\t",n);
}
getch( );
}
Program 14 : WAP to display the prime numbers between 1 and 100
55 (M. Imp.)
#include<stdio.h>
#include<conio.h>
void main( ) {
clrscr( );
int n,ctr,f=0;
for(n=1;n<=100;n++) {
for(f=0,ctr=2;ctr<n;ctr++) {
if(n%ctr= =0) {
f=1;
break;
} }
if(f= =0)
printf(" %d\t",n);
}
getch( );
}
Program 15 : WAP to display the following pattern : 1 2 3 4
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
#include<stdio.h>
#include<conio.h>
void main() {
clrscr();
int i,j;
for(i=1;i<=5;i++) {
for(j=1;j<=4;j++) printf("%d ",j);
printf("\n");
}
getch();
}