24CSE401
24CSE401
24CSE401
Name : ………………………………………………………..
Register No :………………………………………………………..
Year/Sem : …………………………………………………….….
Department : …………………………………….…………………..
BONAFIDE CERTIFICATE
Name : ……………………………………………
Year/Sem : ……………………………………………
Department : ……………………………………………
Certified that this is a Bonafide Record of the Practical work done for the
above course in Laboratory during the period …..………………………..
……………………………………………………………
PAGE
S.NO. DATE NAME OF THE EXPERIMENT MARK SIGN
NO.
1. I/O Statements And Expressions
#include<stdio.h>
#include<conio.h>
void main()
{
int age,bir_year,cur_year;
clrscr();
printf("Enter the year of birth:\n");
scanf("%d",&bir_year);
age=cur_year-bir_year;
getch();
}
1
OUTPUT:
2
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“*********************\n”);
printf(“POSITIVE OR NEGATIVE\n”);
printf(“**********************\n”);
printf("Enter the number\n");
scanf("%d",&n);
if(n>0)
printf("The given number %d is positive\n",n);
else if(n<0)
printf("The given number %d is negative",n);
else
printf("The given number %d is neither positive nor negative",n);
getch();
}
3
OUTPUT:
***********************
POSITIVE OR NEGATIVE
***********************
4
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int ch,a,b,c;
clrscr();
printf("**********************\n");
printf("Menu driven program\n");
printf("**********************\n");
printf("Enter the choice\n");
printf(" 1) Addition\n 2) Subtraction\n 3) Multiplication\n 4) Division\n 5) Square\n");
printf(“Enter your choice:”);
scanf("%d",& ch);
switch(ch)
{
case 1:
printf("Enter two numbers to be added:");
scanf("%d%d",&a,&b);
c=a+b;
printf("\nThe sum of two numbers %d and %d is:%d",a,b,c);
break;
case 2:
printf("Enter two numbers to be subtracted:");
scanf("%d%d",&a,&b);
c=a-b;
printf("\nThe difference of two numbers %d and %d is:%d",a,b,c);
break;
5
case 3:
printf("Enter two numbers to be multiplied:");
scanf("%d%d",&a,&b);
c=a*b;
printf("\nThe product of two numbers %d and %d is:%d",a,b,c);
break;
case 4:
printf("Enter two numbers to be divided:");
scanf("%d%d",&a,&b);
c=a/b;
printf("\nThe division of two numbers %d and %d is:%d",a,b,c);
break;
case 5:
printf("Enter a number to be Square:");
scanf("%d",&a);
c=a*a;
printf("\nThe square of a number %d is:%d",a,c); break;
default:
printf("Invalid option");
}
getch();
}
6
OUTPUT:
*******************
Menu driven program
*******************
Enter the choice:
1) Addition
2) Subtraction
3) Multiplication
4) Division
5) Square
7
PROGRAM:
#include <stdio.h>
#include <math.h>
int main()
{
int n1, onum, r, result = 0, n = 0;
printf("\n\n Check whether an n digits number is armstrong or not :\n");
printf(" \n");
printf(" Input an integer : ");
scanf("%d", &n1);
onum = n1;
while (onum != 0)
{
onum /= 10;
++n;
}
onum = n1;
while (onum != 0)
{
r = onum % 10;
result += pow(r, n);
onum /= 10;
}
if(result == n1)
printf(" %d is an Armstrong number.\n\n", n1);
else
printf(" %d is not an Armstrong number.\n\n", n1);
return 0;
}
8
OUTPUT:
9
PROGRAM:
#include <stdio.h>
int main()
{
int a[1000],i,n,min,max;
printf("Enter size of the array : ");
scanf("%d",&n);
printf("Enter elements in array : ");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
min=max=a[0];
for(i=1; i<n; i++)
{
if(min>a[i])
min=a[i];
if(max<a[i])
max=a[i];
}
printf("Minimum of array is : %d",min);
printf("\nMaximum of array is : %d",max);
return 0;
}
10
OUTPUT:
76
85
55
Minimum of array is : 3
Maximum of array is : 85
11
PROGRAM:
#include<stdio.h>
int main()
{
int n, m, c, d, first[10][10], second[10][10], sum[10][10], diff[10][10];
printf("\nEnter the number of rows and columns of the first matrix \n\n");
scanf("%d%d", &m, &n);
printf("\nEnter the %d elements of the first matrix \n\n", m*n);
for(c = 0; c < m; c++)
{
for(d = 0; d < n; d++)
{
scanf("%d", &first[c][d]);
}
}
printf("\nEnter the %d elements of the second matrix \n\n", m*n);
for(c = 0; c < m; c++)
{
for(d = 0; d < n; d++)
{
scanf("%d", &second[c][d]);
}
}
printf("\n\nThe first matrix is: \n\n");
for(c = 0; c < m; c++)
{
for(d = 0; d < n; d++)
{
printf("%d\t", first[c][d]);
}
printf("\n");
}
12
printf("\n\nThe second matrix is: \n\n");
for(c = 0; c < m; c++)
{
for(d = 0; d < n; d++)
{
printf("%d\t", second[c][d]);
}
printf("\n");
}
for(c = 0; c < m; c++)
{
for(d = 0; d < n; d++)
{
sum[c][d] = first[c][d] + second[c][d];
}
}
printf("\n\nThe sum of the two entered matrices is: \n\n");
for(c = 0; c < m; c++)
{
for(d = 0; d < n; d++)
{
printf("%d\t", sum[c][d]);
}
printf("\n");
}
for(c = 0; c < m; c++)
for(d = 0; d < n; d++)
diff[c][d] = first[c][d] - second[c][d];
printf("\n\nThe difference(subtraction) of the two entered matrices is: \n\n");
for(c = 0; c < m; c++)
{
for(d = 0; d < n; d++)
{
13
printf("%d\t", diff[c][d]);
}
printf("\n");
}
return 0;
}
14
OUTPUT:
Enter the number of rows and columns of the first matrix
2
2
15
PROGRAM:
#include <string.h>
#include<stdio.h>
int main()
{
char s[1000],c1,c2,ch;
int i=0;
printf("Enter the string : ");
gets(s);
puts("Enter a character replace: ");
c1=getchar();
getchar();
printf("\nEnter character to replace with %c : ",c1);
c2=getchar();
printf("\n Before replace:%s",s);
for(i=0;s[i];i++)
{
if(s[i]==c1)
{
s[i]=c2;
}
}
printf("\nAfter replace:%s",s);
while((ch=getchar())!='\n')
{
s[i]=ch;
i++;
}
printf("\nOriginal String: %s\n",s);
printf("\nReverse String: ");
printf(“%s”,strrev(s));
return 0;}
16
OUTPUT:
17
PROGRAM:
#include<stdio.h>
int mul(int,int);
int main()
int a,b,pro;
scanf("%d%d",&a,&b);
pro=mul(a,b);
int p;
p=x*y;
return(p);
18
OUTPUT:
19
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<string.h>
#defineMINBAL500
structBank_Account
charno[10];
char ame[20];
char balance[15];
};
void main()
{
long int pos1,pos2,pos;
FILE*fp;
char *ano,*amt;
char choice;
int type,flag=0;
float bal;
do
clrscr();
fflush(stdin);
printf("2.Display\n");
20
printf("3.DepositorWithdraw\n");
printf("4.Number of Account Holder Whose Balance is less than the Minimum Balance\n");
printf("5. Stop\n");
printf("Enteryourchoice:");
choice=getchar();
switch(choice)
case1:
fflush(stdin);
fp=fopen("acc.dat","a");
gets(acc.no);
gets(acc.name);
fseek(fp,0,2);
fwrite(&acc,sizeof(acc),1,fp);
fclose(fp);
break;
case2:
fp=fopen("acc.dat","r");
if(fp==NULL)
printf("\nFile is Empty");
else
while(fread(&acc,sizeof(acc),1,fp)==1)
21
printf("%s\t\t%s\t%s\n",acc.no,acc.name,acc.balance);
fclose(fp);
break;
case3:
fflush(stdin);
flag=0;
fp=fopen("acc.dat","r+");
gets(ano);
for(pos1=ftell(fp);
fread(&acc,sizeof(acc),1,fp)==1;
pos1=ftell(fp))
{
if(strcmp(acc.no,ano)==0)
printf("\nEntertheType1fordeposit&2forwithdraw: ");
scanf("%d",&type);
fflush(stdin);
gets(amt);
if(type==1)
bal=atof(acc.balance)+atof(amt);
else
if(bal<0)
22
{
flag=2;
break;
flag++;break;
if(flag==1)
pos2=ftell(fp);
pos=pos2-pos1;
fseek(fp,-pos,1);
sprintf(amt,"%.2f",bal);
strcpy(acc.balance,amt);
fwrite(&acc,sizeof(acc),1,fp);
elseif(flag==0)
break;
case4:
fp=fopen("acc.dat","r");
flag=0;
while(fread(&acc,sizeof(acc),1,fp)==1)
bal = atof(acc.balance);
23
if(bal<MINBAL)
flag++;
printf("\nThe Number of Account Holder whose Balance less than the Minimum Balance :
%d",flag);
fclose(fp);
break;
case 5 :
fclose(fp);
exit(0);
}
printf("\nPress any key to continue. ... ");
getch();
} while (choice!='5');
}
24
OUTPUT:
25
PROGRAM:
#include<stdio.h>
union Job
float salary;
int workerno;
}j;
void main()
j.workerno=100;
printf(“Salary=%1f”,j.salary);
printf(“Workerno=%d”,j.workerno);
26
OUTPUT:
Salary=0.0
Workerno=100
27
PROGRAM:
#include<stdio.h>
void main()
int myage=37;
int *p=&myage;
printf(“\n Age=%d”,myage);
printf(“\n Address=%p”,p);
28
OUTPUT:
Age=37
Address=0x7ffe536e044
29
PROGRAM:
(CALL BY VALUE)
#include <stdio.h>
void swap(int, int);
int main()
{
int x, y;
printf("\n\nEnter the value of x and y : ");
scanf("%d%d",&x,&y);
printf("\n\nBefore Swapping : \nx = %d\ny = %d\n", x, y);
swap(x, y);
printf("\n\nAfter Swapping : \nx = %d\ny = %d\n", x, y);
return 0;
}
void swap(int a, int b)
{
int temp;
temp = b;
b = a;
a = temp;
printf("Values of a and b is %d %d\n",a,b);
}
30
OUTPUT:
Enter the value of x and y : 99 45
Before Swapping :
x = 99
y = 45
After Swapping :
x = 45
y = 99
31
PROGRAM:
(CALL BY REFERENCE)
#include <stdio.h>
void swap(int*, int*);
int main()
{
int x, y;
printf("\n\nEnter the value of x and y : ");
scanf("%d%d",&x,&y);
printf("\n\nBefore Swapping : \nx = %d\ny = %d\n", x, y);
swap(&x, &y);
printf("\n\nAfter Swapping : \nx = %d\ny = %d\n", x, y);
return 0;
}
void swap(int *a, int *b)
{
int temp;
temp = *b;
*b = *a;
*a = temp;
}
32
OUTPUT:
Enter the value of x and y : 99 45
Before Swapping :
x = 99
y = 45
After Swapping :
x = 45
y = 99
33
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
FILE *f1,*f2;
char c;
clrscr();
f1=fopen(“file1.txt”,”w”);
while((c=getchar()!=EOF)
putc(c,f1);
fclose(f1);
f2=fopen(“file2.txt”,”w”);
f1=fopen(“file1.txt”,”r”);
while((c=getc(f1))!=EOF)
putc(c,f2);
fclose(f1);
fclose(f2);
f2=fopen(“file2.txt”,”r”);
while((c=getc(f2))!=EOF)
34
printf(“%c”,c);
fclose(f2);
getch();
35
OUTPUT:
36
PROGRAM
#include <stdio.h>
if(argc < 2)
else
37
OUTPUT:
C:\TC\BIN\>program13.exe Hello
38