Docsity

File Handling-Network Programming-Lab Report, Exercises of Network Programming

Toggle sidebar
bg1
NETWORK PROGRAMING
LAB # 1
TASK #1
Make a program that swaps the values of integer type variables by calling a
function swap1 using two methods
. a) By value.
b) By reference.
Solution (a)
#include "stdafx.h"
#include<stdio.h>
int swap1(int a, int b);
int main(int agrc, char *argv[])
{
int a=5,b=6;
printf ("before swaping");
printf("\n a=%d",a);
printf("\n b=%d",b);
swap1(a, b);
printf("\n After swapping");
printf("\n a=%d",a);
printf("\n b=%d",b);
return 0;
}
int swap1(int a, int b)
{
int c=0;
c=a;
a=b;
b=c;
return;
}
docsity.com
pf3

Partial preview of the text

Download File Handling-Network Programming-Lab Report and more Exercises Network Programming in PDF only on Docsity!

NETWORK PROGRAMING

LAB # 1

TASK

Make a program that swaps the values of integer type variables by calling a

function swap1 using two methods

a) By value.

b) By reference.

Solution (a) #include "stdafx.h" #include<stdio.h> int swap1(int a, int b); int main(int agrc, char *argv[]) { int a=5,b=6; printf ("before swaping"); printf("\n a=%d",a); printf("\n b=%d",b); swap1(a, b); printf("\n After swapping"); printf("\n a=%d",a); printf("\n b=%d",b); return 0; } int swap1(int a, int b) { int c=0; c=a; a=b; b=c; return; }

Solution (b) #include "stdafx.h" #include<stdio.h> int swap1(int &a, int &b); int main(int agrc, char *argv[]) { int a=5,b=6; printf ("before swaping"); printf("\n a=%d",a); printf("\n b=%d",b); swap1(&a, &b); printf("\n After swapping"); printf("\n a=%d",a); printf("\n b=%d",b); return 0; } int swap1(int *a, int b) { int c=0; c=a; a=b; *b=c; return; } TASK # Make a program that swaps two strings of character type by calling a function swap1. Strings carry the names of the students then pass them to a function by reference. TASK# Make a program that swaps two structures of students then pass there values to the function by reference.. Struct student { int id=10; char name[ ]; }