PSTC Record 1 ST Year
PSTC Record 1 ST Year
in
www.vardhaman.org
DEPARTMENT OF INFORMATION TECHNOLOGY
CERTIFICATE
This is to Certify that, this is the bonafide record of practical lab work done by
Roll Number:…………………………………
www.vardhaman.org
INDEX
Mr. /Ms ………………………………………………… Roll No……………………………………..
Page
S.No Date Title of the Experiment Marks Signature
No.
1 Swap two Numbers
5 Calculating Displacement
www.vardhaman.org
INDEX
Mr. /Ms ………………………………………………… Roll No……………………………………..
Page
S.No Date Title of the Experiment Marks Signature
No.
15 Write a C program to calculate the factorial of a
given number
17 Reverse of a Number
23 grade of a student
27 prime or not
www.vardhaman.org
INDEX
Mr. /Ms ………………………………………………… Roll No……………………………………..
Page
S.No Date Title of the Experiment Marks Signature
No.
29 read an array of n elements and find
the sum of those elements
www.vardhaman.org
INDEX
Mr. /Ms ………………………………………………… Roll No……………………………………..
Page
S.No Date Title of the Experiment Marks Signature
No.
43 Read n elements into an Array and
find Sum of those elements using
functions
44 Read 1 person information and print
it using structures
45 Read 1 book information and print it
using structures
46 Read 1 student information and
print it using structures
47 Read n persons information and
print it using structures
48 Read n books information and print
it using structures
49 Read n students information and
print it using structures
50 Swap 2 Numbers using Call by Value
www.vardhaman.org
INDEX
Mr. /Ms ………………………………………………… Roll No……………………………………..
Page
S.No Date Title of the Experiment Marks Signature
No.
57 Print the contents of file in reverse
order
58 Random access in Files
www.vardhaman.org
VISION
To evolve as a center of academic excellence with ethical values in the field of Information
Technology to meet global needs.
MISSION
To mould young graduates to unleash their abilities for innovation and demands of the
industry.
To train students to take up diverse career paths.
To develop interpersonal skills through participation in the process of technology transfer.
To inculcate innovative thinking through collaborative research.
PROGRAM OUTCOMES (POs) & PROGRAM SPECIFIC OUTCOMES (PSOs)
PO1: Engineering Knowledge: Apply knowledge of mathematics, natural science, computing,
engineering fundamentals and an engineering specialization as specified in WK1 to WK4 respectively to
develop to the solution of complex engineering problems.
PO2: Problem Analysis: Identify, formulate, review research literature and analyze complex
engineering problems reaching substantiated conclusions with consideration for sustainable
development. (WK1 to WK4)
PO3: Design/Development of Solutions: Design creative solutions for complex engineering problems
and design/develop systems/components/processes to meet identified needs with consideration for
the public health and safety, whole-life cost, net zero carbon, culture, society and environment as
required. (WK5)
PO4: Conduct Investigations of Complex Problems: Conduct investigations of complex engineering
problems using research-based knowledge including design of experiments, modelling, analysis &
interpretation of data to provide valid conclusions. (WK8).
PO5: Engineering Tool Usage: Create, select and apply appropriate techniques, resources and modern
engineering & IT tools, including prediction and modelling recognizing their limitations to solve
complex engineering problems. (WK2 and WK6)
PO6: The Engineer and The World: Analyze and evaluate societal and environmental aspects while
solving complex engineering problems for its impact on sustainability with reference to economy,
health, safety, legal framework, culture and environment. (WK1, WK5, and WK7).
PO7: Ethics: Apply ethical principles and commit to professional ethics, human values, diversity and
inclusion; adhere to national & international laws. (WK9)
PO8: Individual and Collaborative Team work: Function effectively as an individual, and as a
member or leader in diverse/multi-disciplinary teams.
PO9: Communication: Communicate effectively and inclusively within the engineering community and
society at large, such as being able to comprehend and write effective reports and design
documentation, make effective presentations considering cultural, language, and learning differences.
PO10: Project Management and Finance: Apply knowledge and understanding of engineering
management principles and economic decision-making and apply these to one’s own work, as a
member and leader in a team, and to manage projects and in multidisciplinary environments.
PO11: Life-Long Learning: Recognize the need for, and have the preparation and ability for i)
independent and life-long learning ii) adaptability to new and emerging technologies and iii) critical
thinking in the broadest context of technological change.(WK8)
PSO1: Competent in Emerging Trends: Apply software design and development practices to develop
software applications in emerging areas such as Cloud and High-Performance Computing, Data
Analytics and Cyber Security.
PSO2: Successful Career and Entrepreneurship: The ability to employ modern computer languages,
environments, and platforms in creating innovative career paths to be an entrepreneur and a zest for
higher studies.
www.vardhaman.org
20. Write a C program to find the greatest of 3 numbers using conditional
operator
#include <stdio.h>
main()
scanf("%d%d%d",&a,&b,&c);
Output:
Enter a,b,c 20 30 10
BIG = 30
21. Write a C program to find the Smallest of 3 numbers using conditional
operator
#include <stdio.h>
main()
scanf("%d%d%d",&a,&b,&c);
Output:
Enter a,b,c 20 10 30
SMALL = 10
22. Write a C program to check whether the given number is even or odd.
#include<stdio.h>
main()
{
int n;
printf("Enter number ");
scanf("%d",&n);
if(n%2==0)
{
printf(" EVEN Number ");
}
else
{
printf(" ODD Number ");
}
}
Output:
Enter number 4
EVEN Number
23. Write a C program to read 3 subject Marks. Calculate and display the grade of a
student based on the following percentages.
< 40 - Fail
Between 41 and 50 – C grade
Between 51 to 60 – B grade
Between 61 to 75 – A grade
Greater than 75 – distinction
#include<stdio.h>
#include<math.h>
main()
{
int s1,s2,s3,p;
printf("Enter 3 subject marks ");
scanf("%d%d%d", &s1,&s2,&s3);
p=(s1+s2+s3)/3;
if(p>75)
{
printf(" Distinction ");
}
else if( (p>=61)&&(p<=75) )
{
printf(" A Grade ");
}
else if( (p>=51)&&(p<=60) )
{
printf(" B Grade ");
}
else if( (p>=41)&&(p<=50) )
{
printf(" C Grade ");
}
else
{
printf(" Fail ");
}
}
24. Write a C Program to perform Simple calculator using switch
statement
#include<stdio.h>
main()
{
int a,b,res;
char op;
printf("Enter 1 operator ");
scanf("%c", &op);
printf("Enter 2 operands ");
scanf("%d%d",&a,&b);
switch(op)
{
case '+':
res= a+b;
break;
case '-':
res= a-b;
break;
case '*':
res= a*b;
break;
case '/':
res= a/b;
break;
case '%':
res= a%b;
break;
default:
break;
}
printf(" RESULT = %d",res);
}
]
Output:
Enter 1 operator +
Enter 2 operands 4 2
RESULT = 6
25. Write a C program to find sum of individual digits of the given
number.
#include<stdio.h>
main()
{
int n,sum;
printf("Enter n ");
scanf("%d",&n);
sum=0;
while(n!=0)
{
sum= sum + n%10 ;
n = n/10;
}
printf(" %d ",sum);
}
Output:
Enter n 123
6
26. Write a C program to find the given number is number palindrome or not.
#include<stdio.h>
main()
{
int n,num,rev;
printf("Enter n ");
scanf("%d",&n);
num=n;
rev=0;
while(n!=0)
{
rev = rev*10 + n%10 ;
n = n/10;
}
if(num==rev)
{
printf(" Palindrome ");
}
else
{
printf(" Not Palindrome ");
}
}
Output:
Enter n 121
Palindrome
27. Write a C program to check the given number is prime or not.
#include<stdio.h>
#include<stdlib.h>
main()
{
int n,i;
printf("Enter n ");
scanf("%d",&n);
i=2;
while(i<=(n/2))
{
if((n%i)==0)
{
printf("Not Prime Number ");
exit(1);
}
i=i+1;
}
printf(" Prime Number ");
}
Output:
Enter n 11
Prime Number
28. Write a C program to print the output in various triangle patterns using
Nested for loop.
#include <stdio.h>
main()
{
int i,j;
for(i=1;i<=5;i=i+1)
{
for(j=1;j<=i;j=j+1)
{
printf(" %d ",i);
}
printf("\n\n");
}
}
Output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
#include <stdio.h>
main()
{
int i,j;
for(i=1;i<=5;i=i+1)
{
for(j=1;j<=i;j=j+1)
{
printf(" %d ",j);
}
printf("\n\n");
}
}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
#include <stdio.h>
main()
{
int i,j;
for(i=1;i<=5;i=i+1)
{
for(j=1;j<=i;j=j+1)
{
printf(" * ",j);
}
printf("\n\n");
}
}
Output:
* *
* * *
* * * *
* * * * *
29. Write a C Program to read an array of n elements and find the sum of
those elements
#include<stdio.h>
main()
{
int n,i,sum, x[10];
printf("Enter value of n ");
scanf("%d",&n);
printf("Enter array elements ");
for(i=0;i<n;i=i+1)
{
scanf("%d", &x[i]);
}
sum=0;
for(i=0;i<n;i=i+1)
{
sum= sum+x[i];
}
printf(" SUM = %d ",sum);
}
Output:
Enter value of n 3
Enter array elements 1 2 3
SUM = 6
30 . Write a C program to find the largest number among a list of integers.
#include<stdio.h>
main()
{
int n,i,big, x[10];
printf("Enter value of n ");
scanf("%d",&n);
printf("Enter array elements ");
for(i=0;i<n;i=i+1)
{
scanf("%d", &x[i]);
}
big=x[0];
for(i=1;i<n;i=i+1)
{
if(big<x[i])
{
big=x[i];
}
}
printf(" %d ",big);
}
Output:
Enter value of n 3
Enter array elements 20 30 10
30
31.Write a C program to find the smallest number among a list of integers.
#include<stdio.h>
main()
{
int n,i,small, x[10];
printf("Enter value of n ");
scanf("%d",&n);
printf("Enter array elements ");
for(i=0;i<n;i=i+1)
{
scanf("%d", &x[i]);
}
small=x[0];
for(i=1;i<n;i=i+1)
{
if(small>x[i])
{
small=x[i];
}
}
printf(" %d ",small);
}
Output:
Enter value of n 3
Enter array elements 20 10 30
10
32. Write a C Program to read an array of n elements and find the sum of all even
integers and odd integers.
#include<stdio.h>
main()
{
int n,i,se,so, x[10];
printf("Enter value of n ");
scanf("%d",&n);
printf("Enter array elements ");
for(i=0;i<n;i=i+1)
{
scanf("%d", &x[i]);
}
se=0;
so=0;
for(i=0;i<n;i=i+1)
{
if(x[i]%2==0)
{
se=se+x[i];
}
else
{
so = so+x[i];
}
}
printf(" %d %d ",se,so);
}
Output:
Enter value of n 4
Enter array elements 1234
6 4
33. Write a C program to find Addition of two Matrices.
#include<stdio.h>
main()
{
int A[10][10], B[10][10], C[10][10], p,q, i, j;
printf("SIZE OF MATRIX ");
scanf("%d%d",&p,&q);
printf("ENTER MATRIX A ");
for(i=0; i<p; i++)
{
for(j=0; j<q; j++)
{
scanf("%d",&A[i][j]);
}
}
printf("ENTER MATRIX B ");
for(i=0; i<p; i++)
{
for(j=0; j<q; j++)
{
scanf("%d",&B[i][j]);
}
}
SIZE OF MATRIX 2 2
ENTER MATRIX A
12
34
ENTER MATRIX B
11
11
2 3
4 5
34. Write a C program to find Multiplication of two Matrices.
#include<stdio.h>
main()
{
int A[10][10], B[10][10], C[10][10], p,q,r, i, j,k;
printf("SIZE OF MATRIX A ");
scanf("%d%d",&p,&q);
printf("ENTER MATRIX A ");
for(i=0; i<p; i++)
{
for(j=0; j<q; j++)
{
scanf("%d",&A[i][j]);
}
}
}
}
}
}
Output:
SIZE OF MATRIX A 2 2
ENTER MATRIX A
12
34
SIZE OF MATRIX B 2 2
ENTER MATRIX B
11
11
3 3
7 7
35. Check whether the given string is palindrome or not
#include<stdio.h>
#include<string.h>
main()
{
char x[10]= "aba" ;
char y[10];
strcpy(y,x);
if(strcmp(y,strrev(x))==0)
printf("Palindrome");
else
printf("Not Palindrome");
}
36. Read n names and print it.
#include <stdio.h>
main()
{
char x[100][20];
int i,n;
printf("Enter value of n ");
scanf("%d",&n);
printf("Enter n Names ");
for(i=0;i<n;i++)
{
scanf("%s",x[i]);
}
for(i=0;i<n;i++)
{
printf(" %s",x[i]);
}
}
Output:
Enter value of n 3
#include<stdio.h>
main()
{
printf(" %d ", fact(4) );
}
fact(int n)
{
if(n==1)return 1;
else
return n* fact(n-1);
}
Output:
24
38. Fibonacci numbers using Recursive function
#include<stdio.h>
main()
{
int i;
for(i=1; i<=10; i++)
{
printf(" %d ",fib(i));
}
}
fib(int n)
{
if(n==1) return 1;
else if(n==2)return 1;
else
return fib(n-1)+fib(n-2);
}
Output:
1 1 2 3 5 8 13 21 34 55
39. Write a c program to compute x power n.
#include <stdio.h>
main()
{
printf(" %d ", power(2,5));
}
power(int x, int n)
{
if(n==1) return x;
else return x * power(x,n-1);
}
Output:
32
40. Factorial of given number using Non Recursive function
#include<stdio.h>
main()
{
factorial();
}
factorial()
{
int n,i,fact;
printf("Enter n ");
scanf("%d",&n);
fact=1;
i=1;
while(i<=n)
{
fact= fact*i;
i= i+1;
}
printf(" %d",fact);
}
Output:
Enter n 4
24
41. Read n elements into an Array and find Largest element using functions.
#include<stdio.h>
main()
{
int n,i, x[10];
printf("Enter value of n ");
scanf("%d",&n);
printf("Enter array elements ");
for(i=0;i<n;i=i+1)
{
scanf("%d", &x[i]);
}
largest(x,n);
}
Output:
Enter value of n 4
Enter array elements 6 2 9 7
9
42. Read n elements into an Array and find Smallest element using functions.
#include<stdio.h>
main()
{
int n,i, x[10];
printf("Enter value of n ");
scanf("%d",&n);
printf("Enter array elements ");
for(i=0;i<n;i=i+1)
{
scanf("%d", &x[i]);
}
smallest(x,n);
}
Output:
Enter value of n 4
Enter array elements 9 5 2 6
2
43. Read n elements into an Array and find Sum of those elements using
functions.
#include<stdio.h>
main()
{
int n,i, x[10];
printf("Enter value of n ");
scanf("%d",&n);
printf("Enter array elements ");
for(i=0;i<n;i=i+1)
{
scanf("%d", &x[i]);
}
sum1(x,n);
}
Enter value of n 3
Enter array elements 1 2 3
6
44. Read 1 person information and print it using structures
#include<stdio.h>
struct person{
char name[20];
int age;
};
main()
{
struct person x;
Output:
NAME AGE
RAMU 18
NAME AGE
RAMU 18
45. Read 1 book information and print it using structures
#include<stdio.h>
struct book{
char title[20];
char author[20];
int pages
};
main()
{
struct book x;
Output:
#include<stdio.h>
struct student{
char name[20];
char rno[20];
char grade[20]
};
main()
{
struct student x;
Output:
#include<stdio.h>
struct person{
char name[20];
int age;
};
#define n 3
main()
{
struct person x[100];
int i;
Output:
NAME AGE
RAVI 17
RAMU 18
RAJU 19
NAME AGE
RAVI 17
RAMU 18
RAJU 19
48. Read n books information and print it using structures
#include<stdio.h>
struct book{
char title[20];
char author[20];
int pages
};
#define n 2
main()
{
struct book x[100];
int i;
printf("\n TITLE AUTHOR PAGES \n" );
for(i=0;i<n;i++)
{
scanf("%s%s%d",x[i].title,x[i].author,&x[i].pages);
}
printf("\n\n TITLE AUTHOR PAGES\n" );
for(i=0;i<n;i++)
{
printf(" %s %s %d \n",x[i].title,x[i].author,x[i].pages);
}
}
Output:
struct student{
char name[20];
char rno[20];
char grade[20]
};
#define n 2
main()
{
struct student x[100];
int i;
printf("\n NAME RNO GRADE \n" );
for(i=0;i<n;i++)
{
scanf("%s%s%s",x[i].name,x[i].rno,x[i].grade);
}
printf("\n\n NAME RNO GRADE \n" );
for(i=0;i<n;i++)
{
printf(" %s %s %s\n",x[i].name,x[i].rno,x[i].grade);
}
}
Output:
#include <stdio.h>
main()
{
int a=10, b=20;
swap(a,b);
printf(" %d %d ", a,b);
}
swap(int x, int y)
{
int temp;
temp=x;
x=y;
y=temp;
}
Output:
10 20
#include <stdio.h>
main()
{
int a=10, b=20;
swap(a,b);
swap(int x, int y)
{
int temp;
temp=x;
x=y;
y=temp;
Output:
20 10
51. Swap 2 Numbers using Call by Reference
#include <stdio.h>
main()
{
int a=10, b=20;
swap(&a,&b);
printf(" %d %d ", a,b);
}
swap(int* x, int* y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
Output:
20 10
52. Pointer Arithmetic
#include <stdio.h>
main()
{
int i=5, *x,*y;
x= &i;
y=x+3;
Output:
2556736948
2556736960
#include <stdio.h>
main()
{
int i=5, *x,*y;
x= &i;
y=x-3;
Output:
1318499524
1318499512
53. Read n cities and print n cities using Pointers and strings.
#include <stdio.h>
main()
{
char* x[100];
int i,n;
printf("Enter value of n ");
scanf("%d",&n);
printf("Enter n cities ");
for(i=0;i<n;i++)
{
scanf("%s",x[i]);
}
for(i=0;i<n;i++)
{
printf(" %s",x[i]);
}
}
Output:
Enter value of n 3
Enter n cities MADRAS DELHI BOMBAY
MADRAS DELHI BOMBAY
54. Copy from screen to file
#include <stdio.h>
main()
{
FILE* f1;
char ch;
f1= fopen("1.c","w");
printf(“Enter data ”);
while(1)
{
ch = getchar();
if(ch==EOF) break;
else putc(ch,f1);
}
fclose(f1);
}
55. Copy from file to screen
#include <stdio.h>
main()
{
FILE* f1;
char ch;
f1= fopen("1.c","r");
while(1)
{
ch = getc(f1);
if(ch==EOF) break;
else putchar(ch);
}
fclose(f1);
}
56. Copy from one file to another file
#include<stdio.h>
main()
{
FILE* f1 , *f2;
char ch;
f1= fopen("1.c","r");
f2= fopen("2.c","w");
while(1)
{
ch = getc(f1);
if(ch==EOF) break;
else putc(ch,f2);
}
fclose(f1);
fclose(f2);
}
57. Print the contents of file in reverse order
#include<stdio.h>
main()
{
FILE* f1;
char ch;
f1= fopen("1.c","r");
int i=0;
while(1)
{
fseek(f1,i,2);
ch = getc(f1);
putchar(ch);
i= i-1;
}
58. Random access in Files
#include<stdio.h>
main()
{
FILE* f1;
char ch;
f1= fopen("1.c","r");
int i=0;
while(1)
{
fseek(f1,i,2);
ch = getc(f1);
putchar(ch);
i= i-1;