C Programming Lab Manual
C Programming Lab Manual
0 0 4 2
COURSE OBJECTIVES:
LIST OF EXPERIMENTS:
Note: The lab instructor is expected to design problems based on the topics
listed. The Examination shall not be restricted to the sample experiments
designed.
TOTAL: 60 PERIODS
COURSE OUTCOMES:
TEXT BOOKS:
1. ReemaThareja, “Programming in C”, Oxford University Press, Second Edition, 2016.
2. Kernighan, B.W and Ritchie,D.M, “The C Programming language”,
Second Edition, Pearson Education, 2015.
REFERENCES:
1. Paul Deitel and Harvey Deitel, “C How to Program with an Introduction to
C++”, Eighth edition, Pearson Education, 2018.
2. Yashwant Kanetkar, Let us C, 17th Edition, BPB Publications, 2020.
3. Byron S. Gottfried, "Schaum's Outline of Theory and Problems of Program-
ming with C", McGraw-Hill Education, 1996.
4. Pradip Dey, Manas Ghosh, “Computer Fundamentals and Programming in C”, Second
5. Edition, Oxford University Press, 2013.
6. Anita Goel and Ajay Mittal, “Computer Fundamentals and Programming in
C”, 1st Edition, Pearson Education, 2013.
List of Experiments
Page Staff
Sl.No Ex.No. Date Title of the Experiments
No. sign
1. 1a Programs using I/O statements
2. 1b Programs using Operators and Expressions
3. 2a Find Odd or Even using goto statement
4. 2b Finding Leap Year or Not
5. 2c Creating a Menu Driven Calculator
6. 2d Checking vowel or not using switch case
Print 1 to n numbers except multiples of 5
7. 2e
using continue statement
8. 3a Finding Armstrong Number
Sum of first N natural numbers using
9. 3b
Looping
10. 3c Sum the cubes of series of N numbers
Finding Sum Of Weights & Sorting The
11. 4a
Elements Based On Weights
Finding The Persons Having Above
12. 4b
Average Height
13. 4c Finding Body Mass Index Using Array
14. 4d Matrix Addition and Multiplication
Reverse String Without Changing The
15. 5
Position Of Special Character
16. 6a Swap the values using call by value
Sorting The Values Using Pass By
17. 6b
Reference
Sum of array elements by passing to a
18. 6c
function
19. 7a Towers of Hanoi
20. 7b Finding factorial of a number
21. 8a Pointer to pointer
22. 8b Array of Pointer
23. 9a Employee Salary Slip
24. 9b Students Internal Mark Sheet
25. 9c Accessing Union Members
26. 10a Sequential Access File
27. 10b Random Access File
28. 10c Processor Directives
EX.NO.:1a PROGRAMS USING I/O STATEMENTS
AIM:
To Write a C program to use Input and Output Statements
PROCEDURE:
SYNTAX:
Unformatted I/O
◦ charvariable=getchar();
◦ charvariable=getche();
◦ charvariable=getch();
◦ gets(chararray_variable);
◦ putch(charvariable);
◦ puts(chararray_variable);
Formatted I/O
◦ scanf(“format specifiers”,address of variables);
◦ printf(“Any text”);
◦ printf(“Any text,format spcifiers”,variables);
◦ printf(“format spcifiers”,variables);
SAMPLE PROGRAMS:
P1: Get & Display a single character using getch()
#include<stdio.h>
#include<conio.h>
main()
{
char c1;
c1=getch();
putch(c1);
}
P2: Get & Display a single character using getche()
#include<stdio.h>
#include<conio.h>
main()
{
char c1;
}
P5: Get & Display a student’s regno,Name and GPA using scanf & printf
#include<stdio.h>
#include<conio.h>
main()
{
int regno;
char name[25];
float GPA;
printf(“\nEnter a Student Regno,Name & GPA\n”);
scanf();
prinntf(“\n------------------------------------------------------\n”);
prinntf(“\n\t\t REG.NO \t\t NAME \t\t GPA \t\t\n”);
prinntf(“\n------------------------------------------------------\n”);
printf();
}
OUTPUT:
RESULT:
Thus the C program for I/O statements has been written & executed successfully.
EX.NO. :1b PROGRAMS USING OPERATORS AND EXPRESSIONS
AIM:
To Write C programs using Operators and Expressions
PROCEDURE:
SYNTAX:
Expression = Operand operator Operand
Operator : Symbol
Operand : variable or Constant
var1=Var2+Var3 (or) Var1=Value1+Value2; (or) Var1=Var2+value
Logical Operators : returns True(1) or false(0) values-Condition1&& Condition2
Ternary Operator: if condition is true True part will be executed. Otherwise, False part
will be executed - Var1= ( condition)? True part: False Part
SAMPLE PROGRAMS:
P1: Arithmetic Operators
#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr(); //to clear the output screen
a=20;
b=5;
printf(“Addition of %d + %d is = %d”,a+b);
printf(“Subtraction of);
printf(“Multiplication of);
printf(“Division of);
printf(“Modulo Division of);
getch();
}
P2: Bit wise Operators
#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr(); //to clear the output screen
a=20;
b=5;
printf(“Bit wise OR of %d + %d is = %d”,a|b);
printf(“Bit wise AND of %d + %d is = %d”, );
printf(“One’s complement of %d is = %d”, );
getch();
}
P3: Relational Operators
#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr(); //to clear the output screen
a=20;
b=5;
printf(“a>b : %d”,a>b);
getch();
}
P4: Logical, Ternary Operators, Increment & decrement Operators
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr(); //to clear the output screen
a=20;
b=5;
c=(a>b)?(a+b):(a-b);
printf(“The value of c is = ”, );
d=(a>b)&&(a>c);
printf(“The value of d is = ”, );
d=(b<c)&&(a<c);
printf(“The value of d is = ”, );
printf(“a++ & ++b is = ”,++a,b++);
getch();
}
OUTPUT:
RESULT:
Thus the C program for expressions has been written & executed successfully.
PROCEDURE:
SYNTAX:
if(condition)
statement;
else
statement;
SAMPLE PROGRAM:
#include <stdio.h>
#include <stdlib.h>
void main()
{
int num;
printf("Enter a number\n");
scanf("%d", &num);
if (num % 2 == 0)
goto even;
else
goto odd;
even:
printf("%d is even\n", num);
exit(0);
odd:
printf("%d is odd\n", num);
}
OUTPUT 1:
Enter a number
74
74 is even
OUTPUT 2:
Enter a number
35
35 is odd
RESULT:
Thus the C program for finding even or odd is written & executed Successfully.
PROCEDURE:
PROGRAM:
#include <stdio.h>
int main(){
int y;
printf("Enter the year to check: ");
scanf("%d",&y);
if (((y % 4 == 0) && (y % 100!= 0)) || (y%400 == 0))
printf("It is a leap year");
else
printf("It is not a leap year");
return 0;
}
Output:
RESULT:
Thus the C program for finding leap year or not is written & executed Successfully.
PROCEDURE:
PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
int option,a,b,c;
clrscr();
printf(“Enter the option”);
printf(“\n 1.ADD \t 2.SUB \t 3.MUL \t 4.DIV \n”);
scanf(“%d”,&option);
switch()
{
case 1:
printf(“Enter two values”);
scanf(“%d%d”,&a,&b);
c=a+b;
break;
case 2:
printf(“Enter two values”);
scanf(“%d%d”,&a,&b);
c=a-b;
break;
case 3:
printf(“Enter two values”);
scanf(“%d%d”,&a,&b);
c=a*b;
break;
case 4:
printf(“Enter two values”);
scanf(“%d%d”,&a,&b);
c=a/b;
break;
default:
printf(“Choose the correct option”);
}
printf(“ Result is =%d”,c);
getch();
}
Output:
RESULT:
Thus the c program for creating a Menu Driven Calculator using switch case is
written & executed successfully.
PROCEDURE:
PROGRAM:
Output:
RESULT:
Thus the c program for Checking vowel or not using switch case switch case is
written & executed successfully.
EX.NO.:2e PRINT 1 TO N NUMBERS EXCEPT MULTIPLES OF 5
AIM:
To Write a C program to Print 1 to n numbers except multiples of 5 using continue
statement.
ALGORITHM:
PROGRAM:
OUTPUT:
RESULT:
AIM:
To Write a C program to find whether a given number is Armstrong number or not.
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
int N,A,digit,cube,sum=0;
printf(“Enter a Number\n”);
scanf(“%d”,&N);
A=N;
while( )
{
digit=N%10;
cube=(digit*digit*digit);
sum=sum+cube;
N=N/10;
}
if ( sum==A)
printf(“%d is Armstrong Number”, );
else
printf(“%d is not an Armstrong Number”, );
getch();
}
OUTPUT:
RESULT:
Thus the C program to find whether a given number is Armstrong number or not
is written & executed successfully.
Ex:3b SUM OF FIRST N NATURAL NUMBERS USING LOOPING
AIM:
To Write a C program for sum of first n natural numbers using while, do…while and for
loop.
ALGORITHM: 1
ALGORITHM: 2
ALGORITHM: 3
PROGRAM:1
#include <stdio.h>
int main() {
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
i = 1;
while (i <= n) {
sum += i;
++i;
}
printf("Sum = %d", sum);
return 0;
}
PROGRAM:2
#include <stdio.h>
int main() {
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
i = 1;
do
{
sum += i;
++i;
} while (i <= n);
PROGRAM:3
#include <stdio.h>
int main() {
int n, i, sum = 0;
Sum =55
RESULT:
Thus the C program to for sum of first n natural numbers using while, do…while and for
loop has been executed successfully and the output was verified.
EX.NO.: 3c SUM THE CUBES OF SERIES OF N NUMBERS
AIM:
To Write a C program to Sum the cubes of series of N numbers.
ALGORITHM:
PROGRAM:
#include <stdio.h>
int main()
{
int n;
int sum = 0;
printf(“Enter the number\n”);
scanf(“%d”,&n);
for (int i = 1; i <= n; i++)
{
sum += i * i * i;
}
printf(“sum= %d”, sum);
return 0;
}
OUTPUT:
RESULT:
Thus the C program for Sum the cubes of series of N numbers has been executed
successfully and the output was verified.
Ex:4a FINDING SUM OF WEIGHTS & SORTING THE ELEMENTS BASED ON
WEIGHTS
AIM:
Write a C program to find sum of weights for a given set of numbers like <10, 36, 54, 89, 12,
27>, Find the sum of weights based on the following conditions.
1. 5 if it is a perfect cube.
2. 4 if it is a multiple of 4 and divisible by 6.
3. 3 if it is a prime number.
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double cubroot,cube;
int a[10]={ },w[10],i,j,N=6,count=0,A,sum=0;
clrscr();
for(i=0;i<N;i++)
{
A=a[i];
w[i]=0;
cubroot=ceil(pow(A,(1/3)));
cube=cubroot*cubroot*cubroot;
if(A==cube)
w[i]=w[i]+5;
if(A%4==0 && A%6==0)
w[i]=w[i]+4;
for(j=2;j<=A;j++)
{
if(A%j == 0)
count=count+j;
}
if(A==1 || A==count)
w[i]=w[i]+3;
}
printf("\n\nELEMENT\t\t\t\tWEIGHT \n\n");
for(i=0;i<N;i++)
{
printf("%d \t\t\t\t%d\n\n",a[i],w[i]);
sum=sum+w[i];
}
printf("The sum of Weights is = sum);
printf("Sorting of the Elements based on weight values\n");
for(i=0;i<N;i++)
for(j=0;j<N;j++)
if(w[j]>w[j+1])
{
t=w[j];
w[j]=w[j+1];
w[j+1]=t;
k=a[j];
a[j]=a[j+1];
a[j+1]=k;
}
for(i=0;i<N;i++)
{
printf("<%d,%d> \t",a[i],w[i]);
}
getch();
}
OUTPUT:
RESULT:
Thus the program is written & executed Successfully.
Ex.No:4b FINDING THE PERSONS HAVING ABOVE AVERAGE HEIGHT
AIM:
Write a C program to populate an array with height of persons and find how many persons are
above the average height.
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
float height[20],avg;
int N,i,sum=0,count=0;
clrscr();
printf("Enter the no. of persons");
scanf("%d",&N);
printf("Enter the persons height on eby one\n");
for(i=0;i<N;i++)
{
scanf("%f",&height[i]);
sum=sum+height[i];
}
avg=sum/N;
for(i=0;i<N;i++)
{
if(height[i]>avg)
{ count=count+1; }
}
printf("Totally %d Persons are having above average height",count);
getch();
}
OUTPUT:
RESULT:
Thus the program is written & executed Successfully.
ALGORITHM:
1. Start the program.
2. Read the Number of Persons.
3. Enter the height,weight values.
4. Read height in centi meters & weight in Kilograms of a person.
5. Height in Meter= height in cm/100;
6. Compute the body mass index value using the following formula
BMI=(weight in Kg)/(Height in Meters)2
7. Store the BMI values in a resultant array.
8. Print the results.
Stop the program.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
float height[20],weight[20],BMI[20],HIM[20];
int i,j,N;
clrscr();
printf("\nEnter the No.of the elements\n");
scanf("%d",&N);
printf("\n Enter the Height & Weight values\n");
for(i=0;i<N;i++)
{
scanf("%f%f",&height[i],&weight[i]);
HIM[i]=height[i]/100;
}
printf("\nPerson\tHeight\tWeight\tBMS\n");
for(i=0;i<N;i++)
{
BMI[i]=weight[i]/(HIM[i]*HIM[i]);
printf("\n%d\t%.2f\t%.2f\t%.2f\n",(i+1),HIM[i],weight[i],BMI[i]);
}
getch();
}
OUTPUT:
Enter No. of the elements
3
RESULT:
Thus the program is written & executed Successfully.
ALGORITHM:1
ALGORITHM:2
PROGRAM:1
#include <stdio.h>
int main() {
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
printf("Enter the number of rows (between 1 and 100): ");
scanf("%d", &r);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &c);
return 0;
}
PROGRAM:2
#include <stdio.h>
printf("\nOutput Matrix:\n");
for (int i = 0; i < row; ++i) {
for (int j = 0; j < column; ++j) {
printf("%d ", result[i][j]);
if (j == column - 1)
printf("\n");
}
}
}
int main() {
int first[10][10], second[10][10], result[10][10], r1, c1, r2, c2;
printf("Enter rows and column for the first matrix: ");
scanf("%d %d", &r1, &c1);
printf("Enter rows and column for the second matrix: ");
scanf("%d %d", &r2, &c2);
return 0;
}
OUTPUT :1
10 8 6
OUTPUT :2
Enter elements:
Enter a11: 2
Enter a12: -3
Enter a13: 4
Enter a21: 53
Enter a22: 3
Enter a23: 5
Enter elements:
Enter a11: 3
Enter a12: 3
Enter a21: 5
Enter a22: 0
Enter a31: -3
Enter a32: 4
Output Matrix:
-21 22
159 179
RESULT:
Thus the C program to calculate Matrix Addition and Multiplication has been
executed successfully and the output was verified.
AIM:
To Write a C program for reversing a string without changing the position of special
characters. (Example input:a@gh%;j and output:j@hg%;a)
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
void reverse(char *);
void main()
{
char str[50];
clrscr();
printf("Enter a string\n");
scanf("%s",str);
printf( "Input string: %s\n",str);
reverse(str);
printf("Output string:%s\n",str);
getch();
}
void reverse(char *str)
{
int r = strlen(str) - 1, f= 0;
char t;
while (f < r)
{
if(isalnum(str[f])!=0 && isalnum(str[r])!=0)
{
t=str[r];
str[r]=str[f];
str[f]=t;
f++;
r--;
}
else if(isalnum(str[f])!=0 && isalnum(str[r])==0)
{ r--; }
}
}
OUTPUT:
Enter a string:
a@gh%;j
Input string: a@gh%;j
Output string:j@hg%;a
RESULT:
Thus the C program to Reverse String Without Changing The Position of Special
Character has been executed successfully and the output was verified.
ALGORITHM:
PROGRAM:
#include <stdio.h>
void swap(int, int);
int main()
{
int x, y;
printf("Enter the value of x and y\n");
scanf("%d%d",&x,&y);
printf("Before Swapping\nx = %d\ny = %d\n", x, y);
swap(x, y);
printf("After Swapping\nx = %d\ny = %d\n", x, y);
return 0;
}
void swap(int a, int b)
{
int temp;
temp = b;
b = a;
a = temp;
printf("Values of a and b is %d %d\n",a,b);
}
OUTPUT:
RESULT:
Thus the C program for Swapping of two numbers using call by value has been
executed successfully and the output was verified.
AIM:
Write a C program to sort numbers using pass by Reference.
ALGORITHM:
PROGRAM:
#include<stdio.h>
void sort(int *,int);
void main()
{
int a[20],N,i;
printf("Enter the no. of elements\n");
scanf("%d",&N);
printf("Enter the Elements one by one\n");
for(i=0;i<N;i++)
scanf("%d",&a[i]);
sort(a,N);
OUTPUT:
Enter the no. of elements
3
Enter the Elements one by one
100
3
45
Sorted Order
3 45 100
RESULT:
Thus the C program for Sorting the Values Using Pass By Reference has been executed
successfully and the output was verified
AIM:
To Write a C program to solve towers of Hanoi using recursion.
ALGORITHM:
PROGRAM:
#include <stdio.h>
void towers(int,char,char,char);
void main()
{
int num;
printf("Enter the number of disks : ");
scanf("%d",&num);
printf("The sequence of moves involved in the Tower of Hanoi are :\n");
towers(num,'A','C','B');
}
OUTPUT:
ALGORITHM:
PROGRAM:
#include<stdio.h>
long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
void main()
{
int number;
long fact;
printf("Enter a number: ");
scanf("%d", &number);
fact = factorial(number);
printf("Factorial of %d is %ld\n", number, fact);
return 0;
}
OUTPUT:
Enter a number: 6
Factorial of 5 is: 720
RESULT:
Thus the C program for finding factorial of a number using recursion has been executed
successfully and the output was verified
AIM:
To Write a C program to print the value and address of the variable using pointer to
pointer.
ALGORITHM:
PROGRAM:
#include<stdio.h>
void main ()
{
int a = 10;
int *p;
int **pp;
p = &a; // pointer p is pointing to the address of a
pp = &p; // pointer pp is a double pointer pointing to the address of pointer p
printf("address of a: %x\n",p); // Address of a will be printed
printf("address of p: %x\n",pp); // Address of p will be printed
printf("value stored at p: %d\n",*p); // value stoted at the address contained by p i.e. 10
will be printed
printf("value stored at pp: %d\n",**pp); // value stored at the address contained by the
pointer stoyred at pp
}
OUTPUT:
RESULT:
Thus the C program to print the value and address of the variable using pointer to pointer.
has been executed successfully and the output was verified
ALGORITHM:
PROGRAM:
#include <stdio.h>
int main () {
int i = 0;
return 0;
}
OUTPUT:
RESULT:
Thus the C program to read and display 5 student names using array of pointer has been
executed successfully and the output was verified
AIM:
To Write a C program to generate employee salary slip using structure & pointer.
ALGORITHM:
PROGRAM:
#include<stdio.h>
struct employee
{
char ename[25];
int eid;
char edes[20];
char edept[20];
int esal;
};
void main()
{
struct employee emp[20],*emp1;
int m,i;
printf("Enter the no. of employee details");
scanf("%d",&m);
printf("\nEnter employee id, name, department, designation & salary\n");
for(i=0;i<m;i++)
{
scanf("%d%s%s%s
%d",&emp[i].eid,&emp[i].ename,&emp[i].edes,&emp[i].edept,&emp[i].esal);
}
emp1=emp;
salaryslip(emp1,m);
getch();
}
OUTPUT:
RESULT:
Thus the C program to generate employee salary slip using structure & pointer has been
executed successfully and the output was verified.
ALGORITHM:
PROGRAM:
#include<stdio.h>
struct student
{
char name[20];
int t[15][15];
int mark[5];
};
void internal( struct student);
void main()
{
struct student s;
int j,k;
clrscr();
for(j=0;j<3;j++)
{
printf("Enter the internal test %d marks for five subjects:\t",j+1);
for(k=0;k<5;k++)
scanf("%d",&s.t[j][k]);
}
internal(s);
getch();
}
void internal(struct student s1)
{
int i,j,k,sum[20],c=0;
for(j=0;j<5;j++)
{
c=0;
for(k=0;k<3;k++)
{
c=c+s1.t[k][j];
}
s1.mark[j]=((c/3)/5);
}
for(i=0;i<5;i++)
printf("\nSubject %d Internal Mark (max. marks 20)= %d",i+1,s1.mark[i]);
}
OUTPUT:
RESULT:
Thus the C program to compute internal marks of students for five different subjects
using nested structure has been executed successfully and the output was verified.
EX.NO.: 9c ACCESSING STUDENT DETAILS USING UNION
AIM:
To Write a C program for accessing student details using union.
ALGORITHM:
PROGRAM:
OUTPUT:
RESULT:
Thus the C program for accessing student details using union has been executed
successfully and the output was verified.
Ex.No: 10a SEQUENTIAL ACCESS FILE
AIM:
Write a C program to count the number of account holders whose balance is less than the
minimum balance using sequential access file.
ALGORITHM:
PROGRAM:
#include <stdio.h>
void insert();
void count();
int main(void)
{
int choice = 0;
while (choice != 3)
{
printf("\n1 insert records\n");
printf("2 Count min balance holders\n");
printf("3 Exit\n");
printf("Enter choice:");
scanf("%d", &choice);
switch(choice)
{
case 1: insert(); break;
case 2: count(); break;
}
}
}
void insert()
{
unsigned int account,i;
char name[30];
double balance;
FILE* cfPtr;
void count()
{
unsigned int account;
char name[30];
double balance;
float minBal = 5000.00;
int count = 0;
FILE *cfPtr;
if ((cfPtr = fopen("clients.dat", "r")) == NULL)
printf("File could not be opened");
else
{
printf("%-10s%-13s%s\n", "Account", "Name", "Balance");
fscanf(cfPtr, "%d%29s%lf", &account, name, &balance);
while (!feof(cfPtr))
{
if (balance < minBal)
{
printf("%-10d%-13s%7.2f\n", account, name, balance);
count++;
}
fscanf(cfPtr, "%d%29s%lf", &account, name, &balance);
}
fclose(cfPtr);
printf("The number of account holders whose balance is less than the minimum balance: %d",
count);
}
}
OUTPUT:
1 insert records
2 Count min balance holders
3 Exit
Enter choice:1
Enter the No. of records 2
Enter the account, name, and balance.1001 A 10000
Enter the account, name, and balance.1002 B 300
1 insert records
2 Count min balance holders
3 Exit
Enter choice:2
Account Name Balance
1002 B 300.00
The number of account holders whose balance is less than the minimum balance: 1
1 insert records
2 Count min balance holders
3 Exit
Enter choice:
RESULT:
Thus the c program to count the number of account holders whose balance is less than the
minimum balance using sequential access file has been executed successfully and the output was
verified.
AIM:
To Write a C program to update telephone details of an individual or a company into a
telephone directory using random access file.
ALGORITHM:
PROGRAM:
#include<stdio.h>
struct teledir
{
int no;
char name[3];
};
void main()
{
struct teledir t1,t2,t3;
int i,n,p,newp;
FILE *fp,*fp1;
clrscr();
fp=fopen("td.txt","w");
printf("Enter the no of records\n");
scanf("%d",&n);
printf("Enter the record\n");
for (i=0;i<n;i++)
{
scanf("%d%s",&t1.no,t1.name);
fwrite(&t1,sizeof(struct teledir),1,fp);
}
fclose(fp);
fp=fopen("td.txt","r");
while(fread(&t2,sizeof(struct teledir),1,fp)!=NULL)
{
printf("\t%d%s\n",t2.no,t2.name);
}
fclose(fp);
getch();
}
OUTPUT:
Enter the no of records
3
Enter the record
111 abc
222 xyz
333 nmo
111abc
222xyz
333nmo
Enter number to be modified & a new number
222 9898
111 abc
9898 xyz
333 nmo
RESULT:
Thus the c program to update telephone details of an individual or a company into a
telephone directory using random access file has been executed successfully and the output was
verified.
AIM:
To Write a C program to find greatest of three numbers using ternary operator in
preprocessor directives.
ALGORITHM:
PROGRAM:
OUTPUT:
RESULT:
Thus the c program to find greatest of three numbers using ternary operator in
preprocessor directives has been executed successfully and the output was verified.