0% found this document useful (0 votes)
17 views41 pages

24CSE401

This document is a practical record for a computing and C programming laboratory course, detailing various experiments and their corresponding programs. It includes a bonafide certificate, a list of experiments, and sample C programs with their outputs, covering topics such as input/output statements, conditional branching, and data structures. The document serves as a record of practical work done by students for assessment purposes.

Uploaded by

B Anandakumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views41 pages

24CSE401

This document is a practical record for a computing and C programming laboratory course, detailing various experiments and their corresponding programs. It includes a bonafide certificate, a list of experiments, and sample C programs with their outputs, covering topics such as input/output statements, conditional branching, and data structures. The document serves as a record of practical work done by students for assessment purposes.

Uploaded by

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

PRACTICAL RECORD

24CSE401

FUNDAMENTALS OF COMPUTING AND C


PROGRAMMING LABORATORY

Name : ………………………………………………………..

Register No :………………………………………………………..

Year/Sem : …………………………………………………….….

Department : …………………………………….…………………..
BONAFIDE CERTIFICATE

Name : ……………………………………………

Register No. : ……………………………………………

Year/Sem : ……………………………………………

Department : ……………………………………………

Course Code : ……………………………………………

Course Name : ……………………………………………

Certified that this is a Bonafide Record of the Practical work done for the
above course in Laboratory during the period …..………………………..

Faculty in-charge Head of the Department

Submitted for the University Practical Examination held on

……………………………………………………………

Internal Examiner External Examiner


CONTENTS

PAGE
S.NO. DATE NAME OF THE EXPERIMENT MARK SIGN
NO.
1. I/O Statements And Expressions

2. Conditional Branching Statements

3. Menu Driven Calculator Using


Switch Case Statement
4. Find Whether Given Number Is An
Armstrong Number Or Not
5A . To Print Minimum And Maximum
Elements In The 1-D Array
To Perform Matrix Addition And
5B . Matrix Subtraction

To Read And Display A Value


6. Using Getchar(),Putchar(),Gets()
And Puts()
7. To Find Product Of Two Numbers
Using Functions
With Arguments, With Return Type
8. To Create Structure For An Account
Holder In A Bank
9. To Create Union Program

10. To Print The Address Of Variable


Using Pointer
11A. To Swap Two Numbers Using Call
By Value

To Swap Two Numbers Using Call


11B. By Reference

Copies The Contents Of One File To


12. Another File

Program Using Command Line


13. Argument
PROGRAM:

#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);

printf("Enter the current year:\n");


scanf("%d",&cur_year);

age=cur_year-bir_year;

printf("The age is:%d years",age);

getch();
}

1
OUTPUT:

Enter the year of birth: 2006


Enter the current year: 2024
The age is: 18 years

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
***********************

Enter the number : 12


The given number 12 is positive

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

Enter a number to be squared: 4

The square of a number 4 is: 16

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:

Check whether an n digits number is armstrong or not :

Input an integer : 1634


1634 is an Armstrong number.

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:

Enter size of the array : 5

Enter elements in array :

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

Enter the 4 elements of the first matrix


23
43
54
87

Enter the 4 elements of the second matrix


54
32
98
76

The first matrix is:


23 43
54 87

The second matrix is:


54 32
98 76

The sum of the two entered matrices is:


77 75
152 163

The difference(subtraction) of the two entered matrices is:


-31 11
-44 11

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:

Enter the string : hello


Enter a character replace:h
Enter character to replace with h : H
Before replace:hello
After replace:Hello
Original String: Hello
Reverse String: olleH

17
PROGRAM:

#include<stdio.h>

int mul(int,int);

int main()

int a,b,pro;

printf("\nInput two integer numbers:");

scanf("%d%d",&a,&b);

pro=mul(a,b);

printf("\n\nMultiplication of two integer=%d",pro);

int mul(int x, int y)

int p;
p=x*y;

return(p);

18
OUTPUT:

Input two integer numbers:21 21

Multiplication of two integer=441

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];

};

Struct Bank_Account acc;

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("1. Add a New Account Holder\n");

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");

printf("\nEnter the Account Number : ");

gets(acc.no);

printf("\nEnter the Account Holder Name : ");

gets(acc.name);

printf("\nEnter the Initial Amount to deposit : ");


gets(acc.balance);

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

printf("\nA/cNumber\tA/c Holder NameBalance\n");

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+");

printf("\nEnter the Account Number :");

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);

printf("\nYourCurrentBalance is: %s",acc.balance);

printf("\nEnter the Amount to transact : ");

fflush(stdin);

gets(amt);

if(type==1)

bal=atof(acc.balance)+atof(amt);

else

bal = atof(acc.balance) - atof(amt);

if(bal<0)
22
{

printf("\nRs.%s Not available in your A/c\n",amt);

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)

printf("\nA/c Number Not exits... Check it again");fclose(fp);

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:

1. Add a New Account Holder


2. Display
3. Deposit or Withdraw
4. Number of Account Holder Whose Balance is less than the Minimum Balance
5. Stop
Enter your choice : 1
Enter the Account Number : 11111
Enter the Account Holder Name : kkkk
Enter the Initial Amount to deposit : 25555
Enter your choice : 2
A/c Number : 11111
A/c Holder Name Balance: kkkk
25555

25
PROGRAM:

#include<stdio.h>

union Job

float salary;

int workerno;

}j;

void main()

j.salary=12.3;//when j.workerno is assigned a value

//j.salary will no longer hold 12.3

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();

printf(“Enter the data to the file1.txt file \n”);

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);

printf(“Afetr copying the data in file2.txt file is \n”);

f2=fopen(“file2.txt”,”r”);

while((c=getc(f2))!=EOF)

34
printf(“%c”,c);

fclose(f2);

getch();

35
OUTPUT:

Enter the data to the file1.txt file

STUDENT BOX OFFICE.IN

After copying the data in file2.txt file is

STUDENT BOX OFFICE.IN

36
PROGRAM

#include <stdio.h>

void main(int argc, char *argv[] )

printf("Program name is: %s\n", argv[0]);

if(argc < 2)

printf("No argument passed through command line.\n");

else

printf("First argument is: %s\n", argv[1]);

37
OUTPUT:

C:\TC\BIN\>program13.exe Hello

Program Name is:C:TC\BIN\PROGRAM13.EXE

First argument is:Hello

38

You might also like