You are on page 1of 388

ACP LAB RECORD

ADVANCED C PROGRAMMING LABORATORY

LABORATORY RECORD

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT Btech. INFORMATION TECHNOLOGY

SECTION A

Roll No : 20F110-BHAVISHYA.S Page 1


ACP LAB RECORD

INDEX

Ex.No Date PAGE No. Name of the Exercise

Read the value of integer and print the value as well as


1 3-4-2021 1 address using
pointer.

2 3-4-2021 7 To find simple interest using pointer.

3 3-4-2021 13 To find volume of cylinder using pointer.

19 To perform multiplication of three float numbers using


4 3-4-2021
pointer

5 3-4-2021 25 Find area of rectangle using void pointer.

31 To check whether the number is leap year or not using


6 9-4-2021
void pointer.

7 9-4-2021 37 To find cube of an number using void pointer.

8 9-4-2021 43 To find square of number using pointer.

9 9-4-2021 49 Swap two numbers using pointer.

10 9-4-2021 55 To find area of circle using generic pointer.

11 9-4-2021 61 Swap two numbers using pointer to pointer.

Roll No : 20F110-BHAVISHYA.S Page 2


ACP LAB RECORD

9-4-2021 67 Read array of 5 numbers and print the numbers using


12
pointer and array.

13 9-4-2021 73 To read and print 2*2 matrix using pointer and array.

9-4-2021 79 To print address of array elements using array of


14
pointer.

15 9-4-2021 85 To find volume of cylinder using pointer to pointer.

91 To check the array elements are odd or even using


16 21-4-2021
pointer and array.
To set primary and secondary diagonal elements to 0
17 21-4-2021 98 using pointer and
array.

18 21-4-2021 104 Perform matrix multiplication using pointer notation.

21-4-2021 109 To find check the matrix is sparse matrix or not using
19
pointer

21-4-2021 115 To check the matrix is identity matrix using pointer and
20
array

Read array of 5 numbers and print the numbers along


21 23-4-2021 121 with address using pointer to an
array.

22 23-4-2021 127 To find sum of array elements using pointer to an array.

23-4-2021 132 To reverse array of 10 float values using pointer to an


23
array.

23-4-2021 138 To find largest element in an array using pointer to an


24
array.

25 23-4-2021 143 To sort array elements using pointer to an array.

Roll No : 20F110-BHAVISHYA.S Page 3


ACP LAB RECORD

23-4-2021 148 Read 3*3 matrix and print transpose of matrix using
26
pointer to an array.

23-4-2021 153 To set primary and secondary diagonal elements to 0


27
using pointer to an array.

28 23-4-2021 158 Add two matrix using pointer to an array.

29 23-4-2021 164 To perform matrix multiplication using VLA.

30 23-4-2021 170 To print alternative elements using VLA.

31 6-5-2021 175 To find length of the string " advanced c program".

6-5-2021 180 To copy the word “Coimbatore” using string handling


32
function

33 6-5-2021 185 To merge two string using strcat function

6-5-2021 190 To find first occurrence of character a in the string


34
"karpagam college of engineering".

35 6-5-2021 195 To find substring using strstr function.

36 7-5-2021 200 To remove the delimiter space and : .

37 7-5-2021 205 To find length of the word without using strlen.

38 7-5-2021 210 Merge two words without strcat.

39 7-5-2021 214 To reverse the string without strrev().

Roll No : 20F110-BHAVISHYA.S Page 4


ACP LAB RECORD

40 7-5-2021 219 To convert the text "karpagam " into upper case

To search the character entered by user in the sentence


41 19-6-2021 224 and count occurrence
of the character.
To replace the first 4 characters in the string
42 19-6-2021 230 “ADVANCED C
PROGRAMMING” with * without using strnset().

43 19-6-2021 235 To print ASCII value along with character in the string.

To copy n number of characters from string1 to string2


44 19-6-2021 240 without using
strncpy()

19-6-2021 245 To count number of space, upper case, lower case in the
45
string.

19-6-2021 250 To find the last occurrence of the character ‘o’ in the
46
string “good morning”.
To convert string “WELCOME TO KCE” into lower
47 19-6-2021 254 case without using
strlwr()

19-6-2021 258 To copy first 5 character into another string without


48
using strncpy().

To remove the & in the sentence using strtok(). Get


49 19-6-2021 262 string from user using
gets.

50 19-6-2021 267 To compare two strings using strcmp().

To create a structure called employee. Initialize and


51 19-6-2021 271 display employee_id,
dept_id and salary values using structure variable.
To initialize book id, book title, author name, subject
19-6-2021 276 using structure. Use
52
two structure variables to initialize the values and
display the values.
To find the size of a structure variable without structure
53 19-6-2021 281 padding using #
pragma pack (1).

Roll No : 20F110-BHAVISHYA.S Page 5


ACP LAB RECORD

To read and print the driving licence details of a person


19-6-2021 285 which includes
54
driving license number, name, address, date_of_birth
valid date using typedef in structure.

19-6-2021 290 Displaying the age, name, salary and voter Id of a person
55
by creating a structure and passing it to a function.
To create a structure student to store the details of 10
56 19-6-2021 295 students of a class and display it. Implement using array
of structures.

57 19-6-2021 301 To find the size of the memory allocated for the union.

19-6-2021 305 To read and display the name, age and salary of the
58
employee using union.

19-6-2021 310 To display the month of a year and its corresponding


59
value using the enumeration data type.
To create a structure time with hour, minutes and
19-6-2021 314 seconds as its members.Use bitfields inside the structure,
60
initialize the values for hour, minutes and seconds and
display it.

61 26-6-2021 318 To find area of circle using malloc().

26-6-2021 322 To read 5 integer values from the user and print the
62
integer. Allocate the memory using calloc().

To store the string in a block of memory space created


63 26-6-2021 326 by malloc() and then modify the same to store the largest
string using realloc().
To read an integer from the user by allocating the
64 26-6-2021 330 memory dynamically and then print the value, release
the memory using free().

26-6-2021 334 To read an array of 5 elements and find the largest


65
element in it using Dynamic Memory Allocation.

66 29-6-2021 339 To multiply two numbers using function pointer.

Roll No : 20F110-BHAVISHYA.S Page 6


ACP LAB RECORD

67 29-6-2021 343 To add three numbers using call by reference.

To copy one string to another string by passing string to


68 29-6-2021 347
function.

To find the factorial of a given number using function


69 29-6-2021 352
pointer.

70 29-6-2021 357 To pass a structure to function.

To read two integers from the user and write the sum
71 29-6-2021 362
into file.

72 29-6-2021 366 To illustrate the use of fseek()

To write some content into file. Read the file content and
73 29-6-2021 370
display the data into terminal. (note use the w+ mode ).

74 29-6-2021 374 To print the source code of your program.

To perform addition of three numbers using command


75 29-6-2021 378
line arguments.

Roll No : 20F110-BHAVISHYA.S Page 7


1
Advanced C Programming Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION A

Ex : No : 01

TITLE POINTER

Roll No : 20F110- BHAVISHYA.S Page 1


2
Advanced C Programming Laboratory

Ex. No : 01 Program to read the value of integer and print the value as well as address using
pointer.

PROBLEM STATEMENT

Write program to read the value of integer and print the value as well as address using
pointer.

Constraints:

Variable Name Data type

ia,*ip =&ia int

Roll No : 20F110- BHAVISHYA.S Page 2


3
Advanced C Programming Laboratory

SOLUTION
AIGORITHM

BEGIN
STEP 1: Declare ia,*ip=&ia of int data type.
STEP 2:Get the value from the user.
STEP 3:Print value=*ip.

STEP 4: Print memory address -ip.

END

Roll No : 20F110- BHAVISHYA.S Page 3


4
Advanced C Programming Laboratory

PROGRAM:

#include <stdio.h>
int main()
{
int ia,*ip=&ia;
printf("\n ENTER A VALUE :");
scanf("%d",&ia);
printf("\n THE VALUE IS:%d",*ip);
printf("\n THE MEMORY ADDRESS IS:%u",ip);
return 0;
}

Roll No : 20F110- BHAVISHYA.S Page 4


5
Advanced C Programming Laboratory

01 - OUTPUT

Roll No : 20F110- BHAVISHYA.S Page 5


6
Advanced C Programming Laboratory

RESULT:

Program to read the value of integer and print the value as well as address using
Pointer has been completed successfully.

Roll No : 20F110- BHAVISHYA.S Page 6


7
Advanced C Programming Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION A

Ex : No : 02

TITLE POINTER

Roll No : 20F110-BHAVISHYA.S Page 1


8
Advanced C Programming Laboratory

Ex. No : 02 C program to find simple interest using pointer.

PROBLEM STATEMENT

Write a a program to find simple interest using pointer.

Constraints:

Variable Name Data type

fp,ft,fr,fpt1,fpt2,fpt3 float

Roll No : 20F110-BHAVISHYA.S Page 2


9
Advanced C Programming Laboratory

SOLUTION
AIGORITHM

BEGIN

STEP 1: Declare float fp=1000,ft=2,fr=0.08,*fpt1=&fp,*fpt2=&ft,*fpt3=&fr of int data type

STEP 2: Print simple intrest -(*fpt1 * *fpt2 **fpt3)/100.

END

Roll No : 20F110-BHAVISHYA.S Page 3


10
Advanced C Programming Laboratory

PROGRAM:
#include <stdio.h>
int main()
{
float fp=1000,ft=2,fr=0.08,*fpt1=&fp,*fpt2=&ft,*fpt3=&fr;
printf("\n SIMPLE INTREST: %f",(*fpt1**fpt2**fpt3)/100);
return 0;
}

Roll No : 20F110-BHAVISHYA.S Page 4


11
Advanced C Programming Laboratory

01 - OUTPUT

Roll No : 20F110-BHAVISHYA.S Page 5


12
Advanced C Programming Laboratory

RESULT:

The C Program to find simple interest has been completed successfully.

Roll No : 20F110-BHAVISHYA.S Page 6


13
Advanced C Programming Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION A

Ex : No : 03

TITLE POINTER

Roll No : 20F110-BHAVISHYA.S Page 1


14
Advanced C Programming Laboratory

Ex. No : 03 C program to find volume of cylinder using pointer.

PROBLEM STATEMENT

Write a program to find volume of cylinder using pointer.

Constraints:

Variable Name Data type

ir,*ip=*&ir int

Roll No : 20F110-BHAVISHYA.S Page 2


15
Advanced C Programming Laboratory

SOLUTION

AIGORITHM

BEGIN

STEP 1: Declare and initialize ir=10,*ip=&ir of int datatype.

STEP 2: Print volume of cylinder is : 3.14 * *ip* *ip.

END

Roll No : 20F110-BHAVISHYA.S Page 3


16
Advanced C Programming Laboratory

PROGRAM:
//c program to find volume of cylinder using pointer
#include <stdio.h>
int main()
{
int ir=10,*ip=&ir;
printf("\n VOLUME OF CYLINDER IS: %u",3.14* *ip* *ip);
return 0;
}

Roll No : 20F110-BHAVISHYA.S Page 4


17
Advanced C Programming Laboratory

01 - OUTPUT

Roll No : 20F110-BHAVISHYA.S Page 5


18
Advanced C Programming Laboratory

RESULT:

The C Program is executed successfully to find volume of cylinder using pointer.

Roll No : 20F110-BHAVISHYA.S Page 6


19
Advanced C Programming Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION A

Ex : No : 04

TITLE POINTER

Roll No : 20F110-BHAVISHYA.S Page 1


20
Advanced C Programming Laboratory

Ex. No : 04 C program to perform multiplication of three float numbers using pointer

PROBLEM STATEMENT

Write a program to perform multiplication of three float numbers using pointer

Constraints:

Variable Name Data type

Ia=7,ib=9,ic=8,*pt1=&ia,*pt2=&ib,*pt3=&ic int

Roll No : 20F110-BHAVISHYA.S Page 2


21
Advanced C Programming Laboratory

SOLUTION
AIGORITHM

BEGIN

STEP 1: Declare and initialize ia=7,ib=9,ic=8 of float data type.

STEP 2: Declare float *ip1=&ia,*ip2=&ib,*ip3=&ic.

STEP 3: Diaplay *ip1 * *ip2 * *ip3.

END

Roll No : 20F110-BHAVISHYA.S Page 3


22
Advanced C Programming Laboratory

PROGRAM:

#include <stdio.h>
int main()
{
float ia=7,ib=9,ic=8;
float *pt1=&ia,*pt2=&ib,*pt3=&ic;
printf(" PRODUCT IS:%f ",*pt1 * *pt2 * *pt3);
return 0;
}

Roll No : 20F110-BHAVISHYA.S Page 4


23
Advanced C Programming Laboratory

01 - OUTPUT

Roll No : 20F110-BHAVISHYA.S Page 5


24
Advanced C Programming Laboratory

RESULT:

The C Program is executed successfully to perform multiplication of three float numbers using
pointer

Roll No : 20F110-BHAVISHYA.S Page 6


25
Advanced C Programming Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION A

Ex : No : 05

TITLE POINTER

Roll No : 20F110-BHAVISHYA Page 1


26
Advanced C Programming Laboratory

Ex. No : 05 C program to find area of rectangle using void pointer.

PROBLEM STATEMENT

Write a program to find area of rectangle using void pointer.

Constraints:

Variable Name Data type

Il,ib Int
*vt1=&il,*vt2=&ib Void.

Roll No : 20F110-BHAVISHYA Page 2


27
Advanced C Programming Laboratory

SOLUTION

AIGORITHM

BEGIN

STEP 1: Declare and initialize il=7,ib=22 of int datatype.

STEP 2: Initialize *vt1=&il, *vt2=&ib.

STEP 3:Diaplay AREA=*(int*)vt1 * *(int*)vt2.

END

Roll No : 20F110-BHAVISHYA Page 3


28
Advanced C Programming Laboratory

PROGRAM:
#include <stdio.h>
int main()
{
int il=7,ib=22;
void *vt1=&il,*vt2=&ib;
printf(" AREA=%d",*(int*)vt1 * *(int*)vt2);
return 0;
}

Roll No : 20F110-BHAVISHYA Page 4


29
Advanced C Programming Laboratory

01 - OUTPUT

Roll No : 20F110-BHAVISHYA Page 5


30
Advanced C Programming Laboratory

RESULT:

The C Program is executed successfully to find area of rectangle using void pointer

Roll No : 20F110-BHAVISHYA Page 6


31
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 6

TITLE POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


32
Programming Logic and Design Laboratory

Ex. No : 06 C program to check whether the number is leap year or not using void
pointer.

PROBLEM STATEMENT
Write a program to check whether the number is leap year or not using void pointer.
Constraints:

Variable Name Data type

Iyear int
*ipt=&iyear void

Roll No : 20F110 –BHAVISHYA.S Page 2


33
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare iyear of int datatype

• STEP 2: Using void operator declare *ipt=&iyear.

• STEP 3:Get the year from the user .

• STEP 4:Using if operator check (*(int*)ipt%4==0).

• STEP 5:If true, display is a Leap year , else print is not a Leap year

END

Roll No : 20F110 –BHAVISHYA.S Page 3


34
Programming Logic and Design Laboratory

PROGRAM:
//pgm to check year is leap yr or not using vois pointer
#include<stdio.h>
#
void main()
{
int iyear;
void *ipt=&iyear;
printf("Enter Year : ");
scanf("%d",&iyear);
if(*(int*)ipt%4==0)
printf("%d is a Leap Year",iyear);
else
printf("%d is not a Leap Year",iyear);

Roll No : 20F110 –BHAVISHYA.S Page 4


35
Programming Logic and Design Laboratory

01 - OUTPUT

02 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


36
Programming Logic and Design Laboratory

RESULT:
C program to check whether the number is leap year or not using void pointer has been
completed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


37
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 7

TITLE POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


38
Programming Logic and Design Laboratory

Ex. No : 7 C program to find cube of an number using void pointer.

PROBLEM STATEMENT
Write a program to find cube of an number using void pointer.
Constraints:

Variable Name Data type

inum int
*ipt=&inum void

Roll No : 20F110 –BHAVISHYA.S Page 2


39
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1:Declare int inum.

• STEP 2:Declare using void operator void *ipt=&inum.

• STEP 3: Get number inum from the user.

• STEP 4:Print cube: *(int*)ipt* *(int*)ipt* *(int*)ipt).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


40
Programming Logic and Design Laboratory

PROGRAM:

//program to find cube of an number using void pointer.


#include <stdio.h>
int main()
{
int inum;
void *ipt=&inum;
printf("\n ENTER NUMBER:");
scanf("%d",&inum);
printf("CUBE OF NUMBER IS:%u",*(int*)ipt* *(int*)ipt* *(int*)ipt);
return 0;
}

Roll No : 20F110 –BHAVISHYA.S Page 4


41
Programming Logic and Design Laboratory

01 - OUTPUT

02 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


42
Programming Logic and Design Laboratory

RESULT:
Program to find cube of an number using void pointer has been completed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


43
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 8

TITLE POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


44
Programming Logic and Design Laboratory

Ex. No : 8 C program to find square of number using pointer.

PROBLEM STATEMENT
Write a program to find square of number using pointer.
Constraints:

Variable Name Data type

inum,*ipt=&inum int

Roll No : 20F110 –BHAVISHYA.S Page 2


45
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1:Declare int inum,*ipt=&inum.

• STEP 2:Get the number from user.

• STEP 3:Display the square of the number-*ipt* *ipt.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


46
Programming Logic and Design Laboratory

PROGRAM:
//pgm to find square of a number using pointer
#include<stdio.h>
void main()
{
int inum,*ipt=&inum;
printf("\n ENTER A NUMBER:");
scanf("%d",&inum);
printf(" SQUARE OF THE NUMBER IS:%u",*ipt* *ipt);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


47
Programming Logic and Design Laboratory

01 - OUTPUT

02 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


48
Programming Logic and Design Laboratory

RESULT:
C program to find square of number using pointer has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


49
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 9

TITLE POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


50
Programming Logic and Design Laboratory

Ex. No : 9 C program swap two numbers using pointer.

PROBLEM STATEMENT
Write a program swap two numbers using pointer.
Constraints:

Variable Name Data type

ia=6,ib=10,ic,*ipt1=&ia,*ipt2=&ib,*ipt3=&ic int

Roll No : 20F110 –BHAVISHYA.S Page 2


51
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1:int ia=6,ib=10,ic,*ipt1=&ia,*ipt2=&ib,*ipt3=&ic.

• STEP 2:Display numbers before swapping- ",*ipt1,*ipt2.

• STEP 3:Initialize
*ipt3=*ipt1;
*ipt1=*ipt2;
*ipt2=*ipt3;

• STEP 4:Display after swapping *ipt1,*ipt2

END

Roll No : 20F110 –BHAVISHYA.S Page 3


52
Programming Logic and Design Laboratory

PROGRAM:
//pgm to swap two numbers using pointer
#include<stdio.h>
void main()
{
int ia=6,ib=10,ic,*ipt1=&ia,*ipt2=&ib,*ipt3=&ic;
printf("\n NUMBERS BEFORE SWAPPING: %u %u",*ipt1,*ipt2);
*ipt3=*ipt1;
*ipt1=*ipt2;
*ipt2=*ipt3;
printf("\n SWAPPED NUMBERS: %u %u",*ipt1,*ipt2);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


53
Programming Logic and Design Laboratory

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


54
Programming Logic and Design Laboratory

RESULT:
Swapping two numbers using pointer has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


55
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 10

TITLE POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


56
Programming Logic and Design Laboratory

Ex. No : 10 C program to find area of circle using generic pointer.

PROBLEM STATEMENT
Write a program to find area of circle using generic pointer.
Constraints:

Variable Name Data type

ir=22 int
*vpt=&ir. void

Roll No : 20F110 –BHAVISHYA.S Page 2


57
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1:Declare int ir=22.

• STEP 2: Using void operator declare void *vpt=&ir.

• STEP 3: Display area of circle 3.14* *(int*)vpt* *(int*)vpt.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


58
Programming Logic and Design Laboratory

PROGRAM:
// pgm to print area of circle using generic ptr
#include <stdio.h>
int main()
{
int ir=22;
void *vpt=&ir;
printf("AREA OF CIRCLE IS:%f",3.14* *(int*)vpt* *(int*)vpt);
return 0;
}

Roll No : 20F110 –BHAVISHYA.S Page 4


59
Programming Logic and Design Laboratory

01 – OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


60
Programming Logic and Design Laboratory

RESULT:
Finding area of circle using generic pointer has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


61
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 11

TITLE POINTER TO POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


62
Programming Logic and Design Laboratory

Ex. No : 11 C program swap two numbers using pointer to pointer.

PROBLEM STATEMENT
Write a program swap two numbers using pointer to pointer.
Constraints:

Variable Name Data type

ia=7,ib=9,ic
*ip1=&ia,*ip2=&ib,*ip3=&ic int
**ipp1=&ip1,**ipp2=&ip2,**ipp3=&ip3

Roll No : 20F110 –BHAVISHYA.S Page 2


63
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int ia=7,ib=9,ic.

• STEP 2:Declare int *ip1=&ia,*ip2=&ib,*ip3=&ic.

• STEP 3:Declare int **ipp1=&ip1,**ipp2=&ip2,**ipp3=&ip3.

• STEP 4: Display numbers before swapping -**ipp1,**ipp2.

• STEP 5:Initialize:
**ipp3=**ipp1;
**ipp1=**ipp2;
**ipp2=**ipp3;

• STEP 6:Display numbers after swapping -**ipp1,**ipp2.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


64
Programming Logic and Design Laboratory

PROGRAM:
// pgm to swap two numbers between pointer to pointer
#include <stdio.h>
int main()
{
int ia=7,ib=9,ic;
int *ip1=&ia,*ip2=&ib,*ip3=&ic;
int **ipp1=&ip1,**ipp2=&ip2,**ipp3=&ip3;
printf(" \n NUMBERS BEFORE SWAPPING: %u %u",**ipp1,**ipp2);
**ipp3=**ipp1;
**ipp1=**ipp2;
**ipp2=**ipp3;
printf("\nNUMBERS AFTER SWAPPING: %u %u",**ipp1,**ipp2);
return 0;
}

Roll No : 20F110 –BHAVISHYA.S Page 4


65
Programming Logic and Design Laboratory

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


66
Programming Logic and Design Laboratory

RESULT:
Swapping two numbers using pointer to pointer has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


67
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 12

TITLE POINTER AND ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


68
Programming Logic and Design Laboratory

Ex. No : 12 C program read array of 5 numbers and print the numbers using pointer
and array.

PROBLEM STATEMENT
Write a program read array of 5 numbers and print the numbers using pointer and array.
Constraints:

Variable Name Data type

ain[5],il int

Roll No : 20F110 –BHAVISHYA.S Page 2


69
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int ain[5],il.

• STEP 2: Using for loop , initialize il=0.

• STEP 3: Check condition il<5.

• STEP 4: Increment il - il++.

• STEP 5: Get the array elements from the user.

• STEP 6: Using for loop, initialize il=0.

• STEP 7: Check condition il<5.

• STEP 8: Increment il - il++.

• STEP 9: Display the array elements-*(ain+il).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


70
Programming Logic and Design Laboratory

PROGRAM:
// pgm to read array of numbers and print using pointer
#include <stdio.h>
int main()
{
int ain[5],il;
printf("\n ENTER ARRAY ELEMENTS:");
for(il=0;il<5;il++)
{
scanf("%d",&ain[il]);
}
printf("\n ARRAY ELEMENTS ARE:");
for(il=0;il<5;il++)
{
printf(" \t %u",*(ain+il));
}
return 0;
}

Roll No : 20F110 –BHAVISHYA.S Page 4


71
Programming Logic and Design Laboratory

01 - OUTPUT

02 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


72
Programming Logic and Design Laboratory

RESULT:
Reading array of 5 numbers and printing the numbers using pointer and array has been executed
successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


73
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 13

TITLE POINTER TO POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


74
Programming Logic and Design Laboratory

Ex. No : 13 C program to read and print 2*2 matrix using pointer and array.

PROBLEM STATEMENT
Write a program to read and print 2*2 matrix using pointer and array.
Constraints:

Variable Name Data type

ain[2][2]={12,23,45,66},ir,ic int

Roll No : 20F110 –BHAVISHYA.S Page 2


75
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1:Declare int ain[2][2]={12,23,45,66},ir,ic.

• STEP 2:Using for loop ,Initialize ir=0.

• STEP 3:Compare ir<2.

• STEP 4:Increment ir-ir++.

• STEP 5:Using for loop ,Initialize ic=0.

• STEP 6:Compare ic<2.

• STEP 7:Increment ic-ic++.

• STEP 8: Print array elements-",*(*(ain+ir)+ic)).

• STEP 9:Closing loop, print next line.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


76
Programming Logic and Design Laboratory

PROGRAM:
//pgm to read and prinr 2*2 matrix using pointer and array
#include<stdio.h>
void main()
{
int ain[2][2]={12,23,45,66},ir,ic;
for(ir=0;ir<2;ir++)
{
for(ic=0;ic<2;ic++)
{
printf("%d \t",*(*(ain+ir)+ic));
}
printf("\n");
}

Roll No : 20F110 –BHAVISHYA.S Page 4


77
Programming Logic and Design Laboratory

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


78
Programming Logic and Design Laboratory

RESULT:
Reading and printing 2*2 matrix using pointer and array has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


79
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 14

TITLE ARRY AND POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


80
Programming Logic and Design Laboratory

Ex. No :14 C program to print address of array elements using array of pointer.

PROBLEM STATEMENT
Write a program to print address of array elements using array of pointer.
Constraints:

Variable Name Data type

ain[5]={1,2,3,4,5},il. int
int *aip[5] int

Roll No : 20F110 –BHAVISHYA.S Page 2


81
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1:Declare int ain[5]={1,2,3,4,5},il.

• STEP 2:Declare int *aip[5];

• STEP 3: Using for loop ,Initialize il=0.

• STEP 4: Check condition il<5.

• STEP 5:Increment il-il++.

• STEP 6: Print array element and address -aip[il],aip[il]).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


82
Programming Logic and Design Laboratory

PROGRAM:
///pgm to print address of array elements using pointer
#include<stdio.h>
void main()
{
int ain[5]={1,2,3,4,5},il;
int *aip[5];
for(il=0;il<5;il++)
{
aip[il]=&ain[il];
printf("%d %u \n ",*aip[il],aip[il]);
}
}

Roll No : 20F110 –BHAVISHYA.S Page 4


83
Programming Logic and Design Laboratory

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


84
Programming Logic and Design Laboratory

RESULT:
Printing address of array elements using array of pointer has been executed successfully

Roll No : 20F110 –BHAVISHYA.S Page 6


85
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 15

TITLE POINTER TO POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


86
Programming Logic and Design Laboratory

Ex. No : 15 C program to find volume of cylinder using pointer to pointer.

PROBLEM STATEMENT
Write a program to find volume of cylinder using pointer to pointer.
Constraints:

Variable Name Data type

ir,ih,*ip1=&ir,*ip2=&ih int
**ipp1=&ip1,**ipp2=&ip2 int

Roll No : 20F110 –BHAVISHYA.S Page 2


87
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int ir,ih,*ip1=&ir,*ip2=&ih.

• STEP 2:Declare int **ipp1=&ip1,**ipp2=&ip2.

• STEP 3: Get the radius and height from the user – ir,ih.

• STEP 4: Display volume 3.14* **ipp1* **ipp1* **ipp2.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


88
Programming Logic and Design Laboratory

PROGRAM:
//pgm to find volume of cylinder using pointer to pointer
#include<stdio.h>
void main()
{
int ir,ih,*ip1=&ir,*ip2=&ih;
int **ipp1=&ip1,**ipp2=&ip2;
printf("\n ENTER RADIUS:");
scanf("%d",&ir);
printf("\n ENTER HEIGHT:");
scanf("%d",&ih);
printf("\n VOLUME:%f ",3.14* **ipp1* **ipp1* **ipp2);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


89
Programming Logic and Design Laboratory

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


90
Programming Logic and Design Laboratory

RESULT:
Finding volume of cylinder using pointer to pointer has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


91
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 16

TITLE POINTER AND ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


92
Programming Logic and Design Laboratory

Ex. No : 16 C program read array of 10 numbers check the number is odd or even using pointer
and array.

PROBLEM STATEMENT
Write a program read array of 10 numbers check the number is odd or even using pointer and
array.
Constraints:

Variable Name Data type

a[10]={12,13,45,66,78,90,77,67,51,35} int
*ipt=&a[0], il int

Roll No : 20F110 –BHAVISHYA.S Page 2


93
Programming Logic and Design Laboratory

SOLUTION

ALGORITHM:
STEP 1: Declare int a[10]={12,13,45,66,78,90,77,67,51,35}.
STEP 2:Declare int *ipt=&a[0].
STEP 3: Using for loop declare int il=0.
STEP 4: Check condition il<10.
STEP 5: Increment il - il++.
STEP 6: Check condition using if(a[il]%2==0).
STEP 7: If true display “EVEN",*(ipt+il).
STEP 8: If false display “ODD",*(ipt+il)
.

Roll No : 20F110 –BHAVISHYA.S Page 3


94
Programming Logic and Design Laboratory

PROGRAM:
// check odd or even using pointer array
#include <stdio.h>

int main()

{
int a[10]={12,13,45,66,78,90,77,67,51,35};
int *ipt=&a[0];
for(int il=0;il<10;il++)
{
if(a[il]%2==0)
printf("\n%d-EVEN",*(ipt+il));
else
printf("\n %d -ODD",*(ipt+il));
}

return 0;
}

Roll No : 20F110 –BHAVISHYA.S Page 4


95
Programming Logic and Design Laboratory

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


96
Programming Logic and Design Laboratory

RESULT:
Reading array of 10 numbers check the number is odd or even using pointer and array has been
executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


97
Programming Logic and Design Laboratory

Roll No : 20F110 –BHAVISHYA.S Page 7


98
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 17

TITLE POINTER NOTATION

Roll No : 20F110 –BHAVISHYA.S Page 1


99
Programming Logic and Design Laboratory

Ex. No : 17 C program to set primary and secondary diagonal elements to 0 using pointer notation

PROBLEM STATEMENT
Write a to set primary and secondary diagonal elements to 0 using pointer notation
Constraints:

Variable Name Data type

ain[3][3]={{12,23,45},{66,87,3 int
3},{54,32,72,90}},ir,ic

Roll No : 20F110 –BHAVISHYA.S Page 2


100
Programming Logic and Design Laboratory

SOLUTION

ALGORITHM:
START
STEP 1: Declare ain[3][3]={{12,23,45},{66,87,33},{54,32,72,90}},ir,ic.
STEP 2: Using for loop initialize int ir=0.
STEP 3: Check condition ir<10.
STEP 4: Increment ir - ir++.
STEP 5: Using for loop initialize int ic=0.
STEP 6: Check condition ic<10.
STEP 7: Increment ic - ic++.
STEP 8:Check condition if(ir==ic||(ir+ic+1)==3).
STEP 9: if true ain[ir][ic]=0.
STEP 10:Display ",*(*(ain+ir)+ic))
END

Roll No : 20F110 –BHAVISHYA.S Page 3


101
Programming Logic and Design Laboratory

PROGRAM:

#include<stdio.h>
void main()
{
int ain[3][3]={{12,23,45},{66,87,33},{54,32,72}},ir,ic;
for(ir=0;ir<3;ir++)
{
for(ic=0;ic<3;ic++)
{
if(ir==ic||(ir+ic+1)==3)
ain[ir][ic]=0;
printf("%d \t",*(*(ain+ir)+ic));
}
printf("\n");
}
}

Roll No : 20F110 –BHAVISHYA.S Page 4


102
Programming Logic and Design Laboratory

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


103
Programming Logic and Design Laboratory

RESULT:
Setting primary and secondary diagonal elements to 0 using pointer notation has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


104
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 18

TITLE POINTER NOTATION

Roll No : 20F110 –BHAVISHYA.S Page 7


105
Programming Logic and Design Laboratory

Ex. No : 18 C program perform matrix multiplication using pointer notation.

PROBLEM STATEMENT
Write a program perform matrix multiplication using pointer notation.
Constraints:

Variable Name Data type

ain1[2][2]={1,2,3,4},ain2[3][3] int
={7,12,20,13},ir,ic,imul[2][2]

Roll No : 20F110 –BHAVISHYA.S Page 8


106
Programming Logic and Design Laboratory

SOLUTION

ALGORITHM:
START
• STEP 1:Declare int ain1[2][2]={1,2,3,4},ain2[3][3]={7,12,20,13},ir,ic,imul[2][2].
• STEP 2:Display product of the matrix.
• STEP 3: Using for loop initialize int ir=0.
• STEP 4: Check condition ir<10.
• STEP 5: Increment ir - ir++.
• STEP 6: Using for loop initialize int ic=0.
• STEP 7: Check condition ic<10.
• STEP 8: Increment ic - ic++.
• STEP 9: Initialize imul[ir][ic]=0.
• STEP 10: Initialize imul[ir][ic]+=ain1[ir][ic]*ain2[ir][ic];
• STEP 11: Using for loop initialize int ir=0.
• STEP 12: Check condition ir<10.
• STEP 13: Increment ir - ir++.
• STEP 14: Using for loop initialize int ic=0.
• STEP 15: Check condition ic<10.
• STEP 16: Increment ic - ic++.
• STEP 17: Display *(*imul+ir)+ic).

END

Roll No : 20F110 –BHAVISHYA.S Page 9


107
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
void main()
{
int ain1[2][2]={1,2,3,4},ain2[3][3]={7,12,20,13},ir,ic,imul[2][2];
printf("Product of the matrix=\n");
for(ir=0;ir<2;ir++)
{
for(ic=0;ic<2;ic++)
{
imul[ir][ic]=0;
imul[ir][ic]+=ain1[ir][ic]*ain2[ir][ic];
}
}
for(ir=0;ir<2;ir++)
{
for(ic=0;ic<2;ic++)
{
printf("%d\t",*(*imul+ir)+ic);
}
printf("\n");
}

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page


10
108
Programming Logic and Design Laboratory

RESULT:
Performing matrix multiplication using pointer notation has been completed successfully.

Roll No : 20F110 –BHAVISHYA.S Page


11
109
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 19

TITLE POINTER NOTATION

Roll No : 20F110 –BHAVISHYA.S Page


12
110
Programming Logic and Design Laboratory

Ex. No : 19 C program to find check the matrix is sparse matrix or not using pointer

PROBLEM STATEMENT
. Write a program to find check the matrix is sparse matrix or not using pointer
Constraints:

Variable Name Data type

aim[3][3]={20,18,27,0,49,35 int
,87,92,0},ir,ic,iz=0
(*p)[3]=aim

Roll No : 20F110 –BHAVISHYA.S Page


13
111
Programming Logic and Design Laboratory

SOLUTION

ALGORITHM:
START
• STEP 1: Declare int aim[3][3]={20,18,27,0,49,35,87,92,0},ir,ic,iz=0.
• STEP 2: Declare int(*p)[3]=aim.
• STEP 3: In for loop Declare ir=0
• STEP 4: Check condition ir<3.
• STEP 5: Increment ir++.
• STEP 6: In for loop Declare ic=0
• STEP 7: Check condition ic<3.
• STEP 8: Increment ic++.
• STEP 9: Check condition using if((*(*p+ir)+ic)==0)
• STEP 10: Increment iz- iz++.
• STEP 11:Check condition if((3*3)/2==iz).
• STEP 12:If true print Sparse matrix.
• STEP 13:Else print NOT.

END

Roll No : 20F110 –BHAVISHYA.S Page


14
112
Programming Logic and Design Laboratory

PROGRAM:
//pgm to print sparse matrix
#include <stdio.h>
int main()
{
int aim[3][3]={20,18,27,0,49,35,87,92,0},ir,ic,iz=0;
int(*p)[3]=aim;
for(ir=0;ir<3;ir++)
{
for(ic=0;ic<3;ic++)
{
if((*(*p+ir)+ic)==0);
iz++;
}
}
if((3*3)/2==iz)
printf("Sparse matrix");
else
printf("\n NOT");
return 0;
}
}

Roll No : 20F110 –BHAVISHYA.S Page


15
113
Programming Logic and Design Laboratory

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page


16
114
Programming Logic and Design Laboratory

RESULT:
Checking the matrix is sparse matrix or not using pointer has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page


17
115
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 20

TITLE POINTER AND ARRAY

Roll No : 20F110 –BHAVISHYA.S Page


18
116
Programming Logic and Design Laboratory

Ex. No : 20 C program to check the matrix is identity matrix using pointer and array

PROBLEM STATEMENT
Write a program to check the matrix is identity matrix using pointer and array
Constraints:

Variable Name Data type

arr1[3][3]={1,0,0,0,1,0,0,0,1}, int
ir,ic,flag=1.

Roll No : 20F110 –BHAVISHYA.S Page


19
117
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int arr1[3][3]={1,0,0,0,1,0,0,0,1}.


• STEP 2: Declare ir,ic.

• STEP 3: Declare flag=1.

• STEP 4: Using for loop initialize ir=0.

• STEP 5: Check condition ir<3.

• STEP 6: Increment ir- ir++.

• STEP 7: Using for loop initialize ic=0.

• STEP 8: Check condition ic<3.

• STEP 9: Increment ic- ic++.

• STEP 10: Display "*(*(arr1+ir)+ic)) using array and pointer.

• STEP 11: Using for loop initialize ir=0.

• STEP 12: Check condition ir<3.

• STEP 13: Increment ir- ir++.

• STEP 14: Using for loop initialize ic=0.

• STEP 15: Check condition ic<3.

• STEP 16: Increment ic- ic++.

• STEP 17: Initialize flag=0.

• STEP 18: Check condition if flag==1, If true print It is identity matrix .

• STEP 19:Else print not identity matrix.

END

Roll No : 20F110 –BHAVISHYA.S Page


20
118
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
void main()
{
int arr1[3][3]={1,0,0,0,1,0,0,0,1};
int ir,ic;
int flag=1;

printf("MATRIX :\n");
for(ir=0;ir<3;ir++)
{
for(ic=0;ic<3;ic++)
printf("%d",*(*(arr1+ir)+ic));
printf("\n");
}

for(ir=0;ir<3;ir++)
{
for(ic=0;ic<3;ic++)
{
if(arr1[ir][ic]!=1&&arr1[ir][ic]!=0)
{
flag=0;
break;
}
}
}

if(flag==1)
printf(" The matrix is an identity matrix.\n\n");
else
printf(" The matrix is not an identity matrix.\n\n");
}

Roll No : 20F110 –BHAVISHYA.S Page


21
119
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
Checking the matrix is identity matrix using pointer and array has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page


22
120
Programming Logic and Design Laboratory

Roll No : 20F110 –BHAVISHYA.S Page


23
121
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 21

TITLE POINTER TO AN ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


122
Programming Logic and Design Laboratory

Ex. No : 21 C program read array of 5 numbers and print the numbers along with
address using pointer to an
array.

PROBLEM STATEMENT
Write a program read array of 5 numbers and print the numbers along with address using pointer
to an array.
Constraints:

Variable Name Data type

int
ain[5]={12,34,56,72,99},il
int
*ip=&ain[0]

Roll No : 20F110 –BHAVISHYA.S Page 2


123
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int ain[5]={12,34,56,72,99},il.

• STEP 2: Declare *ip=&ain[0];

• STEP 3: In for loop initialize il=0.

• STEP 4: Check condition il<5.

• STEP 5: Increment il- il++.

• STEP 6:Display array elements and memeory address using pointer to array-

*(ip+il),(ip+il).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


124
Programming Logic and Design Laboratory

PROGRAM:
//program read array of 5 numbers and print the numbers along with address using pointer to an
array.
#include <stdio.h>
int main()
{
int ain[5]={12,34,56,72,99},il;
int*ip=&ain[0];
for(il=0;il<5;il++)
printf("%d %d \t ",*(ip+il),(ip+il));

return 0;
}

Roll No : 20F110 –BHAVISHYA.S Page 4


125
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
Reading array of 5 numbers and print the numbers along with address using pointer to an array
has been completed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


126
Programming Logic and Design Laboratory

Roll No : 20F110 –BHAVISHYA.S Page 6


127
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 22

TITLE POINTER TO AN ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


128
Programming Logic and Design Laboratory

Ex. No : 22 C program to find sum of array elements using pointer to an array.

PROBLEM STATEMENT
Write a program to find sum of array elements using pointer to an array.
Constraints:

Variable Name Data type

ain[5]={1,2,3,4,5},il,isum=0 int
*p=ain

Roll No : 20F110 –BHAVISHYA.S Page 2


129
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int ain[5]={1,2,3,4,5},il,isum=0.

• STEP 2: Declare *p=ain.

• STEP 3: In for loop initialize il=0.

• STEP 4: Check condition il<5.

• STEP 5: Increment il- il++.

• STEP 6:Initialize isum+=*(p+il).

• STEP 7:Print sum -isum.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


130
Programming Logic and Design Laboratory

PROGRAM:
//Write a program to find sum of array elements using pointer to an array.
#include<stdio.h>
void main()
{
int ain[5]={1,2,3,4,5},il,isum=0;
int *p=ain;
for(il=0;il<5;il++)
{
isum+=*(p+il);
}
printf("\n SUM= %d",isum);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


131
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
Finding sum of array elements using pointer to an array has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


132
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 23

TITLE POINTER TO AN ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


133
Programming Logic and Design Laboratory

Ex. No : 23 C program to reverse array of 10 float values using pointer to an array.

PROBLEM STATEMENT
Write a program to reverse array of 10 float values using pointer to an array.
Constraints:

Variable Name Data type

a[5],*p=a float
il int

Roll No : 20F110 –BHAVISHYA.S Page 2


134
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int a[5],*p=a.

• STEP 2: declare il.

• STEP 3: In for loop initialize il=0.

• STEP 4: Check condition il<5.

• STEP 5: Increment il- il++.

• STEP 6:Get array elements -(p+il).

• STEP 7: Then using for loop for(i=4;i>0;i--).

• STEP 8: Display array elements-*(p+il)).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


135
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
void main()
{
float a[5],*p=a;
int il;
printf("\nEnter the array element:");
for(il=0;il<5;il++)
scanf("%f",(p+il));
printf("\n array element in reverse order");
for(il=4;il>=0;il--)
printf("\n %2f",*(p+il));
}

Roll No : 20F110 –BHAVISHYA.S Page 4


136
Programming Logic and Design Laboratory

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


137
Programming Logic and Design Laboratory

RESULT:
Reversing float values using pointer to array has been completed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


138
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 24

TITLE POINTER TO ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


139
Programming Logic and Design Laboratory

Ex. No : 24 C program to find largest element in an array using pointer to an array

PROBLEM STATEMENT
Write a program to find largest element in an array using pointer to an array
Constraints:

Variable Name Data type

a[5],*p=a,i int

Roll No : 20F110 –BHAVISHYA.S Page 2


140
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP1:Initialization int a[5],i,j;


• STEP2:Using for loop for(i=0;i<5;i++) for scan array element
• STEP3:Copy the array element to pointer
• STEP4:Then using for loop for(i=0;i<5;i++) for printing
• STEP5:Then print*(p+i)
• STEP6:Initialize*(p+0)
• STEP7:using fo rloop (i=0;i<5;i++)
• STEP7.1:if*(p+i)>*(p+0)
• STEP8:This condition is true print large number.

END

PROGRAM:

Roll No : 20F110 –BHAVISHYA.S Page 3


141
Programming Logic and Design Laboratory

#include<stdio.h>
void main()
{
int a[5],*p=a;
int i;
printf("\nEnter the array element:");
for(i=0;i<5;i++)
scanf("%d",(p+i));
printf("array element is");
for(i=0;i<5;i++)
{
printf("%d\t",*(p+i));
}
int large=*(p+0);
for(i=0;i<5;i++)
{
if(*(p+i)>*(p+0))
{
large=*(p+i);
break;
}
}
printf("\nlargest number in array is:%d",large);
}

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 4


142
Programming Logic and Design Laboratory

RESULT:
Finding largest element in an array using pointer to an array has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


143
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 25

TITLE POINTER TO ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


144
Programming Logic and Design Laboratory

Ex. No : 25 C program to sort array elements using pointer to an array.

PROBLEM STATEMENT
Write a program to sort array elements using pointer to an array.
Constraints:

Variable Name Data type

int a[5],*p=a,j,t,i int

Roll No : 20F110 –BHAVISHYA.S Page 2


145
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1:initializing the array


• STEP 2:Using for loop for(i=0;i<5;i++) for scan array
element
• STEP 3:Copy the array element to pointer
• STEP 4:sorting the array element using swap logic using
Temper or variable method
• STEP 5:Then all the element in array using for loop print
*(p+i)

END

PROGRAM:

Roll No : 20F110 –BHAVISHYA.S Page 3


146
Programming Logic and Design Laboratory

#include<stdio.h>
void main()
{
int a[5],*p=a,j,t;
int i;
printf("\nEnter the array element:");
for(i=0;i<5;i++)
scanf("%d",(p+i));
printf("before sorting array element is");
for(i=0;i<5;i++)
{
printf("%d\t",*(p+i));
}
for(i=0;i<5;++i)
{
for(j=i+1;j<5;++j)
{
if(*(p+i)>*(p+j))
{
t=*(p+i);
*(p+i)=*(p+j);
*(p+j)=t;
}
}
}
printf("\nafter sorting:");
for(i=0;i<5;i++)

Roll No : 20F110 –BHAVISHYA.S Page 4


147
Programming Logic and Design Laboratory

printf("%d\t",*(p+i));
}

01 - OUTPUT

RESULT:
Sorting array elements using pointer to an array has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


148
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 26

TITLE POINTER TO ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


149
Programming Logic and Design Laboratory

Ex. No : 26 C program read 3*3 matrix and print transpose of matrix using pointer to
an array.

PROBLEM STATEMENT
Write a program read 3*3 matrix and print transpose of matrix using pointer to an array.
Constraints:

Variable Name Data type

a[3][3],i,j, (*p)[3]=a int

Roll No : 20F110 –BHAVISHYA.S Page 2


150
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP1: Initialization int a[3][3],i,j.


• STEP2:int(*p)[3]=a.
• STEP3: Using for loop for(i=0;i<3;i++) for scan array
element
• STEP3.1: Then using for loop for(j=0;j<3;j++)for printing
• STEP3.2: scan a[i][j]
• STEP4: Using for loop for(i=0;i<3;i++) for scan array element
• STEP4.1: Then using for loop for (j=0;j<3;j++) for printing
• STEP4.2:print*(*(p+j)+i)
• STEP5:print next line using by\n.

END

PROGRAM:

Roll No : 20F110 –BHAVISHYA.S Page 3


151
Programming Logic and Design Laboratory

include<stdio.h>
void main()
{
int a[3][3],i,j;
int(*p)[3]=a;
printf("Enter array element");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Transpose of matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",*(*(p+j)+i));
}printf("\n");
}
}

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 4


152
Programming Logic and Design Laboratory

RESULT:
.Reading 3*3 matrix and printing transpose of matrix using pointer to an array has been executed
successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


153
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 27

TITLE POINTER TO ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


154
Programming Logic and Design Laboratory

Ex. No : 27 C program to set primary and secondary diagonal elements to 0 using


pointer to an array.

PROBLEM STATEMENT
Write a program to set primary and secondary diagonal elements to 0 using pointer to an array.
Constraints:

Variable Name Data type

aim[3][3]={2,3,4,5,6,7,2,3,4} int
(*p)[3]=aim,ir,ic

Roll No : 20F110 –BHAVISHYA.S Page 2


155
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP1:Initialization int aim[3][3]={2,3,4,5,6,7,2,3,4,},ir,ic;


• STEP2: int(*p)[3]=aim;
• STEP3: Using for loop for(ir=0;ir<3;ir++)for scan array
element
• STEP3.1:Then using for loop for (ic=0;ic<3;ic++) for printing
• STEP3.2:if(ir==ic||ic+ir==2)
• STEP3.2.1: print0
• STEP4: Else printf("%d\t",*(*(p+ir)+ic));
• STEP5:Print next line using\n

END

Roll No : 20F110 –BHAVISHYA.S Page 3


156
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
void main()
{
int aim[3][3]={2,3,4,5,6,7,2,3,4};
int(*p)[3]=aim;
int ir,ic;
for(ir=0;ir<3;ir++)
{
for(ic=0;ic<3;ic++)
{
if(ir==ic||ic+ir==2)
{
printf("0\t");
}
else
{
printf("%d\t",*(*(p+ir)+ic));
}
}printf("\n");
}
}

Roll No : 20F110 –BHAVISHYA.S Page 4


157
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
.Setting primary and secondary diagonal elements to 0 using pointer to an array has been
completed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


158
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 28

TITLE POINTER TO ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


159
Programming Logic and Design Laboratory

Ex. No : 28 C program add two matrix using pointer to an array.

PROBLEM STATEMENT
Write a program add two matrix using pointer to an array.
Constraints:

Variable Name Data type

a[2][2],b[2][2],i,j,add[2][2] int
int(*p)[2]=a int
int(*p1)[2]=b int

Roll No : 20F110 –BHAVISHYA.S Page 2


160
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1:Initialization int a[2][2],b[2][2], i,j ,add[2][2];


• STEP 2:int(*p)[2]=a,(*p1)[2]=b;
• STEP 3:Using for loop for(i=0;i<3;i++) for scan array element
• STEP 3.1:Then using for loop for(j=0;j<3;j++)for printing
• STEP 3.2:scan a[i][j]
• STEP 4:Using for loop for(i=0;i<3;i++) for scan array element
• STEP 4.1:Then using for loop for(j=0;j<3;j++ )for printing
• STEP 4.2:scan b[i][j]
• STEP 5:print addition of matrix
• STEP 6:Using for loop for(i=0;i<3;i++) for scan array element
• STEP 6.1:Then using for loop for(j=0;j<3;j++)for printing
• STEP 7:add[i][j]=(*(*p+i)+j)+(*(*p1+i)+j).
• STEP 8: Using forloop for(i=0;i<3;i++) for scan array element
• STEP 8.1:Then using for loop for(j=0;j<3;j++) for printing
• STEP 8.2:printf("%d",add[i][j]).
• STEP 9:print next line using\n

END

Roll No : 20F110 –BHAVISHYA.S Page 3


161
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
int main()
{
int a[2][2],b[2][2],i,j,add[2][2];
int(*p)[2]=a;
int(*p1)[2]=b;
printf("Enter the 1st array element:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the 2nd array element:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("addition of two arrayis:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{

Roll No : 20F110 –BHAVISHYA.S Page 4


162
Programming Logic and Design Laboratory

add[i][j]=(*(*p+i)+j)+(*(*p1+i)+j);
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d \t ",add[i][j]);
}printf("\n");
}}

Roll No : 20F110 –BHAVISHYA.S Page 5


163
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
Adding two matrix using pointer to an array has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


164
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 29

TITLE POINTER TO ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


165
Programming Logic and Design Laboratory

Ex. No : 29 C program to perform matrix multiplication using VLA.

PROBLEM STATEMENT
Write a program to perform matrix multiplication using VLA.
Constraints:

Variable Name Data type

r,c,i,j,k, Int
a[r][c],b[r][c],mul[r][c],
Int
(*p)[c]=a
Int
(*p1)[c]=b
int

Roll No : 20F110 –BHAVISHYA.S Page 2


166
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN’

• STEP1:Initialization int r,c,i,j,k,


• STEP2:Read the value r,c
• STEP3:int a[r][c],b[r][c],mul[r][c].
• STEP4:int(*p)[c]=a,(*p1)[c]=b.
• STEP5:Using for loop for(i=0;i<r;i++) for scan array element
• STEP5.1:Then using for loop for(c=0;c<3;c++)for printing
• STEP5.2:scan a[i][j]
• STEP6:Using for loop for(j=0;j<c;j++)for scan array element
• STEP6.1:Then using for loop for(j=0;j<3;j++)for printing
• STEP6.2:scan b[i][j]
• STEP7:print addition of matrix
• STEP8:Using for loop for(i=0;i<3;i++)for scan array element
• STEP8.1: Then using for loop for(j=0;j<3;j++)for printing
• STEP8.2: mul[i][j]=0;
• STEP8.2.1: for(k=0;k<c;k++)
• STEP8.2.2: mul[i][j]+=*(*(p+i)+k)**(*(p1+k)+j).
• STEP9:print multiplication of array
• STEP10:Using for loop for(i=0;i<r;i++)for scan array element
• STEP10.1:Then using for loop for(j=0;j<c;j++)for printing
• STEP10.2:printf("%d",mul[i][j]);
• STEP11:print next line using\n

END

Roll No : 20F110 –BHAVISHYA.S Page 3


167
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
int main()
{
int r,c,i,j,k;
printf("enter the value for row and column:");
scanf("%d %d",&r,&c);
int a[r][c],b[r][c],mul[r][c];
int(*p)[c]=a;
int(*p1)[c]=b;
printf("enter the element for first array:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the element for second array:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<r;i++)

Roll No : 20F110 –BHAVISHYA.S Page 4


168
Programming Logic and Design Laboratory

{
for(j=0;j<c;j++)
{
mul[i][j]=0; for(k=0;k<c;k++)
{
mul[i][j]+=*(*(p+i)+k)**(*(p1+k)+j);
}
}
}
printf("multiplication of array:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d \t",mul[i][j]);
}printf("\n");
}
}

Roll No : 20F110 –BHAVISHYA.S Page 5


169
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
.Performing matrix multiplication using VLA has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 6


170
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 30

TITLE POINTER TO ARRAY

Roll No : 20F110 –BHAVISHYA.S Page 1


171
Programming Logic and Design Laboratory

Ex. No : 30 C program to print alternative elements using VLA.

PROBLEM STATEMENT
Write a program to print alternative elements using VLA.
Constraints:

Variable Name Data type

n,a[n],*p=a,i int

Roll No : 20F110 –BHAVISHYA.S Page 2


172
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP1: Initialization int a[5],i,j;


• STEP2: Using for loop for(i=0;i<5;i++)for scan array
• element
• STEP3: Copy the array element to pointer
• STEP4: Then using for loop for(i=0;i<5;i+2)for printing
• STEP5: Then print*(p+i)
• STEP6: display the alternative number in array.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


173
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
void main()
{
int n;
printf("enter the value for row");
scanf("%d",&n);
int a[n];
int*p=a;
int i;
printf("enter the element of an array\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Alternate elements of a given array\n");
for(i=0;i<10;i+=2)
printf("%d\n",*(p+i));
}

Roll No : 20F110 –BHAVISHYA.S Page 4


174
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
Printing alternative elements using VLA has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


175
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 31

TITLE STRING HANDLING

Roll No : 20F110 –BHAVISHYA.S Page 1


176
Programming Logic and Design Laboratory

Ex. No : 31 C program to find length of the string " advanced c program".

PROBLEM STATEMENT
Write a program to find length of the string " advanced c program".
Constraints:

Variable Name Data type

cstr[100]="advanced c char
program"
il,len
int

Roll No : 20F110 –BHAVISHYA.S Page 2


177
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char cstr[100]="advanced c program.

• STEP 2: Declare int il,len=0.

• STEP 3: Using for loop initialize, check condition, increment (il=0;cstr[il]!='\0';il++).

• STEP 4: Increment length-len.

• STEP 5: Display length.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


178
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
void main()
{
char cstr[100]="advanced c program";
int il,len=0;
for(il=0;cstr[il]!='\0';il++)
len++;
printf("the length of given string is:%d",len);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


179
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
Finding length of the string " advanced c program" has been completed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


180
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 32

TITLE STRING HANDLING

Roll No : 20F110 –BHAVISHYA.S Page 1


181
Programming Logic and Design Laboratory

Ex. No : 32 C program to copy the word “Coimbatore” using string handling function

PROBLEM STATEMENT
Write a program to copy the word “Coimbatore” using string handling function
Constraints:

Variable Name Data type

cstr[100]= Char
"Coimbatore",cstr1[100]
il
int

Roll No : 20F110 –BHAVISHYA.S Page 2


182
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char cstr[100]= "Coimbatore",cstr1[100].

• STEP 2: Declare int il.

• STEP 3: Using for loop initialize, check condition, increment(il=0; cstr[il]!='\0';il++).

• STEP 4: Using string handling function copy cstr to cstr1 strcpy(cstr1,cstr).

• STEP 5: Display given and copied string.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


183
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
#include<string.h>
void main()
{
char cstr[100]= "Coimbatore",cstr1[100];
int il;
for(il=0;cstr[il]!='\0';il++)
strcpy(cstr1,cstr);
printf("Given string:%s",cstr);
printf("\n Copied string:%s",cstr1);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


184
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
. Coping the word “Coimbatore” using string handling function has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


185
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 33

TITLE STRING HANDLING

Roll No : 20F110 –BHAVISHYA.S Page 1


186
Programming Logic and Design Laboratory

Ex. No : 33 C program to merge two string using strcat function

PROBLEM STATEMENT
Write a program to merge two string using strcat function
Constraints:

Variable Name Data type

cstr[100]="BTS",cstr1[100]="ARMY". char

Roll No : 20F110 –BHAVISHYA.S Page 2


187
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare cstr[100]="BTS",cstr1[100]="ARMY".

• STEP 2: Using string concatenating function display string strcat(cstr,cstr1)

END

Roll No : 20F110 –BHAVISHYA.S Page 3


188
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
#include<string.h>
int main()
{
char cstr[100]="BTS",cstr1[100]="ARMY";

printf("CONCATINATED STRING:%s",strcat(cstr,cstr1));

return 0;
}

Roll No : 20F110 –BHAVISHYA.S Page 4


189
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
. Merging two string using strcat function has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


190
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 34

TITLE STRING HANDLING

Roll No : 20F110 –BHAVISHYA.S Page 1


191
Programming Logic and Design Laboratory

Ex. No : 34 C program to find first occurrence of character a in the string "karpagam


college of
engineering".

PROBLEM STATEMENT
Write a program to find first occurrence of character a in the string "karpagam college of
engineering".
Constraints:

Variable Name Data type

str[100]="karpagam college char


of engineering",str1[5]="a"

Roll No : 20F110 –BHAVISHYA.S Page 2


192
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare str[100]="karpagam college of engineering",str1[5]="a".

• STEP 2: Using string handling function print the first occurrence of a strstr(str,str1).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


193
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
#include<string.h>
void main()
{
char str[100]="karpagam college of engineering",str1[5]="a";
printf("\n the first occurrence of character a in the string is :: %s",strstr(str,str1));
}

Roll No : 20F110 –BHAVISHYA.S Page 4


194
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
Finding first occurrence of character a in the string "karpagam college of
engineering" has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


195
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 35

TITLE STRING HANDLING

Roll No : 20F110 –BHAVISHYA.S Page 1


196
Programming Logic and Design Laboratory

Ex. No : 35 C program to find substring using strstr function.

PROBLEM STATEMENT
Write a program to find substring using strstr function.
Constraints:

Variable Name Data type

Roll No : 20F110 –BHAVISHYA.S Page 2


197
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str[100]="karpagam college of engineering",str1[100]="college".

• STEP 2: Using string handling function strstr display the substring.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


198
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
#include<string.h>
void main()
{
char str[100]="karpagam college of engineering",str1[100]="college";
printf(" substring present in given string is :: %s",strstr(str,str1));
}

Roll No : 20F110 –BHAVISHYA.S Page 4


199
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
Finding substring using strstr function has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


200
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 36

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


201
Programming Logic and Design Laboratory

Ex. No : 36 C program to remove the delimiter space and : .

PROBLEM STATEMENT
Write a program to remove the delimiter space and : .
Constraints:

Variable Name Data type

char a[100]="kce:cbe",*p char

Roll No : 20F110 –BHAVISHYA.S Page 2


202
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char a[100]="kce:cbe",*p.

• STEP 2: Initialize p=strtok(a,":").

• STEP 3: In while loop check condition p!=NULL

• STEP 4: Display p.

• STEP 5: Using string handling function Display p=strtok(NULL,";");


END

Roll No : 20F110 –BHAVISHYA.S Page 3


203
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
char a[100]="kce:cbe",*p;
p=strtok(a,":");
while(p!=NULL)
{
printf("%s",p);
p=strtok(NULL,";");
}
}

Roll No : 20F110 –BHAVISHYA.S Page 4


204
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
Removing the delimiter space and : has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


205
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 37

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


206
Programming Logic and Design Laboratory

Ex. No : 37 C program to find length of the word without using strlen.

PROBLEM STATEMENT
Write a program to find length of the word without using strlen.
Constraints:

Variable Name Data type

cstr[10]=”ARMY” char
il,len=0 int

Roll No : 20F110 –BHAVISHYA.S Page 2


207
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char cstr[10]=”ARMY”.

• STEP 2: Declare int il,len=0.

• STEP 3:In for loop declare il=0.

• STEP 4: Compare condition cstr[il]!='\0' .

• STEP 5:Increment il-il++

• STEP 6:If true increment len-len++.

• STEP 7: Display string length.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


208
Programming Logic and Design Laboratory

PROGRAM:
//pgm to find length without using strlen
#include <stdio.h>
int main()
{
char cstr[10]="ARMY";
int il,len=0;
for(il=0;cstr[il]!='\0';il++)
len++;
printf("LENGTH=%d",len);

return 0;
}

Roll No : 20F110 –BHAVISHYA.S Page 4


209
Programming Logic and Design Laboratory

01 - OUTPUT

RESULT:
Finding length of the word without using strlen has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


210
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 38

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


211
Programming Logic and Design Laboratory

Ex. No : 38 C program merge two words without strcat.

PROBLEM STATEMENT
Write a program merge two words without strcat.
Constraints:

Variable Name Data type

cstr[100]="BANGTAN",cstr1[100]="SONEYODAN”. char

Roll No : 20F110 –BHAVISHYA.S Page 2


212
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare cstr[100]="BANGTAN",cstr1[100]="SONEYODAN”.

• STEP 2: Display combined string cstr, cstr1.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


213
Programming Logic and Design Laboratory

PROGRAM:
//program to concatenate string without using strcat
#include<stdio.h>
#include<string.h>
void main()
{
char cstr[100]="BANGTAN",cstr1[100]="SONEYODAN";
printf(" COMBINED STRING =%s %s ",cstr,cstr1);
}

01 - OUTPUT

RESULT:
Merging two words without strcat has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4


214
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 39

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


215
Programming Logic and Design Laboratory

Ex. No : 39 C program to reverse the string without strrev().

PROBLEM STATEMENT
Write a program to reverse the string without strrev().
Constraints:

Variable Name Data type

a[100]="BUTTER" Char
il int

Roll No : 20F110 –BHAVISHYA.S Page 2


216
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char a[100]="BUTTER".

• STEP 2: Declare int il.

• STEP 3: Using for loop initialize il=strlen(a)-1

• STEP 4: check condition il>=0

• STEP 5 decrement il—

• STEP 6:Display string a.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


217
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
char a[100]="BUTTER";
int il;
for(il=strlen(a)-1;il>=0;il--)
{
printf("%c",a[il]);
}

01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 4


218
Programming Logic and Design Laboratory

RESULT:
Reversing the string without strrev() .

Roll No : 20F110 –BHAVISHYA.S Page 5


219
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 40

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


220
Programming Logic and Design Laboratory

Ex. No : 40 C program to convert the text "karpagam " into upper case

PROBLEM STATEMENT
Write a program to convert the text "karpagam " into upper case
Constraints:

Variable Name Data type

a[100]="karpagam” char
il int

Roll No : 20F110 –BHAVISHYA.S Page 2


221
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char a[100]="karpagam"

• STEP 2: Declare int il.

• STEP 3: In for loop initialize il=0

• STEP 4: check condition a[il]!='\0'

• STEP 5: increment il++

• STEP 6: Display converting to upper case a[il]-32.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


222
Programming Logic and Design Laboratory

PROGRAM:
//program to reverse the string without strrev().
#include<stdio.h>
#include<string.h>
void main()
{
char a[100]="karpagam";
int il;
for(il=0;a[il]!='\0';il++)
{
printf("%c",a[il]-32);
}

}
01 - OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 4


223
Programming Logic and Design Laboratory

RESULT:
Converting the text "karpagam " into upper case has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


224
Programming Logic and Design Laboratory

PROGRAMMING LOGIC AND DESIGN LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 41

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


225
Programming Logic and Design Laboratory

Ex. No : 41 C program to search the character entered by user in the sentence and
count occurrence
of the character.

PROBLEM STATEMENT
Write a program to search the character entered by user in the sentence and count occurrence
of the character.
Constraints:

Variable Name Data type

str[100],c char
icnt=0,il int

Roll No : 20F110 –BHAVISHYA.S Page 2


226
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str[100],c and int icnt=0,il.

• STEP 2: Get string from user- gets(str).

• STEP 3: Get character to be searched from the user- c=getchar().

• STEP 4: Using for loop initialize il=0.

• STEP 5: Check condition str[il]!='\0'.

• STEP 6: Increment -il++.

• STEP 7 : If true , check condition using if-(str[il]==c).

• STEP 8: If true increment icnt-icnt++

• STEP 9: Display character found and count.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


227
Programming Logic and Design Laboratory

PROGRAM:
//pgm to search the character entered by user in the sentence and count occurrence of the
character.
#include <stdio.h>
#include<string.h>
int main()
{
char str[100],c;
int icnt=0,il;
printf("\n ENTER A STRING:");
gets(str);
printf("\n ENTER CHARACTER TO SEARCH:");
c=getchar();
for(il=0;str[il]!='\0';il++)
{
if(str[il]==c)
icnt++;
}
printf("\n Character found , Count: %d",icnt);
return 0;
}

Roll No : 20F110 –BHAVISHYA.S Page 4


228
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Searching the character entered by user in the sentence and count occurrence has been
executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


229
Programming Logic and Design Laboratory

Roll No : 20F110 –BHAVISHYA.S Page 6


230
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 42

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


231
Programming Logic and Design Laboratory

Ex. No : 42 C program to replace the first 4 characters in the string “ADVANCED C


PROGRAMMING” with * without using strnset().

PROBLEM STATEMENT
Write a program to replace the first 4 characters in the string “ADVANCED C
PROGRAMMING” with * without using strnset().
Constraints:

Variable Name Data type

str[100]="ADVANCED C Char
PROGRAMMING”

il
int

Roll No : 20F110 –BHAVISHYA.S Page 2


232
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str[100]="ADVANCED C PROGRAMMING”.

• STEP 2: Declare int il.

• STEP 3: Using for loop, initialize il=0.

• STEP 4: Check condition -il<4.

• STEP 5: Increment -il++.

• STEP 6: If true - str[il]='*'.

• STEP 7: Display String- puts(str);

END

Roll No : 20F110 –BHAVISHYA.S Page 3


233
Programming Logic and Design Laboratory

PROGRAM:
//pgm to replace 1st 4 character as '*'
#include<stdio.h>
void main()
{
char str[100]="ADVANCED C PROGRAMMING”;
int il;
for(il=0;il<4;il++)
{
str[il]='*';
}
puts(str);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


234
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Replacing the first 4 characters in the string “ADVANCED C
PROGRAMMING” with * without using strnset() has been executed successfully,.

Roll No : 20F110 –BHAVISHYA.S Page 5


235
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 43

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


236
Programming Logic and Design Laboratory

Ex. No : 43 C program to print ASCII value along with character in the string.

PROBLEM STATEMENT
Write a program to print ASCII value along with character in the string.
Constraints:

Variable Name Data type

Str[100]=”BTS” Char
il int

Roll No : 20F110 –BHAVISHYA.S Page 2


237
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str[100]="BTS".

• STEP 2: Declare int il.

• STEP 3: Using for loop initialize il=0.

• STEP 4: Check condition -il<strlen(str)

• STEP 5: Increment il- il++.

• STEP 6: Display ASCII value and character using printf.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


238
Programming Logic and Design Laboratory

PROGRAM:

//pgm to print ASCII value along with character in the string


#include<stdio.h>
#include<string.h>
void main()
{
char str[100]="BTS";
int il;
for(il=0;il<strlen(str);il++)
{
printf("\n ASCII: %d CHARACTER: %c",str[il],str[il]);
}
}

Roll No : 20F110 –BHAVISHYA.S Page 4


239
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Printing ASCII value along with character in the string has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


240
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 44

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


241
Programming Logic and Design Laboratory

Ex. No : 44 C program to copy n number of characters from string1 to string2 without


using
strncpy() .

PROBLEM STATEMENT
Write a program to copy n number of characters from string1 to string2 without using
strncpy()
Constraints:

Variable Name Data type

str1[100],str2[100] Char
il,in int

Roll No : 20F110 –BHAVISHYA.S Page 2


242
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str1[100],str2[100].

• STEP 2: Declare il,in.

• STEP 3: Get the string and number of characters from the user.

• STEP 4: Using for loop initialize il=0 .

• STEP 5: Check condition il<in.

• STEP 6: Increment il -il++.

• STEP 7 : If true, initialize- str2[il]=str1[il].

• STEP 8 For string length not = 0 str2[il]='\0’

• STEP 9 : Display string -str2.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


243
Programming Logic and Design Laboratory

PROGRAM:
//to copy n number of characters from string1 to string2 without using strncpy().
#include<stdio.h>
void main()
{
char str1[100],str2[100];
int il,in;
printf("\n ENTER STRING:");
gets(str1);
printf("\n ENTER NO.OF CHARACTERS:");
scanf("%d",&in);
for(il=0;il<in;il++)
{
str2[il]=str1[il];
}
str2[il]='\0';
puts(str2);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


244
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Coping n number of characters from string1 to string2 without using
strncpy() has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


245
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 45

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


246
Programming Logic and Design Laboratory

Ex. No : 45 C program to count number of space, upper case, lower case in the string.

PROBLEM STATEMENT
Write a program to count number of space, upper case, lower case in the string.
Constraints:

Variable Name Data type

str1[100] Char
Il,iu=0,ilow=0,isp=0 int

Roll No : 20F110 –BHAVISHYA.S Page 2


247
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str1[100].

• STEP 2: Declare int il,iu=0,ilow=0,isp=0.

• STEP 3: Get the string from the user.

• STEP 4: Using for loop initialize, check condition and increment il=0; il<strlen(str1);

il++.

• STEP 5: If true using else if, check str1[il]>='A'&& str1[il]<='Z', increment iu++.

• STEP 6: Check str1[il]>='a'&& str1[il]<='z', increemt ilow++.

• STEP 7: Check str1[il]==', increment isp++.

• STEP 8:Display upper case, lower case, space count.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


248
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
char str1[100];
int il,iu=0,ilow=0,isp=0;
printf("\n ENTER STRING:");
gets(str1);
for(il=0;il<strlen(str1);il++)
{
if(str1[il]>='A'&& str1[il]<='Z')
iu++;
else if(str1[il]>='a'&& str1[il]<='z')
ilow++;
else if(str1[il]==' ')
isp++;
}
printf("UPPER: %d\n ",iu);
printf("LOWER:%d \n SPACE: %d ",ilow,isp);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


249
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Counting number of space, upper case, lower case in the string has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


250
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 46

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


251
Programming Logic and Design Laboratory

Ex. No : 46 C program to find the last occurrence of the character ‘o’ in the string
“good morning”.

PROBLEM STATEMENT
Write a program to find the last occurrence of the character ‘o’ in the string “good morning”.
Constraints:

Variable Name Data type

str1=”good morning” char

Roll No : 20F110 –BHAVISHYA.S Page 2


252
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str[100]="good Morning"

• STEP 2: Using strrchr, display last occurance of character o- printf("%s ",strrchr(str,'o')).

END

PROGRAM:
#include<stdio.h>
void main()
{
char str[100]="good Morning";
printf("%s ",strrchr(str,'o'));
}

01 – OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 3


253
Programming Logic and Design Laboratory

RESULT:
Finding the last occurrence of the character ‘o’ in the string “good morning” has been completed
successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4


254
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 47

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


255
Programming Logic and Design Laboratory

Ex. No : 47 C program to convert string “WELCOME TO KCE” into lower case


without using
strlwr()

PROBLEM STATEMENT
Write a program to convert string “WELCOME TO KCE” into lower case without using
strlwr()
Constraints:

Variable Name Data type

str[100]="WELCOME Char
TO KCE".
il
int

Roll No : 20F110 –BHAVISHYA.S Page 2


256
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str[100]="WELCOME TO KCE".

• STEP 2: Declare int il.

• STEP 3: Using for loop initialize, check condition, increment il=0;il<strlen(str);il++.

• STEP 4: Using if Check condition str[il]>='A'&& str[il]<='Z'.

• STEP 5: If true display sing printf -printf("%c",str[il]+32)

END

PROGRAM:
#include<stdio.h>
main()
{
char str[100]="WELCOME TO KCE";
int il;
for(il=0;il<strlen(str);il++)
{
if(str[il]>='A'&& str[il]<='Z')
printf("%c",str[il]+32);
}
}

Roll No : 20F110 –BHAVISHYA.S Page 3


257
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Converting string “WELCOME TO KCE” into lower case without using
strlwr() has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4


258
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 48

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


259
Programming Logic and Design Laboratory

Ex. No : 48 C program to copy first 5 character into another string without using
strncpy().

PROBLEM STATEMENT
Write a program to copy first 5 character into another string without using strncpy().
Constraints:

Variable Name Data type

str1[100]="CHIMCHIM",str2[100] Char
il int

Roll No : 20F110 –BHAVISHYA.S Page 2


260
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str1[100]="CHIMCHIM",str2[100].

• STEP 2: Declare int il.

• STEP 3: Using for loop initialize, check condition, increment -il=0;il<5;il++.

• STEP 4: Initialize str2[il]=str1[il].

• STEP 5: Display string using puts - puts(str2)

END

PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
char str1[100]="CHIMCHIM",str2[100];
int il;
for(il=0;il<5;il++)
{
str2[il]=str1[il];
}
puts(str2);
}

Roll No : 20F110 –BHAVISHYA.S Page 3


261
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Coping first 5 character into another string without using strncpy() has been executed
successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4


262
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 49

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


263
Programming Logic and Design Laboratory

Ex. No : 49 C program to remove the & in the sentence using strtok(). Get string from
user using
gets.

PROBLEM STATEMENT
Write a program to remove the & in the sentence using strtok(). Get string from user using
gets.
Constraints:

Variable Name Data type

str[25] char
* p = strtok(str, "&") char

Roll No : 20F110 –BHAVISHYA.S Page 2


264
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str[25].

• STEP 2: Get string from user using gets( ).

• STEP 3: Using pointer declare char* p = strtok(str, "&").

• STEP 4: In while loop check condition- p != NULL.

• STEP 5: Display string , use strtok()-p = strtok(NULL, "&").

END

Roll No : 20F110 –BHAVISHYA.S Page 3


265
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
#include <string.h>
void main()
{
char str[25];
printf("ENTER STRING:");
gets(str);
char* p = strtok(str, "&");
while (p != NULL)
{
printf("%s\n", p);
p = strtok(NULL, "&");
}

01 – OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 4


266
Programming Logic and Design Laboratory

RESULT:
Removing the & in the sentence using strtok(). Get string from user using
Gets has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


267
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 50

TITLE STRING HANDLING FUNCTION

Roll No : 20F110 –BHAVISHYA.S Page 1


268
Programming Logic and Design Laboratory

Ex. No : 50 C program to compare two strings using strcmp().

PROBLEM STATEMENT
Write a program to compare two strings using strcmp().
Constraints:

Variable Name Data type

str1[25],str2[25] char

Roll No : 20F110 –BHAVISHYA.S Page 2


269
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char str1[25],str2[25]

• STEP 2: Get strings from user using gets().

• STEP 3: Comparing two strings using strcmp()-strcmp(str1,str2).

• STEP 4: Returns 0 if true or integer if false.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


270
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
#include <string.h>
void main()
{
char str1[25],str2[25];
printf("STRING 1:");
gets(str1);
printf("STRING 2:");
gets(str2);
printf(" COMPARING BOTH STRINGS:%d",strcmp(str1,str2));

01 – OUTPUT

RESULT:
Comparing two strings using strcmp() has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4


271
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 51

TITLE STRUCTURE

Roll No : 20F110 –BHAVISHYA.S Page 1


272
Programming Logic and Design Laboratory

Ex. No : 51 C program to create a structure called employee. Initialize and display


employee_id,
dept_id and salary values using structure variable.

PROBLEM STATEMENT
Write a program to create a structure called employee. Initialize and display employee_id,
dept_id and salary values using structure variable.
Constraints:

Variable Name Data type

employee_id[100],dept_id[100] char
salary int

Roll No : 20F110 –BHAVISHYA.S Page 2


273
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Under struct Employee, Declare char employee_id[100],dept_id[100].

• STEP 2: Declare int salary.

• STEP 3: Close the structure and initialize e={"A1M75","IT1001",50000}.

• STEP 4: In the main function using printf display e.employee_id,e.dept_id,e.salary.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


274
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
struct Employee
{
char employee_id[100],dept_id[100];
int salary;
}e={"A1M75","IT1001",50000};
void main()
{
printf("%s %s %d",e.employee_id,e.dept_id,e.salary);
}

01 – OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 4


275
Programming Logic and Design Laboratory

RESULT:
Creation a structure called employee. Initialize and display employee_id,
dept_id and salary values using structure variable has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


276
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 52

TITLE STRUCTURE

Roll No : 20F110 –BHAVISHYA.S Page 1


277
Programming Logic and Design Laboratory

Ex. No : 52 C program to initialize book id, book title, author name, subject using
structure. Use
two structure variables to initialize the values and display the values.

PROBLEM STATEMENT
Write a program to initialize book id, book title, author name, subject using structure. Use
two structure variables to initialize the values and display the values.
Constraints:

Variable Name Data type

bk_id[100], char
ctit[100],cauth[100],sub[100]

Roll No : 20F110 –BHAVISHYA.S Page 2


278
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: In structure Book , declare char bk_id[100],ctit[100],cauth[100],sub[100].

• STEP 2: Closing structure initialize

b={"AR22LB","AVENGERS","STALIN","LITERATURE"}.

• STEP 3: Inside main function using printf display b.bk_id,b.ctit,b.cauth,b.sub.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


279
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
struct Book
{
char bk_id[100],ctit[100],cauth[100],sub[100];
}b={"AR22LB","AVENGERS","STALIN","LITERATURE"};
void main()
{
printf("\n %s %s %s %s",b.bk_id,b.ctit,b.cauth,b.sub);
}

01 – OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 4


280
Programming Logic and Design Laboratory

RESULT:
Initializing book id, book title, author name, subject using structure. Use
two structure variables to initialize the values and display the values has been executed .

Roll No : 20F110 –BHAVISHYA.S Page 5


281
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 53

TITLE STRUCTURE

Roll No : 20F110 –BHAVISHYA.S Page 1


282
Programming Logic and Design Laboratory

Ex. No : 53 C program to find the size of a structure variable without structure


padding using #
pragma pack (1).

PROBLEM STATEMENT
Write a program to find the size of a structure variable without structure padding using #
pragma pack (1)
Constraints:

Variable Name Data type

bk_id[100],ctit[100],cauth[100],sub[100] char

Roll No : 20F110 –BHAVISHYA.S Page 2


283
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Instructure Book , declarechar bk_id[100],ctit[100],cauth[100],sub[100].


• STEP 2: Closing structure initialize
b={"AR22LB","AVENGERS","STALIN","LITERATURE"}.
• STEP 3: In the main function using printf display size- sizeof(b).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


284
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
struct Book
{
char bk_id[100],ctit[100],cauth[100],sub[100];
}b={"AR22LB","AVENGERS","STALIN","LITERATURE",};
void main()
{
printf("%d",sizeof(b));
}

01 – OUTPUT

RESULT:
Finding the size of a structure variable without structure padding using #
pragma pack (1) has been executed.

Roll No : 20F110 –BHAVISHYA.S Page 4


285
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 54

TITLE STRUCTURE

Roll No : 20F110 –BHAVISHYA.S Page 1


286
Programming Logic and Design Laboratory

Ex. No : 54 C program to read and print the driving licence details of a person which
includes driving license number, name, address, date_of_birth valid date
using typedef in structure.

PROBLEM STATEMENT
Write a program to read and print the driving licence details of a person which includes
driving license number, name, address, date_of_birth valid date using typedef in structure.
Constraints:

Variable Name Data type

dnum,ival int
name[50],add[100],idob[50]
char

Roll No : 20F110 –BHAVISHYA.S Page 2


287
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: In struct Details declare int dnum,ival.


• STEP 2: Declare char name[50],add[100],idob[50].
• STEP 3: In the main function declare typedef struct Details det.

• STEP 4: Declare det D.

• STEP 5: Using string function initialize name,add,idob- strcpy(D.name,"BHAVISHYA")

• STEP 6:Initialize dnum, ival - D.dnum=13101995, D.ival=2030.

• STEP 7: Print all the details.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


288
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
#include<string.h>
struct Details
{
int dnum,ival;
char name[50],add[100],idob[50];
};
void main()
{
typedef struct Details det;
det D;
strcpy(D.name,"BHAVISHYA");
strcpy(D.add,"Kangnam,Kstar rd, South Korea");
D.dnum=13101995;
strcpy(D.idob,"7 DECEMBER 2002");
D.ival=2030;
printf("\n %d %d %s %s %s", D.dnum, D.ival,D.name,D.add,D.idob);
}

01 – OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 4


289
Programming Logic and Design Laboratory

RESULT:
Reading and print the driving licence details of a person which includes
driving license number, name, address, date_of_birth valid date using typedef in structure has
been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


290
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 55

TITLE STRUCTURE

Roll No : 20F110 –BHAVISHYA.S Page 1


291
Programming Logic and Design Laboratory

Ex. No : 55 C program for displaying the age, name, salary and voter Id of a person
by creating a
structure and passing it to a function.

PROBLEM STATEMENT
Write a program for displaying the age, name, salary and voter Id of a person by creating a
structure and passing it to a function.
Constraints:

Variable Name Data type

name[50],bias[100] Char
toc
int

Roll No : 20F110 –BHAVISHYA.S Page 2


292
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Create structure Army and declare char name[50],bias[100].


• STEP 2: Declare int toc.
• STEP 3: Function prototype- void disp(struct Army b).

• STEP 4: In the main function initialize struct Army a={"BHAVISHYA","PARK

JIMIN",13101995}.

• STEP 5: Pass the structure into function- disp(a).

• STEP 6: In the function disp, display contents- b.name,b.bias,b.tocken using printf.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


293
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
struct Army
{
char name[50],bias[100];
int toc;
};

void disp(struct Army b);

int main()
{
struct Army a={"BHAVISHYA","PARK JIMIN",13101995} ;
disp(a);
return 0;
}

void disp(struct Army b)


{
printf("\n INFORMATION :\n");
printf("\n NAME: %s", b.name);
printf("\n TOCKEN:: %d", b.toc);
printf("\nBIAS: %s", b.bias);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


294
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Displaying the age, name, salary and voter Id of a person by creating a
structure and passing it to a function has been executed.

Roll No : 20F110 –BHAVISHYA.S Page 5


295
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 56

TITLE STRUCTURE

Roll No : 20F110 –BHAVISHYA.S Page 1


296
Programming Logic and Design Laboratory

Ex. No : 56 C program to create a structure student to store the details of 10


students of a class and display it. Implement using array of structures.

PROBLEM STATEMENT
Write a program to create a structure student to store the details of 10 students of a class and
display it. Implement using array of structures.
Constraints:

Variable Name Data type

roll int
marks
float

Roll No : 20F110 –BHAVISHYA.S Page 2


297
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: In struct student declare int roll and float marks;

• STEP 2: In the main function , get the information from the user -s[i].roll,s[i].marks
using for loop.
• STEP 3: In the for loop initialize,compare,increment- i = 0; i < 10;i++.

• STEP 4: Display the details using for loop of same conditions .

END

Roll No : 20F110 –BHAVISHYA.S Page 3


298
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
struct student
{
int roll;
float marks;
} s[10];

int main() {
int i;
printf("ENTER INFORMATION:\n");
for (i = 0; i < 10;i++)
{
s[i].roll = i + 1;
printf("\n ENTER ROLL NUMBER :");
scanf("%d",&s[i].roll);
printf("ENTER MARKS: ");
scanf("%f", &s[i].marks);
}
printf("\n STUDENT DETAILS:");
for (i = 0; i < 10;i++)
{
printf("\nROLL NUMBER: %d\n", i + 1);
printf("MARKS: %.1f", s[i].marks);
printf("\n");
}
return 0;

Roll No : 20F110 –BHAVISHYA.S Page 4


299
Programming Logic and Design Laboratory

01 – OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 5


300
Programming Logic and Design Laboratory

RESULT:
Creating a structure student to store the details of 10 students of a class and
display it. Implement using array of structures has been executed .

Roll No : 20F110 –BHAVISHYA.S Page 6


301
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 56

TITLE STRUCTURE

Roll No : 20F110 –BHAVISHYA.S Page 1


302
Programming Logic and Design Laboratory

Ex. No : 56 C program to find the size of the memory allocated for the union.

PROBLEM STATEMENT
Write a program to find the size of the memory allocated for the union.
Constraints:

Variable Name Data type

idol[50],role[50] char
score
int

Roll No : 20F110 –BHAVISHYA.S Page 2


303
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Create union Jinhit

• STEP 2: In the union declare char idol[50],role[50].


• STEP 3: Declare int score.

• STEP 4: Create structure variable J.

• STEP 5: Using printf display sizeof union Jinhit- sizeof(J).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


304
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
union Jinhit
{
char idol[50],role[50];
int score;
}J;
void main()
{
printf("%d",sizeof(J));
}

01 – OUTPUT

RESULT:
Finding the size of the memory allocated for the union has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4


305
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 58

TITLE STRUCTURE

Roll No : 20F110 –BHAVISHYA.S Page 1


306
Programming Logic and Design Laboratory

Ex. No : 58 C program to read and display the name, age and salary of the employee
using union.

PROBLEM STATEMENT
Write a program to read and display the name, age and salary of the employee using union.
Constraints:

Variable Name Data type

name[100] char
iage
int
isal
float

Roll No : 20F110 –BHAVISHYA.S Page 2


307
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: In union Employee declare char name[100].

• STEP 2: Declare int iage, float isal and close union.


• STEP 3: In the main function declare int age, float salary.

• STEP 4: By using scanf get the elements from the user-e.name,e.age,e.isal.

• STEP 5:Display the constraints using printf.- e.name,e.age,e.isal..

END

Roll No : 20F110 –BHAVISHYA.S Page 3


308
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
union employee
{
char name[100];
int iage;
float isal;
}e;

void main()
{
int age;
float salary;
printf("Enter name : ");
scanf("%s",e.name);
printf("Enter age : ");
scanf("%d",&age);
printf("Enter salary : ");
scanf("%f",&salary);
printf("\n\nEmployee name : %s",e.name);
e.iage=age;
printf("\n\nEmployee age : %d",e.iage);
e.isal=salary;
printf("\n\nEmployee salary : %.2f",e.isal);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


309
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Reading and displaying the name, age and salary of the employee using union has been executed
successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


310
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 59

TITLE STRUCTURE

Roll No : 20F110 –BHAVISHYA.S Page 1


311
Programming Logic and Design Laboratory

Ex. No : 59 C program to display the month of a year and its corresponding value
using the enumeration data type.

PROBLEM STATEMENT
Write a program to display the month of a year and its corresponding value using the
enumeration data type.
Constraints:

Variable Name Data type

il int

Roll No : 20F110 –BHAVISHYA.S Page 2


312
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int il in main function

• STEP 2: Under enum year -declare enum


year{January,February,March,April,May,Jun,July,August,September,October,November,
December}.
• STEP 3: Using for loop initialize, compare, increment- il=0;il<12;il++.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


313
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
int main()
{ int il;

enumyear{January,February,March,April,May,Jun,July,August,September,October,November,De
cember};
for(il=0;il<12;il++)
printf(" %d ",il);

01 – OUTPUT

RESULT:
Displaying the month of a year and its corresponding value using the
enumeration data type has been executed.

Roll No : 20F110 –BHAVISHYA.S Page 4


314
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 60

TITLE STRUCTURE

Roll No : 20F110 –BHAVISHYA.S Page 1


315
Programming Logic and Design Laboratory

Ex. No: 60 C program to create a structure time with hour, minutes and seconds as its
members. Use bitfields inside the structure, initialize the values for hour,
minutes and seconds and
display it.

PROBLEM STATEMENT
Write a program to create a structure time with hour, minutes and seconds as its members.
Use bitfields inside the structure, initialize the values for hour, minutes and seconds and
display it.
Constraints:

Variable Name Data type

hour, minute, seconds int

Roll No : 20F110 –BHAVISHYA.S Page 2


316
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Under structure time declare int hour, int time, int seconds.

• STEP 2: Closing structure initialize t={7,12,02}.


• STEP 3:Using printf display t.hour,t,minute,t.seconds.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


317
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
struct Time
{
int hour;
int minute;
int second;
}t={7,12,02};
int main()
{

printf("%d:%d:%d",t.hour,t.minute,t.second);
}

01 – OUTPUT

RESULT:
Creating a structure time with hour, minutes and seconds as its members.
Use bitfields inside the structure, initialize the values for hour, minutes and seconds and
display it has been executed.

Roll No : 20F110 –BHAVISHYA.S Page 4


318
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 61

TITLE DYNAMIC MEMORY ALLOCATION

Roll No : 20F110 –BHAVISHYA.S Page 1


319
Programming Logic and Design Laboratory

Ex. No : 61 C program to find area of circle using malloc().

PROBLEM STATEMENT
Write a program to find area of circle using malloc().
Constraints:

Variable Name Data type

float*a float

Roll No : 20F110 –BHAVISHYA.S Page 2


320
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare float*a.

• STEP 2: Initialize a using malloc- a=malloc(7)

• STEP 3: Get the radius from the user using scanf.

• STEP 4: Print area using printf-3.14**a**a.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


321
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void main()
{
float*a;
a=malloc(7);
printf("\n ENTER RADIUS :");
scanf("%f",a);
printf("%f",3.14**a**a);
}

01 – OUTPUT

RESULT:
Finding area using malloc has been successfully executed.

Roll No : 20F110 –BHAVISHYA.S Page 4


322
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 62

TITLE DYNAMIC MEMORY ALLOCATION

Roll No : 20F110 –BHAVISHYA.S Page 1


323
Programming Logic and Design Laboratory

Ex. No : 62 C program to read 5 integer values from the user and print the integer.
Allocate the memory using calloc().

PROBLEM STATEMENT
Write a c program to read 5 integer values from the user and print the integer. Allocate the
memory using calloc().
Constraints:

Variable Name Data type

int *a,il int

Roll No : 20F110 –BHAVISHYA.S Page 2


324
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int *a,il.

• STEP 2: Initialize a=calloc(7,22).

• STEP 3: Using for loop get the array elements from the user , initialize,compare and

increment il- il=0;il<5;il++.

• STEP 4: Print the array elements-*(a+il)).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


325
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void main()
{
int *a,il;
a=calloc(7,22);
printf("\n ENTER ARRAY ELEMENTS:");
for(il=0;il<5;il++)
{
scanf("%d",&a[il]);
printf("%d \t ",*(a+il));
}
}
01 – OUTPUT

RESULT:
Read 5 integer values from the user and print the integer. Allocate the memory using calloc().

Roll No : 20F110 –BHAVISHYA.S Page 4


326
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 63

TITLE DYNAMIC MEMORY ALLOCATION

Roll No : 20F110 –BHAVISHYA.S Page 1


327
Programming Logic and Design Laboratory

Ex. No : 63 C program to store the string in a block of memory space created by


malloc() and then modify the same to store the largest string using
realloc().

PROBLEM STATEMENT
Write a program to store the string in a block of memory space created by malloc() and then
modify the same to store the largest string using realloc().
Constraints:

Variable Name Data type

char *a char

Roll No : 20F110 –BHAVISHYA.S Page 2


328
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare char *a.

• STEP 2: Using DMA, allocate a=malloc(20).

• STEP 3: Using scanf get the string from user.

• STEP 4: Using realloc()- reallocate the string - a=realloc(a,95).

• STEP 5: After reallocation , display string using printf-a.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


329
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
char *a;
a=malloc(20);
printf("\n BEFORE REALLOCATION:");
printf("\n ENTER STRING:");
scanf("%s",a);
printf("\n STRING:");
a=realloc(a,95);
printf("\n AFTER REALLOCATION:");
scanf("%s",a);
printf("\n STRING AFTER REALLOCATION: %s",a);
}
01 – OUTPUT

RESULT:
Storing the string in a block of memory space created by malloc() and then
modify the same to store the largest string using realloc() has been completed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4


330
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 64

TITLE DYNAMIC MEMORY ALLOCATION

Roll No : 20F110 –BHAVISHYA.S Page 1


331
Programming Logic and Design Laboratory

Ex. No : 64 C program to read an integer from the user by allocating the memory
dynamically and then print the value, release the memory using free().

PROBLEM STATEMENT
Write a c program to read an integer from the user by allocating the memory dynamically
and then print the value, release the memory using free().
Constraints:

Variable Name Data type

*a int

Roll No : 20F110 –BHAVISHYA.S Page 2


332
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int *a.

• STEP 2: Using DMA allocate - a=malloc(13).

• STEP 3: Get the number from the user using scanf.

• STEP 4: Display the number using printf-*a

• STEP 5: Deallocate memory- free(a).


END

Roll No : 20F110 –BHAVISHYA.S Page 3


333
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void main()
{
int *a;
a=malloc(13);
printf("\n ENTER A NUMBER:");
scanf("%d",a);
printf("\n ENTERED NUMBER IS: %d",*a);
free(a);
}
01 – OUTPUT

RESULT:
Reading an integer from the user by allocating the memory dynamically
and then print the value, release the memory using free() has been executed.

Roll No : 20F110 –BHAVISHYA.S Page 4


334
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 65

TITLE DYNAMIC MEMORY ALLOCATION

Roll No : 20F110 –BHAVISHYA.S Page 1


335
Programming Logic and Design Laboratory

Ex. No : 65 C program to read an array of 5 elements and find the largest element in it
using Dynamic Memory Allocation.

PROBLEM STATEMENT
Write a c program to read an array of 5 elements and find the largest element in it using
Dynamic Memory Allocation.
Constraints:

Variable Name Data type

*a,il,ilarge int

Roll No : 20F110 –BHAVISHYA.S Page 2


336
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare *a,il,ilarge,

• STEP 2: Reallocate memory using malloc- a=malloc(20).

• STEP 3: Using for loop initialize, compare, increment- il : il=0;il<5; il++.

• STEP 4: Get array elements using scanf.

• STEP 5: Using for loop initialize, compare, increment- il : il=0;il<5; il++, check
condition- if(*(a+il)>ilarge),ilarge=*(a+il).

• STEP 6: Display largest number- ilarge.


END

Roll No : 20F110 –BHAVISHYA.S Page 3


337
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void main()
{
int *a,il,ilarge;
printf( "ENTER ELEMENTS:" ) ;
a=malloc(20) ;
for(il=0;il<5; il++)
{
scanf("%d",(a+il)) ;
}
ilarge=*a;
for(il=0;il<5;il++)
{
if(*(a+il)>ilarge)
ilarge=*(a+il) ;
}
printf(" LARGEST NUMBER IS : %d",ilarge) ;
}

01 – OUTPUT

Roll No : 20F110 –BHAVISHYA.S Page 4


338
Programming Logic and Design Laboratory

RESULT:
Reading an array of 5 elements and find the largest element in it using
Dynamic Memory Allocation has been executed.

Roll No : 20F110 –BHAVISHYA.S Page 5


339
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 66

TITLE FUNCTION POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


340
Programming Logic and Design Laboratory

Ex. No : 66 C program to multiply two numbers using function pointer.

PROBLEM STATEMENT
Write a c program to multiply two numbers using function pointer.
Constraints:

Variable Name Data type

void(*p)()=mul; void

Roll No : 20F110 –BHAVISHYA.S Page 2


341
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare function prototype void mul().

• STEP 2: Under main, declare void(*p)()=mul; (*p)();

• STEP 3: In mul(), declare int a,b.

• STEP 4: Get numbers from user-a,b.

• STEP 5: Display-a*b

END

Roll No : 20F110 –BHAVISHYA.S Page 3


342
Programming Logic and Design Laboratory

PROGRAM:
//pgm to multiply 2 num using fnptr
#include<stdio.h>
void mul();
void main()
{
void(*p)()=mul;
(*p)();
}
void mul()
{
int a,b;
printf("\n ENTER NUMBERS:");
scanf("%d %d",&a,&b);
printf("%d",a*b);
}

01 – OUTPUT

RESULT:
Multiplying two numbers using function pointer has been executed.

Roll No : 20F110 –BHAVISHYA.S Page 4


343
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 67

TITLE FUNCTION POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


344
Programming Logic and Design Laboratory

Ex. No : 67 C program to add three numbers using call by reference.

PROBLEM STATEMENT
Write a program to add three numbers using call by reference.
Constraints:

Variable Name Data type

a=33,b=56,c=17 int
sum
int

Roll No : 20F110 –BHAVISHYA.S Page 2


345
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare function prototype int add(int*a,int*b,int*c);

• STEP 2: Under main declare, int a=33,b=56,c=17.

• STEP 3: Display sum , calling function add passing a,b,c by reference add(&a,&b,&c).

• STEP 4: Under function add declare int sum, initialize: sum=*a+*b+*c.

• STEP 5:Return sum.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


346
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
int add(int*a,int*b,int*c);
void main()
{
int a=33,b=56,c=17;
printf("\n SUM: %d",add(&a,&b,&c));
}
int add(int*a,int *b, int*c)
{
int sum;
sum=*a+*b+*c;
return sum;
}

01 – OUTPUT

RESULT:
Adding three numbers using call by reference has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4


347
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 68

TITLE FUNCTION POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


348
Programming Logic and Design Laboratory

Ex. No : 68 C program to copy one string to another string by passing string to


function.

PROBLEM STATEMENT
Write a program to copy one string to another string by passing string to function.
Constraints:

Variable Name Data type

str1[100],str2[100] char

Roll No : 20F110 –BHAVISHYA.S Page 2


349
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Initialize function prototype void stringcopy(char*, char*).

• STEP 2: In main declare char str1[100],str2[100].


• STEP 3: Get – str1.

• STEP 4: Copy str1,str2- stringcopy(str1,str2).

• STEP 5: Display copied string-str2.

• STEP 6 : Under stringcopy – check while(*str1).

• STEP 7 : If satisfies *str2 = *str1,str1++,str2++.

• STEP 8: *str2= '\0'.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


350
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
void stringcopy(char*, char*);
int main()
{
char str1[100],str2[100];
printf("\n ENTER STRING:");
gets(str1);
stringcopy(str1,str2);
printf("\n COPIED STRING : %s",str2);
return 0;
}

void stringcopy(char *str1, char *str2)


{
while(*str1!=’\0’)
{
*str2 = *str1;
str1++;
str2++;
}
*str2= '\0';
}

Roll No : 20F110 –BHAVISHYA.S Page 4


351
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Coping one string to another string by passing string to function has been executed.

Roll No : 20F110 –BHAVISHYA.S Page 5


352
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex: No : 69

TITLE FUNCTION POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


353
Programming Logic and Design Laboratory

Ex. No: 69 C program to find the factorial of a given number using function pointer.

PROBLEM STATEMENT
Write a c program to find the factorial of a given number using function pointer.
Constraints:

Variable Name Data type

no int
i,f=1
int

Roll No : 20F110 –BHAVISHYA.S Page 2


354
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Function prototype: void fact(int).

• STEP 2: In the main function declare int no.


• STEP 3: Get the number from the user-no

• STEP 4: Using file pointer: void (*fun_ptr)(int) = &fact;

• STEP 5:Invoking fact()-(*fun_ptr)(no).

• STEP 6:passing (no) in fact- in fact()-declare int i,f=1.

• STEP 7: Using for loop: declare ,compare, increment i- i=1;i<=no;i++.

• STEP 8: If true, f=f*i.

• STEP 9: Display factorial in main function.


END

Roll No : 20F110 –BHAVISHYA.S Page 3


355
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
void fact(int);

void main()
{
int no;

printf("ENTER A NUMBER: \n");


scanf("%d",&no);
void (*fun_ptr)(int) = &fact;
(*fun_ptr)(no);

void fact(int no)


{
int i,f=1;
for(i=1;i<=no;i++)
{
f=f*i;
}
printf("FACTORIAL OF (%d) = %d\n",no,f);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


356
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Finding the factorial of a given number using function pointer has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


357
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex: No : 70

TITLE FUNCTION POINTER

Roll No : 20F110 –BHAVISHYA.S Page 1


358
Programming Logic and Design Laboratory

Ex. No: 70 C program to pass a structure to function.

PROBLEM STATEMENT
Write a c program to pass a structure to function.
Constraints:

Variable Name Data type

roll Int
name[100]
Char
per float

Roll No : 20F110 –BHAVISHYA.S Page 2


359
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: In struct student declare int roll,char name[100],float per.

• STEP 2: Function prototype void func(struct student st).

• STEP 3: In the main function, create structure element struct student st.

• STEP 4: Initialize st.roll=110, strcpy(st.name,"BHAVISHYA"), st.per =99.9,invoke

function- func(st).

• STEP 5: In the function func, passing structure func(struct student st).

• STEP 6: Display rollnumber, name and percentage - st.roll, st.name, st.per.

END

Roll No : 20F110 –BHAVISHYA.S Page 3


360
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
#include <string.h>
struct student
{
int roll;
char name[100];
float per;
};
void func(struct student st);
int main()
{
struct student st;
st.roll=110;
strcpy(st.name,"BHAVISHYA");
st.per =99.9;
func(st);
return 0;
}

void func(struct student st)


{
printf("\n ROLL NUMBER: %d", st.roll);
printf("\n NAME: %s", st.name);
printf("\n RESULT: %f", st.per);
}

Roll No : 20F110 –BHAVISHYA.S Page 4


361
Programming Logic and Design Laboratory

01 – OUTPUT

RESULT:
Passing a structure to function has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 5


362
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 71

TITLE FILES

Roll No : 20F110 –BHAVISHYA.S Page 1


363
Programming Logic and Design Laboratory

Ex. No : 71 C program to read two integers from the user and write the sum into file.

PROBLEM STATEMENT
Write a c program to read two integers from the user and write the sum into file.
Constraints:

Variable Name Data type

a,b int

Roll No : 20F110 –BHAVISHYA.S Page 2


364
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Declare int a,b.

• STEP 2: Create and open file” sum.txt”- FILE *p=fopen("sum.txt","w").


• STEP 3: Get a and b.

• STEP 4: Display- fprintf(p,"%d" ,a+b).

• STEP 5: Close file-fclose(fp).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


365
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
void main()
{
int a,b;
FILE *p=fopen("sum.txt","w");
scanf("%d %d",&a,&b);
fprintf(p,"%d",a+b);
fclose(p);
}

01 – OUTPUT

RESULT:
Reading two integers from the user and write the sum into file has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4


366
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 72

TITLE FILES

Roll No : 20F110 –BHAVISHYA.S Page 1


367
Programming Logic and Design Laboratory

Ex. No : 72 C program to illustrate the use of fseek()

PROBLEM STATEMENT
Write a c program to illustrate the use of fseek()
Constraints:

Variable Name Data type

FILE *fp FILE POINTER

Roll No : 20F110 –BHAVISHYA.S Page 2


368
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Create file pointer : FILE *fp.

• STEP 2: Open file fp = fopen("file.txt","w+").

• STEP 3: Using printf display illustrstion of fseek()-illustrating Fseek().

• STEP 4: Display moving file pointer, fp.

• STEP 5:Close file-fclose(fp).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


369
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
int main () {
FILE *fp;
fp = fopen("file.txt","w+");
fputs("ILLUSTRATION OF fseek()",fp);
fseek( fp,7,SEEK_SET );
fputs("MOVING FILE POINTER POSITION",fp);
fclose(fp);
return(0);
}

01 – OUTPUT

RESULT:
Illustrationof the use of fseek() has been executed.

Roll No : 20F110 –BHAVISHYA.S Page 4


370
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 73

TITLE FILES

Roll No : 20F110 –BHAVISHYA.S Page 1


371
Programming Logic and Design Laboratory

Ex. No : 73 C program to write some content into file. Read the file content and display
the data into terminal. (note use the w+ mode ).

PROBLEM STATEMENT
Write a c program to write some content into file. Read the file content and display the data
into terminal. (note use the w+ mode ).
Constraints:

Variable Name Data type

final int

Roll No : 20F110 –BHAVISHYA.S Page 2


372
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Create file pointer -FILE *fp.

• STEP 2: Declare int final.


• STEP 3: Open file- fp = fopen("file.txt","w+").

• STEP 4: fprintf(fp,"%d","7"),rewind file pointer-rewind(fp).

• STEP 5: fscanf(fp,"%d",&final).

• STEP 6:Display final-fp.

• STEP 7:Close file -fclose(fp).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


373
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
void main ()
{
FILE *fp;
int final;
fp = fopen("file.txt","w+");
fprintf(fp,"%d","7");
rewind(fp);
fscanf(fp,"%d",&final);
printf("%d",final);
fclose(fp);
}
01 – OUTPUT

RESULT:
Writing some content into file. Read the file content and display the data
into terminal. (note use the w+ mode ) has been executed.

Roll No : 20F110 –BHAVISHYA.S Page 4


374
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 74

TITLE FILES

Roll No : 20F110 –BHAVISHYA.S Page 1


375
Programming Logic and Design Laboratory

Ex. No : 74 C program to print the source code of your program.

PROBLEM STATEMENT
Write a program to print the source code of your program.
Constraints:

Variable Name Data type

ch char

Roll No : 20F110 –BHAVISHYA.S Page 2


376
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: In main function create file pointer fp- FILE *fp.

• STEP 2: Declare char ch.


• STEP 3: Open main file fp = fopen("main.c","r").

• STEP 4: In while loop,check - ch=fgetc(fp))!=EOF.

• STEP 5: If satisfies display - putchar(ch).

• STEP 6: Close file-fclose(fp).

END

Roll No : 20F110 –BHAVISHYA.S Page 3


377
Programming Logic and Design Laboratory

PROGRAM:
#include <stdio.h>
void main ()
{
FILE *fp;
char ch;
fp = fopen("main.c","r");
while((ch=fgetc(fp))!=EOF)
{
putchar(ch);
}
fclose(fp);
}
01 – OUTPUT

RESULT:
Printing the source code of your program has been executed successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4


378
Programming Logic and Design Laboratory

ADVANCED C PROGRAMMING LABORATORY

CODE BOOK

NAME BHAVISHYA.S

ROLL NUMBER 20F110

DEPARTMENT INFORMATION TECHNOLOGY

SECTION “A”

Ex : No : 75

TITLE FILES

Roll No : 20F110 –BHAVISHYA.S Page 1


379
Programming Logic and Design Laboratory

Ex. No : 75 C program to perform addition of three numbers using command line


arguments.

PROBLEM STATEMENT
Write a program to perform addition of three numbers using command line arguments.
Constraints:

Variable Name Data type

i,sum=0 int

Roll No : 20F110 –BHAVISHYA.S Page 2


380
Programming Logic and Design Laboratory

SOLUTION

AIGORITHM

BEGIN

• STEP 1: Pass command line arguiments-argc,argv[] in main - int main(int argc,char


*argv[]).

• STEP 2: Declare int i,sum=0.


• STEP 3: Using for loop initialize, compare increment i- i=1;i<argc;i++.

• STEP 4: Initialize sum=sum+atoi(argv[i]).

• STEP 5: Display sum.


END

Roll No : 20F110 –BHAVISHYA.S Page 3


381
Programming Logic and Design Laboratory

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
int i,sum=0;

for(i=1;i<argc;i++)
{
sum=sum+atoi(argv[i]);
}
printf("SUM:%d", sum);

01 – OUTPUT

RESULT:
Performing addition of three numbers using command line arguments has been executed
successfully.

Roll No : 20F110 –BHAVISHYA.S Page 4

You might also like