Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

LAB 3 - POKOSENKO ALINA - MKDfuc-22

1. Devise a function called min(x,y) that returns the smaller of two double values. Test the


function with a simple driver.
3. Write a function that takes three arguments: a character and two integers. The character is to
be printed. The first integer specifies the number of times that the character is to be printed on
a line, and the second integer specifies the number of lines that are to be printed. Write a
program that makes use of this function.
4. The harmonic mean of two numbers is obtained by taking the inverses of the two numbers,
averaging them, and taking the inverse of the result. Write a function that takes
two double arguments and returns the harmonic mean of the two numbers.
5. Write and test a function called larger_of() that replaces the contents of
two double variables with the maximum of the two values. For example, larger_of(x,y) would
reset both x and y to the larger of the two.
6. Write and test a function that takes the addresses of three double variables as arguments
and that moves the value of the smallest variable into the first variable, the middle value to the
second variable, and the largest value into the third variable.

#include <bits/stdc++.h>

using namespace std;

void valueSwap(double *a,double *b,double *c)

double f,s,t;

if(*a>=*b)

if(*a>=*c)

t = *a;

if(*c>=*b)

s = *c;

f = *b;

else

f = *c;

s = *b;

}
else

f = *b;

s = *a;

t = *c;

else

if(*b>=*c)

t = *b;

if(*c>=*a)

s = *c;

f = *a;

else

f = *c;

s = *a;

}
}

else

t = *c;

s = *b;

f = *a;

*a = f;

*b = s;

*c = t;

int main()

double n1,n2,n3;

cout<<"Enter the first number:";

cin>>n1;

cout<<"Enter the second number:";

cin>>n2;

cout<<"Enter the third number:";

cin>>n3;

valueSwap(&n1,&n2,&n3);

cout<<"Number after swapping: "<<n1<<" "<<n2<<" "<<n3<<endl;


return 0;

}
7. Write a program that reads characters from the standard input to end-of-file. For each
character, have the program report whether it is a letter. If it is a letter, also report its numerical
location in the alphabet. For example, c and C would both be letter 3. Incorporate a function
that takes a character as an argument and returns the numerical location if the character is a
letter and that returns –1 otherwise.
11. Write and test a Fibonacci() function that uses a loop instead of recursion to calculate
Fibonacci numbers.

You might also like