0% found this document useful (0 votes)
2K views

A Practical File On Programming in "C" (PGDCA-105)

The document is a practical file on programming in C language submitted as a partial fulfillment for a post graduate diploma in computer applications. It contains 30 programs on various C programming concepts like data types, loops, arrays, strings, functions, pointers, structures, file handling etc. Each program is presented with its aim, code and output to solve problems related to pattern printing, number systems, searching, sorting, matrix operations and more.

Uploaded by

priyal sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

A Practical File On Programming in "C" (PGDCA-105)

The document is a practical file on programming in C language submitted as a partial fulfillment for a post graduate diploma in computer applications. It contains 30 programs on various C programming concepts like data types, loops, arrays, strings, functions, pointers, structures, file handling etc. Each program is presented with its aim, code and output to solve problems related to pattern printing, number systems, searching, sorting, matrix operations and more.

Uploaded by

priyal sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 142

A

Practical File
On
Programming In “C” (PGDCA-105)

Submitted
In
Partial Fulfillment of the Requirement for the Award of the
Degree of
POST GRADUATE DIPLOMA IN COMPUTER
APPLICATIONS
For
Session 2021-22

SUBMITTED BY- GUIDED BY-


Miss. PRIYAL SINHA Mrs. AMRITA SHARMA RATHOD
PGDCA Sem-1 (Assistant Professor Comp. Dept.)

At
Disha College, Raipur
Affiliated to
Pt. Ravishankar Shukla University, Raipur (C.G)
INDEX
S. List of program Page no.
NO
.
1. Write a program in which you declare variable of all of data
type supported by C language. Get input from user and print
the value of each variable with alignment left, right and
column width 10. For real numbers print their value with two
digits right to the decimal.
2. Write a program to print all combination of 123.
3. Write a program to generate following pattern.

A) B)
***** *
**** **
*** ***
** ****
* *****

C) D)
1 1
23 212
456 32123
7 8 9 10 4321234
4. Write a program to display number 1 to 10 in octal, decimal
and hexadecimal system.
5. Write a program to find factorial of a number using loop.
6. Write a program to print Fibonacci series up to n terms.
7. Write a program to print prime numbers up to n terms. 
8. Write a program to print whether a given year is leap or not.
9. Write a program to reverse the string palindrome.
10. Write o program to count to number of characters in string and
copy one string into another.
11. Write a program to sort the elements of an integer array
12. Search for particular value in array element using linear
search. 
13. Search for particular value in array element using binary
search. 
14. Write a program to perform addition of two matrix. 

15. Write a program to perform multiplication of two matrix. 

16. Write a program to perform transpose of matrix.

17. Write a program to perform sum of diagonal elements of


matrix.

18. WAP using function power(a,b) to calculate the value a raised


to b (ab).
19. WAP to calculate factorial using user defined function.
20. WAP to find factorial using recursive function.
21. Create a structure student having data members to store roll
number, name of student, name of three subjects, max marks,
min marks, obtained marks. Declare a structure variable of
student. Provide facilities to input data in data member and
display result of student.
22. create a structure date with data member’s dd, mm, yy(to store
date). Create another structure employee with data members to
hold name of employee, employee id and date of joining (date
of will be hold by variable of structure date which appears as
date member in employee structure). Store data of an
employee and print same.
23. Create a structure student having data member to store roll
number, name of student, name of three subjects, max marks,
min marks, obtained marks. Declare array of structure to hold
data of 3 students. Provide facility to display result of specific
student whose roll number is given.
24. WAP to swapping two numbers and demonstrates call by
value and call by reference
25. WAP to create a structure employee having data number to
store name of employee, employee id, salary. Use pointer
structure to store data of employee and print the data using
pointer to structure.
26. WAP to demonstrate difference between constant pointer and
pointer to constant. 
27. WAP to demonstrate pointer arithmetic

28. WAP to demonstrate void pointer.

29. Write a program to copy content of one file to other file. 

30. Write a program to create a file *data’ containing a series of


integers and count all even numbers present in the data. 
OUTPUT-1
PROGRAM-1
AIM: Write a program in which you declare variable of all of data
type supported by C language. Get input from user and print the
value of each variable with alignment left, right and column width
10. For real numbers print their value with two digits right to the
decimal.

#include<stdio.h>
#include<conio.h>
void main()
{
char a;
int b;
float c;
double d;
clrscr();
printf("\n Enter any character:\n");
scanf(" %c",&a);
printf("\n Enter any integer:\n");
scanf(" %d",&b);
printf("\n Enter any real number:\n");
scanf(" %f",&c);
printf("\n Enter any real number:\n");
scanf(" %f",&d);
printf("\n All values with right alignment:");
printf("\n %10c",a);
printf("\n %10d",b);
printf("\n %10.2f",c);
printf("\n %10.21f",d);
printf("\n All values with left alignment:");
printf("\n %-10c",a);
printf("\n %-10d",b);
printf("/n %-10.2f",c);
printf("\n %-10.21f",d);
getch();
}
OUTPUT-2
PROGRAM-2
AIM: Write a program to print all combination of 123.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<3;i++)
{
for(j=1;j<=3;j++)
{
for(k=1;k<=3;k++)
{
if(i!=j&&i!=k&&j!=k)
{
printf("%d%d%d",i,j,k);
printf("\n");
}
}
}
}
getch();
}
OUTPUT-3
(A)
PROGRAM-3 (A)
AIM: Write a program to generate following pattern.

A)
*****
****
***
**
*

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr ();
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
printf("*");
}
printf("\n");
}
getch();
}
OUTPUT-3
(B)
PROGRAM-3 (B)
AIM: Write a program to generate following pattern.
B)
*
**
***
****
*****
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=5;i++)
{
for(k=5;k>i;k--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
OUTPUT-3
(C)
PROGRAM-3 (C)
AIM: Write a program to generate following pattern.   
              
 (C) 1
          2 3
456
7 8 9 10
     

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k=1;
clrscr ();
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++);
{
printf(“%d “,k);
}
printf(“\n”);
}
getch();
}
OUTPUT-3
(D)
PROGRAM-3 (D)
AIM: Write a program to generate following pattern.
(D)
1
212
32123
4321234

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,l;
clrscr();
for(i=1;i<5;i++)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=i;k>=1;k--)
{
printf("%d",k);
}
for(l=2;l<=i;l++)
{
printf("%d",l);
}
printf("\n");
}
getch();
}
OUTPUT-4
PROGRAM-4
AIM: Write a program to display number 1 to 10 in octal, decimal
and hexadecimal system. 

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("Value from 1 to 10 in octal format : \n");
for(i=1;i<=10;i++)
{
printf("%o ",i);
}
printf("\n Value from 1 to 10 in decimal format : \n");
for(i=1;i<=10;i++)
{
printf("%d " ,i);
}
printf("\n Value from 1 to 10 in hexadecimal format : \n");
for(i=1;i<=10;i++)
{
printf("%x " ,i);
}
getch();
}
OUTPUT-5
PROGRAM-5
AIM: Write a program to find factorial of a number using loop. 

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,fact;
clrscr();
fact=1;
printf("enter any number to calculate factorial:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("factorial of %d is:%d",n,fact);
getch();
}
Output-6

Program-6
AIM: Write a program to print Fibonacci series up to n terms. 

#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b=1,c,n,i;
clrscr ();
printf("enter the no");
scanf("%d",&n);
printf("%d %d",a,b);
for(i=2;i<n;++i)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
}
getch ();
}

OUTPUT-7
PROGRAM-7
AIM: Write a program to print prime numbers up to n terms. 

#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,fact,j;
clrscr();
printf("\n\Enter range to print prime no.");
scanf("%d",&num);
printf("Prime Numbers are:\n");
for(i=1;i<=num;i++)
{
fact=0;
for(j=1;j<=num;j++)
{
if(i%j==0)
fact++;
}
if(fact==2)
printf("%d",i);
}
getch();
}
OUTPUT-8

OUTPUT I

OUTPUT II
PROGRAM-8
AIM: Write a program to print whether a given year is leap or not. 

#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter the year");
scanf("%d",&year);
if(year%400==0)
{
printf("Given year is leap year");
}
else if(year%100==0)
{
printf("Given year is not leap year");
}
else if(year%4==0)
{
printf("Given year is leap year");
}
else
{
printf("Given year is not a leap year");
}
getch();
}
OUTPUT-9
PROGRAM-9
AIM: Write a program to reverse the string palindrome. 

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str1[30],str2[30];
printf("\n\n Enter a string: ");
gets(str1);
strcpy(str2,str1);
strrev(str2);
printf("\nReverse of given String is: %s",str1);
if(strcmp(str1,str2)==0)
{
printf("\nThe string is a palindrome.\n");
}
else
{
printf("\nThe string is not a palindrome.\n");
}
getch();
}
OUTPUT-10
PROGRAM-10
AIM: Write o program to count to number of characters in string
and copy one string into another. 

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[20],s2[20];
int l;
clrscr();
printf(“count the number of character in string :- “);
printf(“\nEnter String to know length : “);
gets(s1);
l=strlen(s1);
printf(“Length of the string is :%d”,l);
printf(“\n\n\nCopy one string into another string :- “);
printf(“\nEnter String in copy : “);
gets(s1);
strcpy(s2,s1);
printf(“Second String is : %s”,s2);
getch();
}
OUTPUT-11
PROGRAM-11
AIM: Write a program to sort the elements of an integer array. 

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],I,j,temp;
clrscr();
printf(“enter 9 elements”);
for(i=0;i<=9;i++)
{
scanf(“%d”,&a[i]);
}
for(i=0;i<=9;i++)
{
for(j=0;j<=9;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf(“array is sorted order\n”);
for(i=0;i<=9;i++)
{printf(“%d\n”,a[i]);
}
getch();
OUTPUT-12
OUTPUT-I

OUTPUT-II
PROGRAM-12
AIM: Search for particular value in array element using linear
search.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],I,find,f=0;
clrscr();
printf(“\nEnter 10 elements:\n”);
for(i=0;i<10;i++)
{
scanf(“%d”,&a[i]);
}
printf(“enter elements to be found:\n”);
scanf(“%d”,&a[i]);
for(i=0;i<10;i++)
{
if(a[i]==find)
{
f=1;
break;
}
}
if(f==1)
printf(“\n elements found at %d location\n”,i++);
else
printf(“\n elements not found\n”);
getch();
}
OUTPUT-13
OUTPUT-I

OUTPUT-II
PROGRAM-13
AIM: Search for particular value in array element using binary
search. 

#include<stdio.h>
#include<conio.h>
void main()
{
int arr[10],I,first,last,middle,search;
//clrscr();
printf(“enter 10 no. in acending order \n”);
for(i=0;i<=9;i++)
{
scanf(“%d”,& arr[i]);
}
printf(“enter element to binary search \n”);
scanf(“%d”,&search);
first=0;
last=9;
middle=(first+last)/2;
while(first<=last
{
if(arr[middle]<search)
{
first=middle+1;
}
else if(arr[middle]==search)
{
printf(“element found at %d position”,middle+1);
break;
}
else
{
last=middle-1;
}
middle=(first+last)/2;
}
if(first>last)
{
printf(“\n element not found”);
}
getch(); }
OUTPUT-14
OUTPUT-I

OUTPUT-II
PROGRAM-14
AIM: Write a program to perform addition of two matrix. 

#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j;
clrscr();
printf("Enter Numbers for First Matrix : \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("You have Entered Following Matrix : \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("\nEnter Numbers for Second Matrix : \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("You have Entered Following Matrix : \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d ",b[i][j]);
}
printf("\n");
}
printf("\n\nSum of Matrix are : \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}
OUTPUT-15
PROGRAM-15
AIM: Write a program to perform multiplication of two matrix. 

#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3];
int c[3][3],i,j,k;
clrscr();
printf("enter 9 numbers in first matrix \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter 9 numbers in second matrix \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("multiplication of two matrix \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
c[i][j]=0;
for(k=0;k<=2;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}
OUTPUT-16
PROGRAM-16
AIM:Write a program to perform transpose of matrix. 

#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],i,j;
clrscr();
printf("enter 9 element of martix \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&a[i][j]);
}
}

printf("the matrix is \n");

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

printf("transpose of matrix \n");

for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",a[j][i]);
}
printf("\n");
}
getch();
}
OUTPUT-17
PROGRAM-17
AIM: Write a program to perform sum of diagonal elements of
matrix. 

#include<stdio.h>
#include<conio.h>
void main()
{
int arr[3][3],i,j,sum=0;
clrscr();
printf("Enter 9 Elements");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&arr[i][j]);
}
}
printf("The Matrix is \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",arr[i][j]);
}
printf("\n");
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(i==j)
{
sum=sum+arr[i][j];
}
}
}
printf("\n sum of diagonal element at %d",sum);
getch();
}
OUTPUT -18
PROGRAM-18
AIM: WAP using function power(a,b) to calculate the value a raised
to b (ab). 

#include<stdio.h>
#include<conio.h>
#include<math.h>
void power(int,int);
int main()
{
int a,b;
printf("\n\n Enter the two numbers:\n");
scanf("%d%d",&a,&b);
power(a,b);
getch();
return 0;
}
void power(int a,int b)
{
int i,r;
r=1;
for(i=1;i<=b;i++)
{
r=a*r;
}
printf("The value of %d raised to %d is %d",a,b,r);
}
OUTPUT-19
PROGRAM-19
AIM: WAP to calculate factorial using user defined function. 

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,fact=1;
clrscr();
printf("enter any number to calculate factorial");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("factorial of given no. %d is %d",n,fact);
getch();
}
OUTPUT-20
PROGRAM-20
AIM: WAP to find factorial using recursive function. 

#include<stdio.h>
#include<conio.h>
int fact(int);
int main ()
{
clrscr();
int x,n;
printf(“Enter the number to find Factorial:”);
scanf(“%d”,&n);
x=fact(n);
printf(“\nFactorial =%d is %d”,n,x);
getch();
}
int fact (int n)
{
if(n==0)
return (1);
return n*fact(n-1); }
OUTPUT-21
OUTPUT-I
PROGRAM-21
AIM: Create a structure student having data members to store roll
number, name of student, name of three subjects, max marks, min
marks, obtained marks. Declare a structure variable of student.
Provide facilities to input data in data member and display result of
student. 

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
struct student
{
int roll;
char name[15];
char s1[12],s2[12],s3[12];
int max,min,obt;
};
struct student x;
char option='y';
int p=x.max+1,q=x.max+1,r=x.max+1;
OUTPUT-21
Clrscr();
while(option=='y')
{
printf("\n\n\tEnter the roll number:");
scanf("%d",&x.roll);
printf("\n\tEnter the name of the student:");
scanf("%s",&x.name);
printf("\n\tEnter the name of first subject:");
scanf("%s",&x.s1);
printf("\n\tEnter the name of second subject:");
scanf("%s",&x.s2);
printf("\n\tEnter the name of third subject:");
scanf("%s",&x.s3);
printf("\n\tEnter the maximum marks that can be obtained in each
subject:");
scanf("%d",&x.max);
printf("\n\tEnter the minimum marks that can be obtained in each
subject:");
scanf("%d",&x.min);
while(p>=x.max)
{
printf("\n\tEnter the marks obtained in %s:",x.s1);
scanf("%d",&p);
if(p>x.max)
printf("\n\t Invalid Input !!!");
getch();
}
while(q>=x.max)
{
printf("\n\tEnter the marks obtained in %s:",x.s2);
scanf("%d",&q);
if(q>x.max)
printf("\n\t Inalid Input !!!");
getch();
}
while(r>=x.max)
{
printf("\n\tEnter the marks obtained in %s:",x.s3);
scanf("%d",&r);
if(r>x.max)
printf("\n\t Invalud Input !!!");
getch();
}
clrscr();
x.obt=p+q+r;
printf("\n\t Roll Number :%d",x.roll);
printf("\n\n\t Name Of Student :%s",x.name);
printf("\n\n\t %-18s:%d",x.s1,p);
printf("\n\n\t %-18s:%d",x.s2,q);
printf("\n\n\t %-18s:%d",x.s3,r);
printf("\n\n\t maximum marks :%d",x.max);
printf("\n\n\t minimum marks :%d",x.min);
printf("\n\n\t obtained marks :%d",x.obt);
if(x.obt<((3*x.max)/3) || p<x.min || q<x.min || r<x.min)
printf("\n\n\t You are Fail");
else
printf("\n\n\t Congratulations !! You are Pass");
getch();
clrscr();
printf("\n\n\n\n\tDo you want to continue press y\n");
option=getch();
//return 0;
}
getch();
// return 0;
}
OUTPUT-22
PROGRAM-22
AIM: Create a structure date with data member’s dd, mm, yy(to store
date). Create another structure employee with data members to hold
name of employee, employee id and date of joining (date of will be
hold by variable of structure date which appears as date member in
employee structure). Store data of an employee and print same.

#include<stdio.h>
#include<conio.h>
struct date
{
int dd,mm,yyyy;
};
struct employee
{
char name[25];
int id;
struct date doj;
};
int main()
{
struct employee e1;
printf(“\n\n Enter Name of Employee :”);
scanf(“%s”,&e1.name);
printf(“ Enter Id of Employee :”);
scanf(“%d”,&e1.id);
printf(“ Enter date of joining :”);
scanf(“%d %d %d”,&e1.doj.dd,&e1.doj.mm,&e1.doj.yyyy);
printf(“\n Details of employee\n”);
printf(“\n Name of employee :%s”,e1.name);
printf(“\n Id of employee :%d”,e1.id);
printf(“\n Date of
joining:%d/%d/%d”,e1.doj.dd,e1.doj.mm,e1.doj.yyyy);
getch();
return 0;
}
OUTPUT-23
OUTPUT-I
PROGRAM-23
AIM:Create a structure student having data member to store roll
number, name of student, name of three subjects, max marks, min
marks, obtained marks. Declare array of structure to hold data of 3
students. Provide facility to display result of specific student whose
roll number is given.

#include<stdio.h>
#include<conio.h>
struct student
{
int rollno;
char name[25];
char sub1[30],sub2[30],sub3[30];
int max,min,obt;
}
s1[3];
int main()
{
int i,n,rno;
//clrscr();
printf("\n\nEnter name of subjects.");
OUTPUT-23
OUTPUT-II

OUTPUT-III
scanf("%s %s %s",s1[0].sub1,s1[1].sub2,s1[2].sub3);
printf("Enter maximum marks.");
scanf("%d",&s1[0].max);
printf("Enter minimum marks.");
scanf("%d",&s1[0].min);
for(i=0;i<3;i++)
{
printf("Enter roll number.");
scanf("%d",&s1[i].rollno);
printf("Enter name of student.");
scanf("%s",s1[i].name);
printf("Enter obtained marks.");
scanf("%d",&s1[i].obt);
}
printf("\nResult of students:\n");
printf("\nName of Three
Subjects:1.%s\t2.%s\t3.%s\n",s1[0].sub1,s1[1].sub2,s1[2].sub3);
printf("\n\t\tMaximum marks:%d\t Minimum marks:
%d\n",s1[0].max,s1[0].min);
printf("Do you want to see result of:\n1.All student \n2.Particular
student\n Enter Your Choice");
scanf("%d",&n);
if(n==1)
{
for(i=0;i<=2;i++)
{
printf("\n Roll number.%d\t Name of students:%s\t obtained marks:
%d",s1[i].rollno,s1[i].name,s1[i].obt);
}}
else
{
printf("Enter Roll Number of Student:\n");
scanf("%d",&rno);
if(rno==s1[0].rollno)
printf("Name of students:%s\t obtained marks:
%d",s1[0].name,s1[0].obt);
else if(rno==s1[1].rollno)
printf("Name of students:%s\t obtained marks:
%d",s1[1].name,s1[1].obt);
else if(rno==s1[2].rollno)
printf("Name of students:%s\t obtained marks:
%d",s1[2].name,s1[2].obt);
else
printf("\nYou have entered wrong Roll Number");
}
getch();
return 0;
}
OUTPUT-24
OUTPUT-I

Call by value:
PROGRAM-24
AIM: WAP to swapping two numbers and demonstrates call by
value and call by reference. 

CALL BY VALUE:
#include<stdio.h>
#include<conio.h>
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
printf("Values after swapping:\n a=%d b=%d\n",a,b);
}
void main()
{
int a,b;
clrscr();
printf("\n\nEnter two values:\n");
scanf("%d%d",&a,&b);
printf("Values before swapping:\n a=%d b=%d\n",a,b);
swap(a,b);
getch();
}
OUTPUT-II
CALL BY REFERENCE:

#include<stdio.h>
#include<conio.h>
void swap(int*,int*);
int main()
{
int a,b;
printf("Enter two nnunmbers:");
scanf("%d %d",&a,&b);
printf("\nValue before swapping\n");
printf("a=%d\tb=%d",a,b);
swap(&a,&b);//call by refernce
printf("\nValue after swapping\n");
printf("a=%d\tb=%d",a,b);
getch();
}
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
OUTPUT-25
PROGRAM-25
AIM: WAP to create a structure employee having data number to
store name of employee, employee id, salary. Use pointer structure
to store data of employee and print the data using pointer to
structure. 
#include<stdio.h>
#include<conio.h>
struct employee
{
char name[25];
int id,salary;
}e1={"Priyal",10,30000};
void main()
{
struct employee *p;
p=&e1;
printf("\nEmployee id:%d",p->id);
printf("\nName of Employee:%s",p->name);
printf("\nSalary of Employee:%d",p->salary);
getch();
}
OUTPUT-26
OUTPUT-I
POINTER TO CONSTANT :
PROGRAM-26
AIM: WAP to demonstrate difference between constant pointer and
pointer to constant. 
POINTER TO CONSTANT:
//pointer to constant
#include<stdio.h>
#include<conio.h>

int main()
{
char a='A',b='B';
const char *ptr = &a;

//*ptr = b; illegal statement (assignment of read-only location *ptr)

// ptr can be changed


printf("value pointed to by ptr: %c\n", *ptr);
ptr = &b;
printf("value pointed to by ptr: %c\n", *ptr);
}
OUTPUT-II
CONSTANT TO POINTER:
CONSTANT TO POINTER:

#include<stdio.h>
#include<conio.h>
int main()
{
char a='A',b='B';
char *const ptr = &a;
printf("Value pointed to by ptr: %c\n", *ptr);
printf("Address ptr is pointing to : %d\n\n",ptr);

//ptr = &a; illegal statement(assignment of read-only variable ptr)

//changing the value at the address ptr is pointing to *ptr = b;


printf("Value pointed to by ptr: %c\n",*ptr);
printf("Address ptr is pointed to: %d\n",ptr);
}
OUTPUT-27
PROGRAM-27
AIM: WAP to demonstrate pointer arithmetic. 

#include<stdio.h>
#include<conio.h>
void main()
{
int n=10;
int *p;
p=&n;
clrscr();
printf("\nAddress of n : %u\n",p);
p++;
printf("Pointer using after increment : %u",p);
getch();
}
OUTPUT-28
PROGRAM-28
AIM: WAP to demonstrate void pointer. 

#include<stdio.h>
#include<conio.h>
int main()
{
int a=10;
char c='A';
void *p;
p=&a;
printf("value of a : %d\n",*(int*)p);
printf("address of a : %u\n",p);
p=&c;
printf("value of c : %c\n",*(char*)p);
printf("address of c : %u\n",p);
getch();
}
OUTPUT-29
OUTPUT-I

OUTPUT-II

OUTPUT-III
PROGRAM-29
AIM: Write a program to copy content of one file to other file. 

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
FILE *fp1,*fp2;
char ch,Sample,Output;
fp1=fopen("Sample.txt","r");
fp2=fopen("Output.txt","w");
while((ch=getc(fp1))!=EOF)
{
putc(ch,fp2);
}
printf("\n\n File copied successfully !");
fclose(fp1);
fclose(fp2);
getch();
}
OUTPUT-30
PROGRAM-30
AIM: Write a program to create a file *data’ containing a series of
integers and count all even numbers present in the data.

#include<stdio.h>
#include<conio.h>
int main()
{
FILE *f1,*f2;
int n,i,num,count=0;
printf("\n\nEnter contents of DATA file:\n");
f1=fopen("data.txt","w");
for(i=1;i<=10;i++)
{
scanf("%d",&num);
if(num==-1)
break;
putw(num,f1);
}
fclose(f1);
f1=fopen("data.txt","r");
f2=fopen("even.txt","w");
while((num=getw(f1))!=EOF)
{
if(num%2==0)
{
count++;
putw(num,f2);
}
}
fclose(f1);
fclose(f2);
f2=fopen("even","r");
while((num=getw(f2))!=EOF)
printf("%d",num);
fclose(f2);
printf("\nTotal Even Numbers are:%d",count);
getch();
}

You might also like