0% found this document useful (0 votes)
12 views7 pages

EXP3

C programming and Data Structures lab

Uploaded by

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

EXP3

C programming and Data Structures lab

Uploaded by

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

EX.

NO - 3(A) SWAPPING OF TWO NUMBERS UNING CALL BY REFERENCE

DATE :

AIM :
To write a C program on swapping of two numbers using call by reference.

ALGORITHM :

STEP 1: Start the program.

STEP 2: Assign a=10 & b=20.

STEP 3: Using reference value swap x and y values.

STEP 4: Print the swapped values.

STEP 5: Stop the program.


PROGRAM :
#include<stdio.h>
#include<conio.h>
void swap(int*,int*);
void main()
{
int a=10,b=20;
printf("Before swap values are %d %d",a,b);
swap(&a,&b);
printf("after swap values are %d %d\n",a,b);
getch();
}
void swap(int*x,int*y)
{
*x=*x+*y;
*y=*x-*y;
*x=*x-*y;
printf("\nSwap function values are %d %d\n",*x,*y);
}

SAMPLE OUTPUT :

Before swap values are 10 20


Swap function values are 20 10
after swap values are 20 10

RESULT :
Thus, the C program to perform swapping of two numbers using call by reference has
been executed successfully.
EX. NO - 3(B)
DATE : SWAPPING OF TWO NUMBERS UNING CALL BY VALUE

AIM :
To write a C program on swapping of two numbers using call by reference.

ALGORITHM :

STEP 1: Start the program.

STEP 2: Assign a=10 & b=20.

STEP 3: Using swap function swap a & b values.

STEP 4: Assign t = x, x=y and y=t to swap the values.

STEP 5: Print the swapped values.

STEP 6: Stop the program.


PROGRAM :

#include <stdio.h>
void swap(int x, int y);
int main()
{
int a = 10, b = 20;
swap(a, b);
printf("a=%d b=%d\n", a, b);
return 0;
}
void swap(int x, int y)
{
int t;t
= x;x
= y;y
= t;
printf("x=%d y=%d\n", x, y);
}

SAMPLE OUTPUT :

x=20 y=10
a=10 b=20

RESULT :
Thus , we have implemented the c program swapping of two numbers using call by
value successfully .
EX. NO - 3(C)
DATE : STRUCTURE

AIM :
To write and implement a C program on structure.

ALGORITHM :

STEP 1: Start the program.

STEP 2: Get roll no, m1 & m2 values.

STEP 3: Sum the total marks.

STEP 4: Compute the marks average.

STEP 5: Print the total & average values.

STEP 6: Stop the program.


PROGRAM :

#include<st
dio.h>
#include<c
onio.h>
void
main()
{
struct stud
{
int
rno,m1,m2
; char
name[10];
};
struct
stud
s; int
tot;
float
avg;
clrsc
r();
printf("\n Enter the Student Name,Roll No,Mark1,Mark2
\n"); scanf("%s%d%d%d",s.name,&s.rno,&s.m1,&s.m2);
tot=s.m1+s.m2;
avg=tot/2;
printf("\n Student Name: %s, \n Student Roll no: %d \n Students Marks are
%d\t%d\
n",s.name,s.rno,s.m1,s.m2);
printf("\n Total Mark is ...%d\
n",tot); printf("\n Average is
%f\n",avg); getch();
}

SAMPLE OUTPUT :

Enter the Student Name,Roll No,Mark1,Mark2


Nishanth
2012659001
98
97

Student Name: Nishanth,


Student Roll no: 2012659001
Students Marks are 98 97

Total Mark is ...195

Average is 97.000000

RESULT :

Thus , the C program on structure has been executed successfully.

You might also like