CS8261-C Programming Lab
CS8261-C Programming Lab
com
Syllabus: CS8261 C PROGRAMMING LABORATORY LT PC
0 042
OBJECTIVES:
To develop programs in C using basic constructs.
To develop applications in C using strings, pointers, functions, structures
To develop applications in C using file processing
LIST OF EXPERIMENTS:
om
1. Programs using I/O statements and expressions.
2. Programs using decision-making constructs.
3. Write a program to find whether the given year is leap year or Not? (Hint: not every centurion
year is a leap. For example 1700, 1800 and 1900 is not a leap year)
4. Design a calculator to perform the operations, namely, addition, subtraction, multiplication,
division and square of a number.
.c
5. Check whether a given number is Armstrong number or not?
6. Given a set of numbers like <10, 36, 54, 89, 12, 27>, find sum of weights based on the
following conditions
5 if it is a perfect cube
ul
4 if it is a multiple of 4 and divisible by 6
3 if it is a prime number
Sort the numbers based on the weight in the increasing order as shown below <10,its
pa
weight>,<36,its weight><89,its weight>
7. Populate an array with height of persons and find how many persons are above the average
height.
8. Populate a two dimensional array with height and weight of persons and compute the Body
jin
Mass Index of the individuals.
9. Given a string ―a$bcd./fg‖ find its reverse without changing the position of special
characters.
(Example input:a@gh%;j and output:j@hg%;a)
10. Convert the given decimal number into binary, octal and hexadecimal numbers using user
.re
defined functions.
11. From a given paragraph perform the following using built-in functions:
a. Find the total number of words.
b. Capitalize the first word of each sentence.
c. Replace a given word with another word.
w
16. Insert, update, delete and append telephone details of an individual or a company into a
telephone directory using random access file.
17. Count the number of account holders whose balance is less than the minimum balance
using sequential access file.
Mini Project
18. Create a ―Railway reservation system‖ with the following modules
3
www.rejinpaul.com
Booking
Availability checking
Cancellation
Prepare chart
TOTAL: 60 PERIODS OUTCOMES: Upon completion of the course, the students will be able to
Develop C programs for simple applications making use of basic constructs, arrays and
strings.
Develop C programs involving functions, recursion, pointers, and structures.
om
Design applications using sequential and random access file processing
.c
ul
pa
jin
.re
w
w
w
4
www.rejinpaul.com
Table of Contents
Ex. Page
Name of the Experiment
No. No.
1 Programs using I/O statements and expressions. 7
om
2 Programs using decision-making constructs. 9
4 Arithmetic operations. 13
.c
5 Armstrong number. 15
ul
6 Sort the numbers based on the weight. 17
11 String operations. 29
.re
16 Telephone directory. 43
w
17 Banking Application 49
5
www.rejinpaul.com
Annexure I - Additional C Programs for exercise 57
om
.c
ul
pa
jin
.re
w
w
w
6
www.rejinpaul.com
DATE :
AIM
om
ALGORITHM
.c
1. Start
2. Declare variables and initializations
3. Read the Input variable.
ul
4. Using I/O statements and expressions for computational processing.
5. Display the output of the calculations.
6. Stop
pa
PROGRAM
jin
/*
* Sum the odd and even numbers, respectively, from 1 to a given upperbound.
* Also compute the absolute difference.
* (SumOddEven.c)
.re
*/
#include <stdio.h> // Needed to use IO functions
int main() {
int sumOdd = 0; // For accumulating odd numbers, init to 0
w
7
www.rejinpaul.com
} else { // Odd number
sumOdd += number; // Add number into sumOdd
}
++number; // increment number by 1
}
om
absDiff = sumEven - sumOdd;
}
.c
// Print the results
printf("The sum of odd numbers is %d.\n", sumOdd);
printf("The sum of even numbers is %d.\n", sumEven);
ul
printf("The absolute difference is %d.\n", absDiff);
return 0;
}
pa
OUTPUT
jin
Enter the upper bound: 1000
The sum of odd numbers is 250000.
The sum of even numbers is 250500.
The absolute difference is 500.
.re
w
w
w
RESULT:
Thus a C Program using i/o statements and expressions was executed and the output was
obtained.
8
www.rejinpaul.com
EX.No. : 2 PROGRAM USING DECISION-MAKING CONSTRUCTS
DATE :
AIM
om
ALGORITHM
1. Start
.c
2. Declare variables and initializations
3. Read the Input variable.
4. Codes are given to different categories and da is calculated as follows:
ul
For code 1,10% of basic salary.
For code 2, 15% of basic salary.
pa
For code 3, 20% of basic salary.
For code >3 da is not given.
5. Display the output of the calculations .
jin
6. Stop
PROGRAM
.re
#include <stdio.h>
#include<conio.h>
void main ()
{
w
da=0.0;
printf("Enter employee name\n");
scanf("%[^\n]",name);
printf("Enter basic salary\n");
w
scanf("%f",&basic);
printf("Enter code of the Employee\n");
scanf("%d",&code);
switch (code)
{
case 1:
9
www.rejinpaul.com
da = basic * 0.10;
break;
case 2:
da = basic * 0.15;
break;
case 3:
da = basic * 0.20; break;
default :
da = 0;
}
om
salary = basic + da;
printf("Employee name is\n");
printf("%s\n",name);
printf ("DA is %f and Total salary is =%f\n",da, salary);
getch();
}
.c
ul
OUTPUT
RESULT
Thus a C Program using decision-making constructs was executed and the output was
obtained.
10
www.rejinpaul.com
EX.No. : 3 Leap year checking
DATE :
AIM
To write a C Program to find whether the given year is leap year or Not .
om
ALGORITHM
1. Start
.c
2. Declare variables
3. Read the Input .
4. Take a year as input and store it in the variable year.
ul
5. Using if,else statements to,
a) Check whether a given year is divisible by 400.
pa
b) Check whether a given year is divisible by 100.
c) Check whether a given year is divisible by 4.
6. If the condition at step 5.a becomes true, then print the ouput as “It is a leap year”.
jin
7. If the condition at step 5.b becomes true, then print the ouput as “It is not a leap
year”.
8. If the condition at step 5.c becomes true, then print the ouput as “It is a leap year”.
.re
9. If neither of the condition becomes true, then the year is not a leap year and print
the same.
10. Display the output of the calculations .
11. Stop
w
w
PROGRAM
/*
w
*/
void main()
11
www.rejinpaul.com
int year;
scanf("%d", &year);
if ((year % 400) == 0)
om
printf("%d is a leap year \n", year);
.c
else if ((year % 4) == 0)
ul
printf("%d is a leap year \n", year);
else
pa
printf("%d is not a leap year \n", year);
}
jin
.re
OUTPUT
Enter a year
2012
w
Enter a year
2009
2009 is not a leap year
w
RESULT
Thus a C Program for Leap year checking was executed and the output was obtained.
12
www.rejinpaul.com
EX.No. : 4 Arithmetic operations
DATE :
AIM
om
ALGORITHM
.c
1. Start
2. Declare variables
3. Read the Inputs .
ul
4. Calculate Arithmetic operations(+,-,*,/,pow) for the input of two numbers.
5. Display the output of the calculations .
6. Stop
pa
PROGRAM
jin
/*
* C Program for Addition, Subtraction, Multiplication, Division
* and square of two numbers
*/
.re
#include <stdio.h>
#include <conio.h>
int main(){
/* Variable declation */
w
float quotient;
13
www.rejinpaul.com
/* Subtracting two numbers */
difference = firstNumber - secondNumber;
/* Multiplying two numbers*/
product = firstNumber * secondNumber;
/* Dividing two numbers by typecasting one operand to float*/
quotient = (float)firstNumber / secondNumber;
/* returns remainder of after an integer division */
square = firstNumber *firstNumber;
om
printf("\nDifference = %d", difference);
printf("\nMultiplication = %d", product);
printf("\nDivision = %.3f", quotient);
printf("\n Square= %ld", square);
getch();
.c
return 0;
}
ul
pa
jin
OUTPUT
Sum = 29
Difference = 21
Multiplication = 100
Division = 6.250
Square = 625
w
w
w
RESULT
Thus a C Program for Arithmetic operations was executed and the output was obtained.
14
www.rejinpaul.com
EX.No. : 5 Armstrong number
DATE :
AIM
om
ALGORITHM
.c
1. Start
2. Declare variables
3. Read the Input number.
ul
4. Calculate sum of cubic of individual digits of the input.
5. Match the result with input number.
pa
6. If match, Display the given number is Armstrong otherwise not.
7. Stop
jin
PROGRAM
/*
.re
*/
#include <stdio.h>
w
#include <math.h>
w
void main()
w
15
www.rejinpaul.com
printf ("enter a number");
scanf("%d", &number);
temp = number;
while (number != 0)
om
rem = number % 10;
.c
number = number / 10;
ul
if (sum == temp)
}
.re
w
OUTPUT
enter a number370
The given no is armstrong no
w
w
RESULT
Thus a C Program for Armstrong number checking was executed and the output was
obtained.
16
www.rejinpaul.com
EX.No. : 6 Sort the numbers based on the weight.
DATE :
AIM
om
following conditions
5 if it is a perfect cube
4 if it is a multiple of 4 and divisible by 6
3 if it is a prime number
.c
Sort the numbers based on the weight in the increasing order as shown below <10,its
weight>,<36,its weight><89,its weight>
ul
ALGORITHM
pa
1. Start
jin
2. Declare variables
3. Read the number of elements .
4. Get the individual elements.
.re
PROGRAM
w
#include <stdio.h>
#include <math.h>
void main()
{
int nArray[50],wArray[50],nelem,i,j,t;
17
www.rejinpaul.com
clrscr();
printf("\nEnter the number of elements in an array : ");
scanf("%d",&nelem);
printf("\nEnter %d elements\n",nelem);
for(i=0;i<nelem;i++)
scanf("%d",&nArray[i]);
//Calculate the weight
for(i=0; i<nelem; i++)
{
wArray[i] = 0;
om
if(percube(nArray[i]))
wArray[i] = wArray[i] + 5;
.c
if(prime(nArray[i]))
wArray[i] = wArray[i] + 3;
ul
}
// Sorting an array
for(i=0;i<nelem;i++)
for(j=i+1;j<nelem;j++)
if(wArray[i] > wArray[j])
pa
{
t = wArray[i];
wArray[i] = wArray[j];
jin
wArray[j] = t;
}
getch();
{
int flag=1,i;
for(i=2;i<=num/2;i++)
w
if(num%i==0)
{
flag=0;
w
break;
}
return flag;
}
int percube(int num)
{
int i,flag=0;
18
www.rejinpaul.com
for(i=2;i<=num/2;i++)
if((i*i*i)==num)
{
flag=1;
break;
}
return flag;
}
om
OUTPUT
Enter the number of elements in an array :5
Enter 5 elements:
8
.c
11
216
24
ul
34
<34,0>
<11,3>
pa
<24,4>
<8,5>
<216,9>
jin
Explanation:
8 is a perfect cube of 2, not a prime number and not a multiple of 4 & divisible of 6 so the
answer is 5
11 is a prime number so the answer is 3
216 is a perfect cube and multiple of 4 & divisible by 6 so the answer is 5+4 = 9
.re
24 is not a perfect cube and not a prime number and multiple of 4 & divisible by 6 so the
answer is 4
34 not satisfied all the conditions so the answer is 0
w
w
w
RESULT
Thus a C Program for Sort the numbers based on the weight was executed and the output
was obtained.
19
www.rejinpaul.com
DATE :
AIM
To write a C Program to populate an array with height of persons and find how
om
many persons are above the average height.
ALGORITHM
.c
1. Start
ul
2. Declare variables
3. Read the total number of persons and their height.
4. Calculate avg=sum/n and find number of persons their h>avg.
pa
5. Display the output of the calculations .
6. Stop
jin
PROGRAM
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,sum=0,count=0,height[100];
w
float avg;
clrscr();
//Read Number of persons
w
20
www.rejinpaul.com
//Counting
for(i=0;i<n;i++)
if(height[i]>avg)
count++;
//display
printf("\nAverage Height of %d persons is : %.2f\n",n,avg);
printf("\nThe number of persons above average : %d ",count);
getch();
}
om
OUTPUT
Enter the Number of Persons : 5
.c
155
162
158
ul
154
RESULT
Thus a C Program average height of persons was executed and the output was obtained.
21
www.rejinpaul.com
EX.No. : 8 Body Mass Index of the individuals
DATE :
AIM
To write a C Program to Populate a two dimensional array with height and weight of
persons and compute the Body Mass Index of the individuals..
om
ALGORITHM
.c
1. Start
2. Declare variables
3. Read the number of persons and their height and weight.
ul
4. Calculate BMI=W/H2for each person
5. Display the output of the BMI for each person.
6. Stop
pa
PROGRAM
jin
#include<stdio.h>
#include<math.h>
int main(void){
.re
int n,i,j;
float massheight[n][2];
float bmi[n];
w
for(i=0;i<n;i++){
w
for(j=0;j<2;j++){
switch(j){
case 0:
printf("\nPlease enter the mass of the person %d in kg: ",i+1);
scanf("%f",&massheight[i][0]);
break;
22
www.rejinpaul.com
case 1:
printf("\nPlease enter the height of the person %d in meter: ",i+1);
scanf("%f",&massheight[i][1]);
break;}
}
}
for(i=0;i<n;i++){
om
bmi[i]=massheight[i][0]/pow(massheight[i][1],2.0);
printf("Person %d's BMI is %f\n",i+1,bmi[i]);
}
return 0;
}
.c
ul
OUTPUT
pa
How many people's BMI do you want to calculate?
2
Please enter the mass of the person 1 in kg: 88
jin
Please enter the height of the person 1 in meter: 1.8288
RESULT
Thus a C Program Body Mass Index of the individuals was executed and the output was
obtained.
23
www.rejinpaul.com
EX.No. : 9 Reverse of a given string
DATE :
AIM
om
ALGORITHM
.c
1. Start
2. Declare variables .
3. Read a String.
ul
4. Check each character of string for alphabets or a special character by using
isAlpha() .
pa
5. Change the position of a character vice versa if it is alphabet otherwise remains
same.
6. Repeat step 4 until reach to the mid of the position of a string.
jin
7. Display the output of the reverse string without changing the position of special
characters .
8. Stop
.re
PROGRAM
#include <stdio.h>
#include <string.h>
w
#include <conio.h>
void swap(char *a, char *b)
{
w
char t;
t = *a;
*a = *b;
*b = t;
w
// Main program
void main()
{
char str[100];
24
www.rejinpaul.com
// Function Prototype
void reverse(char *);
int isAlpha(char);
void swap(char *a ,char *b);
clrscr();
printf("Enter the Given String : ");
// scanf("%[^\n]s",str);
gets(str);
reverse(str);
printf("\nReverse String : %s",str);
om
getch();
}
.c
int r = strlen(str) - 1, l = 0;
ul
// 'l' and 'r'
while (l < r)
{
// Ignore special characters
if (!isAlpha(str[l]))
pa
l++;
else if(!isAlpha(str[r]))
r--;
jin
else
{
swap(&str[l], &str[r]);
l++;
.re
r--;
}
}
}
w
int isAlpha(char x)
w
{
return ( (x >= 'A' && x <= 'Z') ||
(x >= 'a' && x <= 'z') );
w
25
www.rejinpaul.com
OUTPUT
om
.c
ul
pa
jin
.re
w
w
w
RESULT
Thus a C Program for reverse of a given String was executed and the output was obtained.
26
www.rejinpaul.com
EX.No. : 10 Conversion of Decimal number into other bases
DATE :
AIM
To write a C Program to Convert the given decimal number into binary, octal and
hexadecimal numbers using user defined functions.
om
ALGORITHM
.c
1. Start
2. Declare variables.
3. Read a decimal number.
ul
4. Develop the procedure for conversion of different base by modulus and divide
operator.
pa
5. Display the output of the conversion value.
6. Stop
jin
PROGRAM
#include <stdio.h>
#include <conio.h>
.re
*s2 = temp;
}
void reverse(char *str, int length)
w
{
int start = 0;
int end = length -1;
while (start < end)
w
{
swap(&str[start], &str[end]);
start++;
end--;
}
}
27
www.rejinpaul.com
char* convert(int num, char str[100], int base)
{
int i = 0;
if (num == 0)
{
str[i++] = '0';
str[i] = '\0';
return str;
}
while (num != 0)
om
{
int rem = num % base;
str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0';
num = num/base;
}
str[i] = '\0'; // Append string terminator
.c
// Reverse the string
reverse(str, i);
return str;
ul
}
void main()
{
char str[100];
int n;
pa
clrscr();
printf("Enter the given decimal number : ");
scanf("%d",&n);
jin
printf("\nThe Binary value : %s\n",convert(n,str,2));
printf("\nThe Octal value : %s\n",convert(n,str,8));
printf("\nThe Hexa value : %s\n",convert(n,str,16));
getch();
}
.re
OUTPUT
w
RESULT
Thus a C Program for conversion of decimal number into other bases was executed and the
output was obtained.
28
www.rejinpaul.com
EX.No. : 11 String operations
DATE :
AIM
om
a. Find the total number of words.
b. Capitalize the first word of each sentence.
c. Replace a given word with another word.
.c
ALGORITHM
ul
1. Start
2. Declare variables
3. Read the text.
pa
4. Display the menu options
5. Compare each character with tab char ‘\t’ or space char ‘ ‘ to count no of words
jin
6. Find the first word of each sentence to capitalize by checks to see if a character is a
punctuation mark used to denote the end of a sentence. (! . ?)
7. Replace the word in the text by user specific word if match.
8. Display the output of the calculations .
9. Repeat the step 4 till choose the option stop.
.re
10.Stop
PROGRAM
w
#include <stdio.h>
#include <stdlib.h>
w
#include <string.h>
void replace (char *, char *, char *);
int main()
{
w
char choice.str[200];
int i, words;
char s_string[200], r_string[200];
/* Input text from user */
printf("Enter any text:\n ");
gets(str);
29
www.rejinpaul.com
do
{
printf("\n1. Find the total number of words \n");
printf("2. Capitalize the first word of each sentence \n");
printf("3. Replace a given word with another word \n");
printf("4. Stop\n");
printf("Enter your choice : ");
choice=getchar();
switch(choice)
om
{
case '1' :
i = 0;
words = 1;
.c
while(str[i] != '\0')
{
/* If the current character(str[i]) is white space */
ul
if(str[i]==' ' || str[i]=='\n' || str[i]=='\t')
{
words++;
}
pa
i++;
}
jin
printf("\nTotal number of words = %d", words);
break;
case '2' :
.re
i = 0;
/* Runs a loop till end of text */
while(str[i] != '\0')
{
/* Checks to see if a character is a punctuation mark used to denote
w
i++;
while(str[i]!=' ' || str[i]!='\n' || str[i]!='\t || str[i] != '\0'’)
{putchar (toupper(str[++i]));
w
i++;
}
}
else
putchar (str[i]);
i++;
30
www.rejinpaul.com
}
break;
case '3' :
Write a user defined function to replace the first occurrence of the search string with the
replace string.
Recursively call the function until there is no occurrence of the search string.*/
om
printf("\nPlease enter the string to search: ");
fflush(stdin);
gets(s_string);
.c
printf("\nPlease enter the replace string ");
fflush(stdin);
gets(r_string);
ul
replace(str, s_string, r_string); pa
puts(str);
break;
case '4' :
exit(0);
jin
}
printf("\nPress any key to continue....");
getch();
}
while(choice!=’4’);
.re
return 0;
}
char * ch;
//copy all the content to buffer before the first occurrence of the search string
strncpy(buffer, str, ch-str);
31
www.rejinpaul.com
buffer[ch-str] = 0;
om
}
.c
OUTPUT
Enter any text:
ul
I like C and C++ programming!
4. Stop
Enter your choice : 4
w
w
w
RESULT
Thus a C Program String operations was executed and the output was obtained.
32
www.rejinpaul.com
EX.No. : 12 Towers of Hanoi using Recursion
DATE :
AIM
om
ALGORITHM
1. Start
.c
2. Declare variables
3. Read the Input for number of discs.
4. Check the condition for each transfer of discs using recursion.
ul
5. Display the output of the each move .
6. Stop
pa
PROGRAM
jin
/*
Rules of Tower of Hanoi:
and then placing it on the top of another stack i.e. only a topmost disk on the stack
can be moved.
Larger disk cannot be placed over smaller disk; placing of disk should be in
increasing order.
*/
w
#include <stdio.h>
#include <conio.h>
void towerofhanoi(int n, char from, char to, char aux)
w
{
if (n == 1)
{
printf("\n Move disk 1 from peg %c to peg %c", from, to);
w
return;
}
towerofhanoi(n-1, from, aux, to);
printf("\n Move disk %d from peg %c to peg %c", n, from, to);
towerofhanoi(n-1, aux, to, from);
}
33
www.rejinpaul.com
int main()
{
int n;
clrscr();
printf("Enter the number of disks : ");
scanf("%d",&n); // Number of disks
towerofhanoi(n, 'A', 'C', 'B'); // A, B and C are names of peg
getch();
return 0;
om
}
.c
ul
OUTPUT
Enter the number of disks : 3
Move disk 1 from peg A to peg C
Move disk 2 from peg A to peg B
Move disk 1 from peg C to peg B
pa
Move disk 3 from peg A to peg C
Move disk 1 from peg B to peg A
Move disk 2 from peg B to peg C
jin
Move disk 1 from peg A to peg C
.re
w
w
w
RESULT
Thus a C Program Towers of Hanoi using Recursion was executed and the output was
obtained.
34
www.rejinpaul.com
DATE :
AIM
om
ALGORITHM
.c
1. Start
2. Declare variables and create an array
ul
3. Read the Input for number of elements and each element.
4. Develop a function to sort the array by passing reference
5. Compare the elements in each pass till all the elements are sorted.
pa
6. Display the output of the sorted elements .
7. Stop
jin
PROGRAM
#include <stdio.h>
.re
#include <conio.h>
void main()
{
int n,a[100],i;
w
void sortarray(int*,int);
clrscr();
printf("\nEnter the Number of Elements in an array : ");
w
scanf("%d",&n);
printf("\nEnter the Array elements\n");
for(i=0;i<n;i++)
w
scanf("%d",&a[i]);
sortarray(a,n);
printf("\nAfter Sorting....\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}
35
www.rejinpaul.com
om
arr[j] = temp;
}
}
.c
ul
OUTPUT
33
45
67
w
w
w
RESULT
Thus a C Program Sorting using pass by reference was executed and the output was
obtained.
36
www.rejinpaul.com
EX.No. : 14 Salary slip of employees
DATE :
AIM
om
ALGORITHM
1. Start
2. Declare variables
.c
3. Read the number of employees .
4. Read allowances, deductions and basic for each employee.
ul
5. Calculate net pay= (basic+ allowances)-deductions
6. Display the output of the Pay slip calculations for each employee.
7. Stop
pa
PROGRAM
#include<stdio.h>
jin
#include<conio.h>
#include "stdlib.h"
struct emp
{
int empno ;
.re
{
int I,n=0;
int more_data = 1;
w
current_ptr = head_ptr;
while (more_data)
{
{
printf("\nEnter the employee number : ") ;
scanf("%d", & current_ptr->empno) ;
printf("\nEnter the name : ") ;
37
www.rejinpaul.com
scanf("%s",& current_ptr->name) ;
printf("\nEnter the basic pay, allowances & deductions : ") ;
scanf("%d %d %d", & current_ptr ->bpay, & current_ptr ->allow, & current_ptr -
>ded) ;
e[i].npay = e[i].bpay + e[i].allow - e[i].ded ;
n++;
printf("Would you like to add another employee? (y/n): ");
scanf("%s", answer);
if (answer!= 'Y')
om
{
current_ptr->next = (struct eme *) NULL;
more_data = 0;
}
else
{
.c
current_ptr->next = (struct emp *) malloc (sizeof(struct emp));
current_ptr = current_ptr->next;
}
ul
}
}
printf("\nEmp. No. Name \t Bpay \t Allow \t Ded \t Npay \n\n") ;
current_ptr = head_ptr;
pa
for(i = 0 ; i < n ; i++)
{
printf("%d \t %s \t %d \t %d \t %d \t %d \n", current_ptr->empno,
jin
current_ptr->name, current_ptr->bpay, current_ptr->allow, current_ptr->ded,
current_ptr->npay) ;
current_ptr=current_ptr->next;
}
getch() ;
.re
}
w
w
OUTPUT
w
38
www.rejinpaul.com
Enter the employee number : 102
Enter the name : Babu
Enter the basic pay, allowances & deductions : 7000 1500 750
Emp.No. Name Bpay Allow Ded Npay
101 Arun 5000 1000 250 5750
102 Babu 7000 1500 750 7750
om
.c
ul
pa
jin
.re
w
w
w
RESULT
Thus a C Program Salary slip of employees was executed and the output was obtained.
39
www.rejinpaul.com
DATE :
AIM
om
subjects using structures and functions.
ALGORITHM
.c
1. Start
ul
2. Declare variables
3. Read the number of students .
4. Read the student mark details
pa
5. Calculate internal mark by i=total of three test marks / 3 for each subject per
student.
6. Display the output of the calculations for all the students .
jin
7. Stop
PROGRAM
.re
#include<stdio.h>
#include<conio.h>
struct stud{
char name[20];
long int rollno;
w
int marks[5,3];
int i[5];
w
}students[10];
void calcinternal(int);
int main(){
w
int a,b,j,n;
clrscr();
printf("How many students : \n");
scanf("%d",&n);
for(a=0;a<n;++a){
clrscr();
printf("\n\nEnter the details of %d student : ", a+1);
40
www.rejinpaul.com
printf("\n\nEnter student %d Name : ", a);
scanf("%s", students[a].name);
printf("\n\nEnter student %d Roll Number : ", a);
scanf("%ld", &students[a].rollno);
total=0;
for(b=0;b<=4;++b){
for(j=0;j<=2;++j){
printf("\n\nEnter the test %d mark of subject-%d : ",j+1, b+1);
scanf("%d", &students[a].marks[b,j]);
}
om
}
}
calcinternal(n);
for(a=0;a<n;++a){
clrscr();
printf("\n\n\t\t\t\tMark Sheet\n");
.c
printf("\nName of Student : %s", students[a].name);
printf("\t\t\t\t Roll No : %ld", students[a].rollno);
printf("\n------------------------------------------------------------------------");
ul
for(b=0;b<5;b++){
printf("\n\n\t Subject %d internal \t\t :\t %d", b+1, students[a].i[b]);
}
printf("\n\n------------------------------------------------------------------------\n");
getch();
pa
}
return(0);
}
jin
void calcinternal(int n)
{
int a,b,j,total;
for(a=1;a<=n;++a){
.re
for(b=0;b<5;b++){
total=0;
for(j=0;j<=2;++j){
total += students[a].marks[b,j];
}
w
students[a].i[b]=total/3;
}
}
w
}
w
OUTPUT
41
www.rejinpaul.com
Enter the test 2 mark of subject-1 : 56
Enter the test 3 mark of subject-1 : 76
Enter the test 1 mark of subject-2 : 85
Enter the test 2mark of subject-2 : 75
Enter the test 3mark of subject-2 : 75
Enter the test 1mark of subject-3 : 66
Enter the test 2 mark of subject-3 : 86
Enter the test 3 mark of subject-3 : 70
Enter the test 1 mark of subject-4 : 25
Enter the test 2mark of subject-4 : 35
om
Enter the test 3mark of subject-4 : 61
Enter the test 1 mark of subject-5 : 45
Enter the test 2mark of subject-5 : 75
Enter the test 3mark of subject-5 : 60
.c
Mark Sheet
Name of Student : H.Xerio Roll No : 536435
------------------------------------------------------------------------
ul
subject 1 internal : 59
subject 2 internal : 78
subject 3 internal : 74
subject 4 internal : 40
pa
subject 5 internal : 60
------------------------------------------------------------------------
jin
.re
w
w
RESULT
w
Thus a C Program for Internal marks of students was executed and the output was
obtained.
42
www.rejinpaul.com
DATE :
AIM
To write a C Program to add, delete ,display ,Search and exit options for telephone
om
details of an individual into a telephone directory using random access file.
ALGORITHM
.c
1. Start.
ul
2. Declare variables, File pointer and phonebook structures.
3. Create menu options.
4. Read the option .
pa
5. Develop procedures for each option.
6. Call the procedure (Add, delete ,display ,Search and exit)for user chosen option.
7. Display the message for operations performed.
jin
8. Stop
PROGRAM
.re
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
w
char LastName[20];
char PhoneNumber[20];
} phone;
w
void AddEntry(phone * );
void DeleteEntry(phone * );
void PrintEntry(phone * );
void SearchForNumber(phone * );
43
www.rejinpaul.com
int counter = 0;
char FileName[256];
FILE *pRead;
FILE *pWrite;
om
phonebook = (phone*) malloc(sizeof(phone)*100);
int iSelection = 0;
if (phonebook == NULL)
{
.c
printf("Out of Memory. The program will now exit");
return 1;
ul
}
else {}
do
{
pa
printf("\n\t\t\tPhonebook Menu");
printf("\n\n\t(1)\tAdd Friend");
printf("\n\t(2)\tDelete Friend");
jin
printf("\n\t(3)\tDisplay Phonebook Entries");
printf("\n\t(4)\tSearch for Phone Number");
printf("\n\t(5)\tExit Phonebook");
printf("\n\nWhat would you like to do? ");
scanf("%d", &iSelection);
.re
if (iSelection == 1)
{
AddEntry(phonebook);
w
}
w
if (iSelection == 2)
{
w
DeleteEntry(phonebook);
}
if (iSelection == 3)
{
PrintEntry(phonebook);
44
www.rejinpaul.com
}
if (iSelection == 4)
{
SearchForNumber(phonebook);
}
om
if (iSelection == 5)
{
printf("\nYou have chosen to exit the Phonebook.\n");
return 0;
}
.c
} while (iSelection <= 4);
}
ul
void AddEntry (phone * phonebook)
{
pWrite = fopen("phonebook_contacts.dat", "a");
if ( pWrite == NULL )
pa
{
perror("The following error occurred ");
exit(EXIT_FAILURE);
jin
}
else
{
counter++;
realloc(phonebook, sizeof(phone));
.re
fclose(pWrite);
}
}
45
www.rejinpaul.com
int i = 0;
char deleteFirstName[20]; //
char deleteLastName[20];
om
{
if (strcmp(deleteFirstName, phonebook[x].FirstName) == 0)
{
if (strcmp(deleteLastName, phonebook[x].LastName) == 0)
{
for ( i = x; i < counter - 1; i++ )
.c
{
strcpy(phonebook[i].FirstName, phonebook[i+1].FirstName);
strcpy(phonebook[i].LastName, phonebook[i+1].LastName);
ul
strcpy(phonebook[i].PhoneNumber, phonebook[i+1].PhoneNumber);
}
printf("Record deleted from the phonebook.\n\n");
--counter;
return;
pa
}
}
}
jin
{
int x = 0;
if ( pRead == NULL)
{
perror("The following error occurred: ");
w
exit(EXIT_FAILURE);
}
else
w
{
for( x = 0; x < counter; x++)
{
printf("\n(%d)\n", x+1);
printf("Name: %s %s\n", phonebook[x].FirstName, phonebook[x].LastName);
printf("Number: %s\n", phonebook[x].PhoneNumber);
}
46
www.rejinpaul.com
}
fclose(pRead);
}
om
printf("\nPlease type the name of the friend you wish to find a number for.");
printf("\n\nFirst Name: ");
scanf("%s", TempFirstName);
printf("Last Name: ");
scanf("%s", TempLastName);
.c
for (x = 0; x < counter; x++)
{
if (strcmp(TempFirstName, phonebook[x].FirstName) == 0)
ul
{
if (strcmp(TempLastName, phonebook[x].LastName) == 0)
{
pa
printf("\n%s %s's phone number is %s\n", phonebook[x].FirstName,
phonebook[x].LastName, phonebook[x].PhoneNumber);
}
}
jin
}
}
OUTPUT
.re
Phonebook Menu
(1) Add Friend
(2) Delete Friend"
(3) Display Phonebook Entries
w
47
www.rejinpaul.com
Phonebook Menu
(1) Add Friend
(2) Delete Friend"
om
What would you like to do? 5
You have chosen to exit the Phonebook.
.c
ul
pa
jin
.re
w
w
w
RESULT
48
www.rejinpaul.com
DATE :
AIM
To write a C Program to Count the number of account holders whose balance is less
om
than the minimum balance using sequential access file.
ALGORITHM
.c
1. Start
ul
2. Declare variables and file pointer.
3. Display the menu options.
4. Read the Input for transaction processing.
pa
5. Check the validation for the input data.
6. Display the output of the calculations .
7. Repeat step 3 until choose to stop.
jin
8. Stop
PROGRAM
.re
/* Count the number of account holders whose balance is less than the minimum balance
using sequential access file.
*/
#include <stdio.h>
#include <stdlib.h>
w
#include <conio.h>
#include <string.h>
#define MINBAL 500
w
struct Bank_Account
{
char no[10];
w
char name[20];
char balance[15];
};
struct Bank_Account acc;
void main()
{
long int pos1,pos2,pos;
49
www.rejinpaul.com
FILE *fp;
char *ano,*amt;
char choice;
int type,flag=0;
float bal;
do
{
clrscr();
fflush(stdin);
printf("1. Add a New Account Holder\n");
om
printf("2. Display\n");
printf("3. Deposit or Withdraw\n");
printf("4. Number of Account Holder Whose Balance is less than the Minimum
Balance\n");
printf("5. Stop\n");
printf("Enter your choice : ");
.c
choice=getchar();
switch(choice)
{
ul
case '1' :
fflush(stdin);
fp=fopen("acc.dat","a");
printf("\nEnter the Account Number : ");
gets(acc.no);
pa
printf("\nEnter the Account Holder Name : ");
gets(acc.name);
printf("\nEnter the Initial Amount to deposit : ");
jin
gets(acc.balance);
fseek(fp,0,2);
fwrite(&acc,sizeof(acc),1,fp);
fclose(fp);
break;
.re
case '2' :
fp=fopen("acc.dat","r");
if(fp==NULL)
printf("\nFile is Empty");
else
w
{
printf("\nA/c Number\tA/c Holder Name Balance\n");
while(fread(&acc,sizeof(acc),1,fp)==1)
w
printf("%-10s\t\t%-20s\t%s\n",acc.no,acc.name,acc.balance);
fclose(fp);
}
w
break;
case '3' :
fflush(stdin);
flag=0;
fp=fopen("acc.dat","r+");
printf("\nEnter the Account Number : ");
gets(ano);
50
www.rejinpaul.com
for(pos1=ftell(fp);fread(&acc,sizeof(acc),1,fp)==1;pos1=ftell(fp))
{
if(strcmp(acc.no,ano)==0)
{
printf("\nEnter the Type 1 for deposit & 2 for withdraw : ");
scanf("%d",&type);
printf("\nYour Current Balance is : %s",acc.balance);
printf("\nEnter the Amount to transact : ");
fflush(stdin);
gets(amt);
om
if(type==1)
bal = atof(acc.balance) + atof(amt);
else
{
bal = atof(acc.balance) - atof(amt);
if(bal<0)
.c
{
printf("\nRs.%s Not available in your A/c\n",amt);
flag=2;
ul
break;
}
}
flag++;
break;
pa
}
jin
}
if(flag==1)
{
pos2=ftell(fp);
pos = pos2-pos1;
.re
fseek(fp,-pos,1);
sprintf(amt,"%.2f",bal);
strcpy(acc.balance,amt);
fwrite(&acc,sizeof(acc),1,fp);
}
w
else if(flag==0)
printf("\nA/c Number Not exits... Check it again");
fclose(fp);
w
break;
case '4' :
w
fp=fopen("acc.dat","r");
flag=0;
while(fread(&acc,sizeof(acc),1,fp)==1)
{
bal = atof(acc.balance);
if(bal<MINBAL)
flag++;
51
www.rejinpaul.com
}
printf("\nThe Number of Account Holder whose Balance less than the Minimum Balance :
%d",flag);
fclose(fp);
break;
case '5' :
fclose(fp);
exit(0);
om
printf("\nPress any key to continue....");
getch();
} while (choice!='5');
}
.c
OUTPUT
1. Add a New Account Holder
ul
2. Display
3. Deposit or Withdraw
4. Number of Account Holder Whose Balance is less than the Minimum Balance
5. Stop
Enter your choice : 1
pa
Enter the Account Number : 547898760
Enter the Account Holder Name : Rajan
Enter the Initial Amount to deposit : 2000
jin
Press any key to continue....
3. Deposit or Withdraw
4. Number of Account Holder Whose Balance is less than the Minimum Balance
5. Stop
Enter your choice : 4
The Number of Account Holder whose Balance less than the Minimum Balance : 0
w
w
w
RESULT
Thus a C Program for Banking Application was executed and the output was obtained.
52
www.rejinpaul.com
DATE :
AIM
Create a Railway reservation system in C with the following modules
Booking
om
Availability checking
Cancellation
Prepare chart
.c
ALGORITHM
ul
1. Start pa
2. Declare variables
3. Display the menu options
4. Read the option.
5. Develop the code for each option.
jin
PROGRAM
#include<stdio.h>
#include<conio.h>
w
int first=5,second=5,thired=5;
struct node
{
w
int ticketno;
int phoneno;
char name[100];
w
char address[100];
}s[15];
int i=0;
void booking()
{
printf("enter your details");
53
www.rejinpaul.com
printf("\nname:");
scanf("%s",s[i].name);
printf("\nphonenumber:");
scanf("%d",&s[i].phoneno);
printf("\naddress:");
scanf("%s",s[i].address);
printf("\nticketnumber only 1-10:");
scanf("%d",&s[i].ticketno);
i++;
}
om
void availability()
{
int c;
printf("availability cheking");
printf("\n1.first class\n2.second class\n3.thired class\n");
printf("enter the option");
.c
scanf("%d",&c);
switch(c)
{
ul
case 1:if(first>0)
{
printf("seat available\n");
first--;
}
pa
else
{
printf("seat not available");
jin
}
break;
case 2: if(second>0)
{
printf("seat available\n");
.re
second--;
}
else
{
printf("seat not available");
w
}
break;
case 3:if(thired>0)
w
{
printf("seat available\n");
thired--;
w
}
else
{
printf("seat not available");
}
break;
default:
54
www.rejinpaul.com
break;
}
}
void cancel()
{
int c;
printf("cancel\n");
printf("which class you want to cancel");
printf("\n1.first class\n2.second class\n3.thired class\n");
printf("enter the option");
om
scanf("%d",c);
switch(c)
{
case 1:
first++;
break;
.c
case 2:
second++;
break;
ul
case 3:
thired++;
break;
default:
break;
pa
}
printf("ticket is canceled");
}
jin
void chart()
{
int c;
for(c=0;c<I;c++)
{
.re
{
int n;
clrscr();
w
option:");
scanf("%d",&n);
switch(n)
{
case 1: booking();
break;
case 2: availability();
55
www.rejinpaul.com
break;
case 3: cancel();
break;
case 4:
chart();
break;
case 5:
printf(“\n Thank you visit again!”);
getch();
exit(0);
om
default:
break;
}
}
getch();
}
.c
OUTPUT
ul
welcome to railway ticket reservation
1.booking
2.availability cheking
3.cancel
pa
4.Chart
5. Exit
enter your option: 2
jin
availability cheking
1.first class
2.second class
3.thired class
enter the option 1
.re
seat available
1.booking
2.availability cheking
3.cancel
4.Chart
w
5. Exit
enter your option: 5
Thank you visit again!
w
w
RESULT
Thus a C Program for Railway reservation system was executed and the output was
obtained.
56
www.rejinpaul.com
Additional C Programs for exercise
1.Program to find the row sum and column sum of a given matrix.
#include<stdio.h>
#include<conio.h>
void main()
om
{
int mat[10][10];
int i,j;
.c
int m,n;
int sumrow,sumcol;
ul
clrscr();
printf("\nTO FIND THE ROW SUM AND COLUMN SUM OF A GIVEN MATRIX:");
pa
printf("\n-- ---- --- --- --- --- ------ --- -- - ----- ------:");
for(i=0;i<m;i++)
.re
for(j=0;j<n;j++)
scanf("%d",&mat[i][j]);
w
}
w
printf("\n\nOUTPUT:");
printf("\n---------------------------------------");
w
for(i=0;i<m;i++)
sumrow=0;
57
www.rejinpaul.com
for(j=0;j<n;j++)
sumrow=sumrow+mat[i][j];
printf("\n---------------------------------------");
om
for(j=0;j<n;j++)
sumcol=0;
.c
for(i=0;i<m;i++)
sumcol=sumcol+mat[i][j];
ul
printf("\nTHE SUM OF %d COLUMN IS %d",j+1,sumcol);
} pa
printf("\n---------------------------------------");
getch();
}
jin
2. Program to read a string and print the first two characters of each word in the
string.
.re
#include<stdio.h>
#include<conio.h>
void main( )
{
char s[100];
w
int i,l;
clrscr( );
printf(“Enter a string”);
gets(s);
w
l=strlen(s);
for(i=0;i<l;i++)
{
w
58
www.rejinpaul.com
}
}
getch( );
}
om
{
struct date d;
getdate(&d);
printf("Current system date is %d/%d/%d",d.da_day,d.da_mon,d.da_year);
getch();
return 0;
.c
}.
ul
#include <stdio.h>
#include <math.h>
float standard_deviation(float data[], int n);
int main()
{
pa
int n, i;
float data[100];
printf("Enter number of datas( should be less than 100): ");
jin
scanf("%d",&n);
printf("Enter elements: ");
for(i=0; i<n; ++i)
scanf("%f",&data[i]);
printf("\n");
.re
{
mean+=data[i];
}
w
mean=mean/n;
for(i=0; i<n;++i)
sum_deviation+=(data[i]-mean)*(data[i]-mean);
return sqrt(sum_deviation/n);
}
59
www.rejinpaul.com
5. Program to calculate the Power of a Number using Recursion.
#include <stdio.h>
int power(int n1,int n2);
int main()
{
int base, exp;
printf("Enter base number: ");
scanf("%d",&base);
printf("Enter power number(positive integer): ");
scanf("%d",&exp);
om
printf("%d^%d = %d", base, exp, power(base, exp));
return 0;
}
int power(int base,int exp)
{
if ( exp!=1 )
.c
return (base*power(base,exp-1));
}
ul
6. Program to find the ASCII value of a Character.
#include <stdio.h>
int main(){
char c;
pa
printf("Enter a character: ");
scanf("%c",&c); /* Takes a character from user */
printf("ASCII value of %c = %d",c,c);
jin
return 0;
}
#include<conio.h>
void main( )
{
int a,b,c,d,big;
clrscr( );
w
scanf(“%d”,&b);
printf(“enter the value of c”);
scanf(“%d”,&c);
w
60
www.rejinpaul.com
8. Program for temperature conversion from Celsius to Fahrenheit and vice versa.
#include<stdio.h>
main()
{
float cel, fah ,c ,f;
clrscr();
printf(“\nEnter the fahrenheit value:”);
scanf(“%f”,&f);
om
cel=(5.0/9.0)*(f-32);
printf(“Celsius=%d”,cel);
printf(“\nEnter the Celsius value:”);
scanf(“%f”,&c);
fah=(9.0/5.0)*c+32;
printf(“Fahrenheit=%d”,fah);
.c
getch();
}
ul
9. Program to find the reverse and the given Number is Palindrome or not.
#include<stdio.h>
main()
pa
{
unsigned long int a, num, r_ num=0,rem;
printf(“\nEnter the number”);
jin
scanf(“%ld”,&num);
a=num;
while(num!=0)
{
.re
rem=num%10;
r_ num=r_ num*10+rem;
num=num/10;
}
w
else
printf(“\nThe given number is not a palindrome”);
}
w
61
www.rejinpaul.com
int n,r;
clrscr();
printf("\nPRG TO FIND nCr USING RECURSION\n");
printf("\n-----------------------------------------------\n");
printf("\nEnter the value of n: ");
scanf("%d",&n);
printf("\nEnter the value of r: ");
scanf("%d",&r);
om
ncr=fact(n)/(fact(r)*fact(n-r));
printf("\nThe value of %dC%d is %ld",n,r,ncr);
getch();
}
.c
ul
pa
jin
.re
w
w
w
62
www.rejinpaul.com
om
programming languages.
.c
3. What are the types of C instructions?
There are basically three types of instructions in C:
� Type Declaration Instruction
ul
� Arithmetic Instruction
� Control Instruction pa
4. What is a pointer?
Pointers are variables which stores the address of another variable. That variable may be a
scalar (including another pointer), or an aggregate (array or structure). The pointed-to
object may be part of a larger object, such as a field of a structure or an element in an
array.
jin
5. What is an array?
Array is a variable that hold multiple elements which has the same data type.
Pointers are used to manipulate data using the address. Pointers use * operator to access
the data pointed to by them.
Array is a collection of similar data type. Array use subscripted variables to access and
manipulate data. Array variables can be equivalently written using pointer expression.
w
63
www.rejinpaul.com
om
10. What are the different storage classes in C?
There are four types of storage classes in C language.
� Automatic
� Extern
� Register
� Static
.c
11. What is a structure?
Structure constitutes a super data type which represents several different data types in a
ul
single unit. A structure can be initialized if it is static or global.
to create an object of type A. The constructor will have no constructor initializer and a null
body.
w
64
www.rejinpaul.com
� It also reduces the Time to run a program. In other way, it’s directly proportional to
Complexity.
� It’s easy to find-out the errors due to the blocks made as function definition outside the
main function.
om
19. What are the differences between structures and union?
A structure variable contains each of the named members, and its size is large enough to
hold all the members. Structure elements are of same size.
A Union contains one of the named members at a given time and is large enough to hold
the largest member. Union element can be of different sizes.
.c
20. What is the difference between an Array and a List?
The main difference between an array and a list is how they internally store the data
ul
whereas Array is collection of homogeneous elements. List is collection of heterogeneous
elements.
21. What is the difference between a string copy (strcpy) and a memory copy (memcpy)?
pa
The strcpy() function is designed to work exclusively with strings. It copies each byte of
the source string to the destination string and stops when the terminating null character ()
has been moved.
On the other hand, the memcpy() function is designed to work with any type of data.
jin
Because not all data ends with a null character, you must provide the memcpy() function
with the number of bytes you want to copy from the source to the destination.
22. What is the difference between const char*p and char const* p?
const char*p - p is pointer to the constant character. i.e value in that address location is
.re
constant.
const char* const p - p is the constant pointer which points to the constant string, both
value and address are constants.
� The second argument n specifies the new size. The size may be increased or decreased.
The typedef help in easier modification when the programs are ported to another machine.
A descriptive new name given to the existing data type may be easier to understand the
code.
65
www.rejinpaul.com
new should be released with delete.
� Malloc allocates uninitialized memory.
� The allocated memory has to be released with free. New automatically calls the
constructor while malloc(dosen’t)
om
It is a pointer that points to the current object. This can be used to access the members of
the current object with the help of the arrow operator.
.c
29. What are the characteristics of arrays in C?
� An array holds elements that have the same data type.
ul
� Array elements are stored in subsequent memory locations
� Two-dimensional array elements are stored row by row in subsequent memory
locations.
� Array name represents the address of the starting element
pa
30. Differentiate between for loop and a while loop? What are it uses?
For executing a set of statements fixed number of times we use for loop while when the
number of iterations to be performed is not known in advance we use while loop.
jin
66
www.rejinpaul.com
int *ptr=(char *)0;
float *ptr=(float *)0;
37. What are macros? What are its advantages and disadvantages?
Macros are abbreviations for lengthy and frequently used statements. When a macro is
called the entire code is substituted by a single line though the macro definition is of
om
several lines.
The advantage of macro is that it reduces the time taken for control transfer as in case of
function. The disadvantage of it is here the entire code is substituted so the program
becomes lengthy if a macro is called several times.
38. What are register variables? What are the advantages of using register variables?
.c
If a variable is declared with a register storage class, it is known as register variable. The
register variable is stored in the CPU register instead of main memory. Frequently used
variables are declared as register variable as it’s access time is faster.
ul
39. What is storage class? What are the different storage classes in C?
Storage class is an attribute that changes the behavior of a variable. It controls the
lifetime,scope and linkage. The storage classes in c are auto, register, and extern, static,
typedef.
pa
40. What the advantages of using Unions?
When the C compiler is allocating memory for unions it will always reserve enough room
jin
for the largest member.
41. In C, why is the void pointer useful? When would you use it?
The void pointer is useful because it is a generic pointer that any pointer can be cast into
and back again without loss of information.
.re
42. What is the difference between the functions memmove() and memcpy()?
The arguments of memmove() can overlap in memory. The arguments of memcpy()
cannot.
w
returned by these function are assigned to pointer variables, such a way of allocating
memory at run time is known as dynamic memory allocation.
67
www.rejinpaul.com
int *p1, **p2,
v=10;
P1=&v;
p2=&p1;
Here p2 is a pointer to a pointer.
om
47. What is an argument?
An argument is an entity used to pass data from the calling to a called function.
.c
� These involve validation of syntax of language.
� Compiler prints diagnostic message.
Logical Error
ul
� Logical error are caused by an incorrect algorithm or by a statement mistyped in such
a way that it doesn’t violet syntax of language.
� Difficult to find.
postfix increment.
The expression appearing on right side of the assignment operator is called as rvalue.
Rvalue is assigned to lvalue, which appears on left side of the assignment operator. The
lvalue should designate to a variable not a constant.
w
68