0% found this document useful (0 votes)
8 views2 pages

Computer Laboratory 6

The document provides instructions for two tasks: 1. Copy and paste code to compute the area of a triangle by calling the TArea function, passing in the three side lengths as arguments and printing the returned area. 2. Write a recursive fibo function to calculate the nth Fibonacci number, with each number being the sum of the previous two, and call this function from main to compute a given value of n.

Uploaded by

furkanarslan1285
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)
8 views2 pages

Computer Laboratory 6

The document provides instructions for two tasks: 1. Copy and paste code to compute the area of a triangle by calling the TArea function, passing in the three side lengths as arguments and printing the returned area. 2. Write a recursive fibo function to calculate the nth Fibonacci number, with each number being the sum of the previous two, and call this function from main to compute a given value of n.

Uploaded by

furkanarslan1285
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/ 2

COMPUTER LABORATORY 6

Task1: Copy and paste the code below. Save (as triangle.cpp), compile and run it.
// Computing the area of a triangle
#include <iostream>
#include <cmath> using
namespace std;
// The function prototype
double TArea(double, double, double);
int main()
{
double a, b, c, area;
cout << "Enter the sides of the triangle: ";
cin >> a >> b >> c;
area = TArea(a, b, c);
cout << "The area of this triangle is " << area << endl;
return 0;
}
// Returns the area of any triangle
double TArea(double a, double b, double c)
{
// Check if any side is negative
if (a<0. || b<0. || c<0.) return 0.0;
// Check if any side is greater than sum of two
if (a >= b+c) return 0.0;
if (b >= a+c) return 0.0;
if (c >= a+b) return 0.0;
// Calculate and return the area
double u, area;
u = 0.5*(a+b+c);
area = sqrt(u*(u-a)*(u-b)*(u-c));
return area;
}

Task 2: Using recursion, write a func?on (named as fibo) to find nth Fibonacci number. Call this func?on in the
main program with the argument n.

Fibonacci Series:
1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th ...
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89...
Task 4:

You might also like