Professional Documents
Culture Documents
LABORATORY RECORD
NAME BHAVISHYA.S
SECTION A
INDEX
13 9-4-2021 73 To read and print 2*2 matrix using pointer and array.
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
23-4-2021 148 Read 3*3 matrix and print transpose of matrix using
26
pointer to an array.
40 7-5-2021 219 To convert the text "karpagam " into upper case
43 19-6-2021 235 To print ASCII value along with character in the string.
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 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.
26-6-2021 322 To read 5 integer values from the user and print the
62
integer. Allocate the memory using calloc().
To read two integers from the user and write the sum
71 29-6-2021 362
into file.
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 ).
CODE BOOK
NAME BHAVISHYA.S
SECTION A
Ex : No : 01
TITLE POINTER
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:
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.
END
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;
}
01 - OUTPUT
RESULT:
Program to read the value of integer and print the value as well as address using
Pointer has been completed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION A
Ex : No : 02
TITLE POINTER
PROBLEM STATEMENT
Constraints:
fp,ft,fr,fpt1,fpt2,fpt3 float
SOLUTION
AIGORITHM
BEGIN
END
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;
}
01 - OUTPUT
RESULT:
CODE BOOK
NAME BHAVISHYA.S
SECTION A
Ex : No : 03
TITLE POINTER
PROBLEM STATEMENT
Constraints:
ir,*ip=*&ir int
SOLUTION
AIGORITHM
BEGIN
END
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;
}
01 - OUTPUT
RESULT:
CODE BOOK
NAME BHAVISHYA
SECTION A
Ex : No : 04
TITLE POINTER
PROBLEM STATEMENT
Constraints:
Ia=7,ib=9,ic=8,*pt1=&ia,*pt2=&ib,*pt3=&ic int
SOLUTION
AIGORITHM
BEGIN
END
PROGRAM:
#include <stdio.h>
int main()
{
float ia=7,ib=9,ic=8;
float *pt1=&ia,*pt2=&ib,*pt3=⁣
printf(" PRODUCT IS:%f ",*pt1 * *pt2 * *pt3);
return 0;
}
01 - OUTPUT
RESULT:
The C Program is executed successfully to perform multiplication of three float numbers using
pointer
CODE BOOK
NAME BHAVISHYA.S
SECTION A
Ex : No : 05
TITLE POINTER
PROBLEM STATEMENT
Constraints:
Il,ib Int
*vt1=&il,*vt2=&ib Void.
SOLUTION
AIGORITHM
BEGIN
END
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;
}
01 - OUTPUT
RESULT:
The C Program is executed successfully to find area of rectangle using void pointer
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 6
TITLE POINTER
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:
Iyear int
*ipt=&iyear void
SOLUTION
AIGORITHM
BEGIN
• STEP 5:If true, display is a Leap year , else print is not a Leap year
END
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);
01 - OUTPUT
02 - OUTPUT
RESULT:
C program to check whether the number is leap year or not using void pointer has been
completed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 7
TITLE POINTER
PROBLEM STATEMENT
Write a program to find cube of an number using void pointer.
Constraints:
inum int
*ipt=&inum void
SOLUTION
AIGORITHM
BEGIN
END
PROGRAM:
01 - OUTPUT
02 - OUTPUT
RESULT:
Program to find cube of an number using void pointer has been completed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 8
TITLE POINTER
PROBLEM STATEMENT
Write a program to find square of number using pointer.
Constraints:
inum,*ipt=&inum int
SOLUTION
AIGORITHM
BEGIN
END
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);
}
01 - OUTPUT
02 - OUTPUT
RESULT:
C program to find square of number using pointer has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 9
TITLE POINTER
PROBLEM STATEMENT
Write a program swap two numbers using pointer.
Constraints:
ia=6,ib=10,ic,*ipt1=&ia,*ipt2=&ib,*ipt3=&ic int
SOLUTION
AIGORITHM
BEGIN
• STEP 3:Initialize
*ipt3=*ipt1;
*ipt1=*ipt2;
*ipt2=*ipt3;
END
PROGRAM:
//pgm to swap two numbers using pointer
#include<stdio.h>
void main()
{
int ia=6,ib=10,ic,*ipt1=&ia,*ipt2=&ib,*ipt3=⁣
printf("\n NUMBERS BEFORE SWAPPING: %u %u",*ipt1,*ipt2);
*ipt3=*ipt1;
*ipt1=*ipt2;
*ipt2=*ipt3;
printf("\n SWAPPED NUMBERS: %u %u",*ipt1,*ipt2);
}
01 - OUTPUT
RESULT:
Swapping two numbers using pointer has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 10
TITLE POINTER
PROBLEM STATEMENT
Write a program to find area of circle using generic pointer.
Constraints:
ir=22 int
*vpt=&ir. void
SOLUTION
AIGORITHM
BEGIN
END
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;
}
01 – OUTPUT
RESULT:
Finding area of circle using generic pointer has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 11
PROBLEM STATEMENT
Write a program swap two numbers using pointer to pointer.
Constraints:
ia=7,ib=9,ic
*ip1=&ia,*ip2=&ib,*ip3=&ic int
**ipp1=&ip1,**ipp2=&ip2,**ipp3=&ip3
SOLUTION
AIGORITHM
BEGIN
• STEP 5:Initialize:
**ipp3=**ipp1;
**ipp1=**ipp2;
**ipp2=**ipp3;
END
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=⁣
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;
}
01 - OUTPUT
RESULT:
Swapping two numbers using pointer to pointer has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 12
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:
ain[5],il int
SOLUTION
AIGORITHM
BEGIN
END
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;
}
01 - OUTPUT
02 - OUTPUT
RESULT:
Reading array of 5 numbers and printing the numbers using pointer and array has been executed
successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 13
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:
ain[2][2]={12,23,45,66},ir,ic int
SOLUTION
AIGORITHM
BEGIN
END
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");
}
01 - OUTPUT
RESULT:
Reading and printing 2*2 matrix using pointer and array has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 14
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:
ain[5]={1,2,3,4,5},il. int
int *aip[5] int
SOLUTION
AIGORITHM
BEGIN
END
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]);
}
}
01 - OUTPUT
RESULT:
Printing address of array elements using array of pointer has been executed successfully
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 15
PROBLEM STATEMENT
Write a program to find volume of cylinder using pointer to pointer.
Constraints:
ir,ih,*ip1=&ir,*ip2=&ih int
**ipp1=&ip1,**ipp2=&ip2 int
SOLUTION
AIGORITHM
BEGIN
• STEP 3: Get the radius and height from the user – ir,ih.
END
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);
}
01 - OUTPUT
RESULT:
Finding volume of cylinder using pointer to pointer has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 16
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:
a[10]={12,13,45,66,78,90,77,67,51,35} int
*ipt=&a[0], il int
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)
.
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;
}
01 - OUTPUT
RESULT:
Reading array of 10 numbers check the number is odd or even using pointer and array has been
executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 17
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:
ain[3][3]={{12,23,45},{66,87,3 int
3},{54,32,72,90}},ir,ic
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
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");
}
}
01 - OUTPUT
RESULT:
Setting primary and secondary diagonal elements to 0 using pointer notation has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 18
PROBLEM STATEMENT
Write a program perform matrix multiplication using pointer notation.
Constraints:
ain1[2][2]={1,2,3,4},ain2[3][3] int
={7,12,20,13},ir,ic,imul[2][2]
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
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
RESULT:
Performing matrix multiplication using pointer notation has been completed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 19
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:
aim[3][3]={20,18,27,0,49,35 int
,87,92,0},ir,ic,iz=0
(*p)[3]=aim
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
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;
}
}
01 - OUTPUT
RESULT:
Checking the matrix is sparse matrix or not using pointer has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 20
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:
arr1[3][3]={1,0,0,0,1,0,0,0,1}, int
ir,ic,flag=1.
SOLUTION
AIGORITHM
BEGIN
END
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");
}
01 - OUTPUT
RESULT:
Checking the matrix is identity matrix using pointer and array has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 21
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:
int
ain[5]={12,34,56,72,99},il
int
*ip=&ain[0]
SOLUTION
AIGORITHM
BEGIN
• STEP 6:Display array elements and memeory address using pointer to array-
*(ip+il),(ip+il).
END
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;
}
01 - OUTPUT
RESULT:
Reading array of 5 numbers and print the numbers along with address using pointer to an array
has been completed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 22
PROBLEM STATEMENT
Write a program to find sum of array elements using pointer to an array.
Constraints:
ain[5]={1,2,3,4,5},il,isum=0 int
*p=ain
SOLUTION
AIGORITHM
BEGIN
END
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);
}
01 - OUTPUT
RESULT:
Finding sum of array elements using pointer to an array has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 23
PROBLEM STATEMENT
Write a program to reverse array of 10 float values using pointer to an array.
Constraints:
a[5],*p=a float
il int
SOLUTION
AIGORITHM
BEGIN
END
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));
}
01 - OUTPUT
RESULT:
Reversing float values using pointer to array has been completed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 24
PROBLEM STATEMENT
Write a program to find largest element in an array using pointer to an array
Constraints:
a[5],*p=a,i int
SOLUTION
AIGORITHM
BEGIN
END
PROGRAM:
#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
RESULT:
Finding largest element in an array using pointer to an array has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 25
PROBLEM STATEMENT
Write a program to sort array elements using pointer to an array.
Constraints:
SOLUTION
AIGORITHM
BEGIN
END
PROGRAM:
#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++)
printf("%d\t",*(p+i));
}
01 - OUTPUT
RESULT:
Sorting array elements using pointer to an array has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 26
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:
SOLUTION
AIGORITHM
BEGIN
END
PROGRAM:
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
RESULT:
.Reading 3*3 matrix and printing transpose of matrix using pointer to an array has been executed
successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 27
PROBLEM STATEMENT
Write a program to set primary and secondary diagonal elements to 0 using pointer to an array.
Constraints:
aim[3][3]={2,3,4,5,6,7,2,3,4} int
(*p)[3]=aim,ir,ic
SOLUTION
AIGORITHM
BEGIN
END
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");
}
}
01 - OUTPUT
RESULT:
.Setting primary and secondary diagonal elements to 0 using pointer to an array has been
completed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 28
PROBLEM STATEMENT
Write a program add two matrix using pointer to an array.
Constraints:
a[2][2],b[2][2],i,j,add[2][2] int
int(*p)[2]=a int
int(*p1)[2]=b int
SOLUTION
AIGORITHM
BEGIN
END
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++)
{
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");
}}
01 - OUTPUT
RESULT:
Adding two matrix using pointer to an array has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 29
PROBLEM STATEMENT
Write a program to perform matrix multiplication using VLA.
Constraints:
r,c,i,j,k, Int
a[r][c],b[r][c],mul[r][c],
Int
(*p)[c]=a
Int
(*p1)[c]=b
int
SOLUTION
AIGORITHM
BEGIN’
END
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++)
{
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");
}
}
01 - OUTPUT
RESULT:
.Performing matrix multiplication using VLA has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 30
PROBLEM STATEMENT
Write a program to print alternative elements using VLA.
Constraints:
n,a[n],*p=a,i int
SOLUTION
AIGORITHM
BEGIN
END
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));
}
01 - OUTPUT
RESULT:
Printing alternative elements using VLA has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 31
PROBLEM STATEMENT
Write a program to find length of the string " advanced c program".
Constraints:
cstr[100]="advanced c char
program"
il,len
int
SOLUTION
AIGORITHM
BEGIN
END
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);
}
01 - OUTPUT
RESULT:
Finding length of the string " advanced c program" has been completed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 32
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:
cstr[100]= Char
"Coimbatore",cstr1[100]
il
int
SOLUTION
AIGORITHM
BEGIN
END
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);
}
01 - OUTPUT
RESULT:
. Coping the word “Coimbatore” using string handling function has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 33
PROBLEM STATEMENT
Write a program to merge two string using strcat function
Constraints:
cstr[100]="BTS",cstr1[100]="ARMY". char
SOLUTION
AIGORITHM
BEGIN
END
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;
}
01 - OUTPUT
RESULT:
. Merging two string using strcat function has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 34
PROBLEM STATEMENT
Write a program to find first occurrence of character a in the string "karpagam college of
engineering".
Constraints:
SOLUTION
AIGORITHM
BEGIN
• STEP 2: Using string handling function print the first occurrence of a strstr(str,str1).
END
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));
}
01 - OUTPUT
RESULT:
Finding first occurrence of character a in the string "karpagam college of
engineering" has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 35
PROBLEM STATEMENT
Write a program to find substring using strstr function.
Constraints:
SOLUTION
AIGORITHM
BEGIN
END
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));
}
01 - OUTPUT
RESULT:
Finding substring using strstr function has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 36
PROBLEM STATEMENT
Write a program to remove the delimiter space and : .
Constraints:
SOLUTION
AIGORITHM
BEGIN
• STEP 4: Display p.
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,";");
}
}
01 - OUTPUT
RESULT:
Removing the delimiter space and : has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 37
PROBLEM STATEMENT
Write a program to find length of the word without using strlen.
Constraints:
cstr[10]=”ARMY” char
il,len=0 int
SOLUTION
AIGORITHM
BEGIN
END
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;
}
01 - OUTPUT
RESULT:
Finding length of the word without using strlen has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 38
PROBLEM STATEMENT
Write a program merge two words without strcat.
Constraints:
cstr[100]="BANGTAN",cstr1[100]="SONEYODAN”. char
SOLUTION
AIGORITHM
BEGIN
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 39
PROBLEM STATEMENT
Write a program to reverse the string without strrev().
Constraints:
a[100]="BUTTER" Char
il int
SOLUTION
AIGORITHM
BEGIN
END
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
RESULT:
Reversing the string without strrev() .
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 40
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:
a[100]="karpagam” char
il int
SOLUTION
AIGORITHM
BEGIN
END
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
RESULT:
Converting the text "karpagam " into upper case has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 41
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:
str[100],c char
icnt=0,il int
SOLUTION
AIGORITHM
BEGIN
END
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;
}
01 – OUTPUT
RESULT:
Searching the character entered by user in the sentence and count occurrence has been
executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 42
PROBLEM STATEMENT
Write a program to replace the first 4 characters in the string “ADVANCED C
PROGRAMMING” with * without using strnset().
Constraints:
str[100]="ADVANCED C Char
PROGRAMMING”
il
int
SOLUTION
AIGORITHM
BEGIN
END
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);
}
01 – OUTPUT
RESULT:
Replacing the first 4 characters in the string “ADVANCED C
PROGRAMMING” with * without using strnset() has been executed successfully,.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 43
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:
Str[100]=”BTS” Char
il int
SOLUTION
AIGORITHM
BEGIN
END
PROGRAM:
01 – OUTPUT
RESULT:
Printing ASCII value along with character in the string has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 44
PROBLEM STATEMENT
Write a program to copy n number of characters from string1 to string2 without using
strncpy()
Constraints:
str1[100],str2[100] Char
il,in int
SOLUTION
AIGORITHM
BEGIN
• STEP 3: Get the string and number of characters from the user.
END
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);
}
01 – OUTPUT
RESULT:
Coping n number of characters from string1 to string2 without using
strncpy() has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 45
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:
str1[100] Char
Il,iu=0,ilow=0,isp=0 int
SOLUTION
AIGORITHM
BEGIN
• 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++.
END
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);
}
01 – OUTPUT
RESULT:
Counting number of space, upper case, lower case in the string has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 46
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:
SOLUTION
AIGORITHM
BEGIN
END
PROGRAM:
#include<stdio.h>
void main()
{
char str[100]="good Morning";
printf("%s ",strrchr(str,'o'));
}
01 – OUTPUT
RESULT:
Finding the last occurrence of the character ‘o’ in the string “good morning” has been completed
successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 47
PROBLEM STATEMENT
Write a program to convert string “WELCOME TO KCE” into lower case without using
strlwr()
Constraints:
str[100]="WELCOME Char
TO KCE".
il
int
SOLUTION
AIGORITHM
BEGIN
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);
}
}
01 – OUTPUT
RESULT:
Converting string “WELCOME TO KCE” into lower case without using
strlwr() has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 48
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:
str1[100]="CHIMCHIM",str2[100] Char
il int
SOLUTION
AIGORITHM
BEGIN
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);
}
01 – OUTPUT
RESULT:
Coping first 5 character into another string without using strncpy() has been executed
successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 49
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:
str[25] char
* p = strtok(str, "&") char
SOLUTION
AIGORITHM
BEGIN
END
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
RESULT:
Removing the & in the sentence using strtok(). Get string from user using
Gets has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 50
PROBLEM STATEMENT
Write a program to compare two strings using strcmp().
Constraints:
str1[25],str2[25] char
SOLUTION
AIGORITHM
BEGIN
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 51
TITLE STRUCTURE
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:
employee_id[100],dept_id[100] char
salary int
SOLUTION
AIGORITHM
BEGIN
END
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
RESULT:
Creation a structure called employee. Initialize and display employee_id,
dept_id and salary values using structure variable has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 52
TITLE STRUCTURE
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:
bk_id[100], char
ctit[100],cauth[100],sub[100]
SOLUTION
AIGORITHM
BEGIN
b={"AR22LB","AVENGERS","STALIN","LITERATURE"}.
END
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
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 .
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 53
TITLE STRUCTURE
PROBLEM STATEMENT
Write a program to find the size of a structure variable without structure padding using #
pragma pack (1)
Constraints:
bk_id[100],ctit[100],cauth[100],sub[100] char
SOLUTION
AIGORITHM
BEGIN
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 54
TITLE STRUCTURE
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:
dnum,ival int
name[50],add[100],idob[50]
char
SOLUTION
AIGORITHM
BEGIN
END
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
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 55
TITLE STRUCTURE
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:
name[50],bias[100] Char
toc
int
SOLUTION
AIGORITHM
BEGIN
JIMIN",13101995}.
END
PROGRAM:
#include <stdio.h>
struct Army
{
char name[50],bias[100];
int toc;
};
int main()
{
struct Army a={"BHAVISHYA","PARK JIMIN",13101995} ;
disp(a);
return 0;
}
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 56
TITLE STRUCTURE
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:
roll int
marks
float
SOLUTION
AIGORITHM
BEGIN
• 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++.
END
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;
01 – OUTPUT
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 .
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 56
TITLE STRUCTURE
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:
idol[50],role[50] char
score
int
SOLUTION
AIGORITHM
BEGIN
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 58
TITLE STRUCTURE
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:
name[100] char
iage
int
isal
float
SOLUTION
AIGORITHM
BEGIN
END
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);
}
01 – OUTPUT
RESULT:
Reading and displaying the name, age and salary of the employee using union has been executed
successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 59
TITLE STRUCTURE
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:
il int
SOLUTION
AIGORITHM
BEGIN
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 60
TITLE STRUCTURE
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:
SOLUTION
AIGORITHM
BEGIN
• STEP 1: Under structure time declare int hour, int time, int seconds.
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 61
PROBLEM STATEMENT
Write a program to find area of circle using malloc().
Constraints:
float*a float
SOLUTION
AIGORITHM
BEGIN
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 62
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:
SOLUTION
AIGORITHM
BEGIN
• STEP 3: Using for loop get the array elements from the user , initialize,compare and
END
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().
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 63
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:
char *a char
SOLUTION
AIGORITHM
BEGIN
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 64
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:
*a int
SOLUTION
AIGORITHM
BEGIN
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 65
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:
*a,il,ilarge int
SOLUTION
AIGORITHM
BEGIN
• STEP 5: Using for loop initialize, compare, increment- il : il=0;il<5; il++, check
condition- if(*(a+il)>ilarge),ilarge=*(a+il).
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
RESULT:
Reading an array of 5 elements and find the largest element in it using
Dynamic Memory Allocation has been executed.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 66
PROBLEM STATEMENT
Write a c program to multiply two numbers using function pointer.
Constraints:
void(*p)()=mul; void
SOLUTION
AIGORITHM
BEGIN
• STEP 5: Display-a*b
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 67
PROBLEM STATEMENT
Write a program to add three numbers using call by reference.
Constraints:
a=33,b=56,c=17 int
sum
int
SOLUTION
AIGORITHM
BEGIN
• STEP 3: Display sum , calling function add passing a,b,c by reference add(&a,&b,&c).
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 68
PROBLEM STATEMENT
Write a program to copy one string to another string by passing string to function.
Constraints:
str1[100],str2[100] char
SOLUTION
AIGORITHM
BEGIN
END
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;
}
01 – OUTPUT
RESULT:
Coping one string to another string by passing string to function has been executed.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex: No : 69
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:
no int
i,f=1
int
SOLUTION
AIGORITHM
BEGIN
PROGRAM:
#include <stdio.h>
void fact(int);
void main()
{
int no;
01 – OUTPUT
RESULT:
Finding the factorial of a given number using function pointer has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex: No : 70
PROBLEM STATEMENT
Write a c program to pass a structure to function.
Constraints:
roll Int
name[100]
Char
per float
SOLUTION
AIGORITHM
BEGIN
• STEP 3: In the main function, create structure element struct student st.
function- func(st).
END
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;
}
01 – OUTPUT
RESULT:
Passing a structure to function has been executed successfully.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 71
TITLE FILES
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:
a,b int
SOLUTION
AIGORITHM
BEGIN
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 72
TITLE FILES
PROBLEM STATEMENT
Write a c program to illustrate the use of fseek()
Constraints:
SOLUTION
AIGORITHM
BEGIN
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 73
TITLE FILES
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:
final int
SOLUTION
AIGORITHM
BEGIN
• STEP 5: fscanf(fp,"%d",&final).
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 74
TITLE FILES
PROBLEM STATEMENT
Write a program to print the source code of your program.
Constraints:
ch char
SOLUTION
AIGORITHM
BEGIN
END
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.
CODE BOOK
NAME BHAVISHYA.S
SECTION “A”
Ex : No : 75
TITLE FILES
PROBLEM STATEMENT
Write a program to perform addition of three numbers using command line arguments.
Constraints:
i,sum=0 int
SOLUTION
AIGORITHM
BEGIN
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.