Lab Task
Lab Task
PROGRAMMING
LAB 4
─
HASNAAT RAZA
22F-3389
15TH FEB,2023
1
TASK 1:
#include <iostream>
if (num == 0)
return 0;
else
int main()
int num;
sum(num);
cout << "The sum is: " << sum(num) << endl;
cout << "The average is: " << avg << endl;
return 0;
}
2
Task 2:
#include <iostream>
if (n <= 0)
return;
fibonacci(n - 1, b, a + b);
int main()
int n;
cin >> n;
3
fibonacci(n);
return 0;
Task 4:
#include <iostream>
struct Car
char carName[20];
char carModel[20];
int yearModel;
double cost;
};
int main()
cout << "The " << car1.carName << " has a higher cost." <<
endl
<< endl;
else
cout << "The " << car2.carName << " has a higher cost." <<
endl
<< endl;
<< endl;
}
5
Task 5:
#include <iostream>
struct distanc
int feet;
float inches;
};
int main()
distanc d1,d2,d3;
d2.feet = 10;
d2.inches = 5.25;
6
cout << "d1 = " << d1.feet << " feet " << d1.inches << " inches"
<< endl;
cout << "d2 = " << d2.feet << " feet " << d2.inches << " inches"
<< endl;
cout << "d3 = " << d3.feet << " feet " << d3.inches << " inches"
<< endl;
d3.feet += 1;
d3.inches -= 12.0;
cout << "d1 = " << d1.feet << " feet " << d1.inches << " inches"
<< endl;
cout << "d2 = " << d2.feet << " feet " << d2.inches << " inches"
<< endl;
cout << "d3 = " << d3.feet << " feet " << d3.inches << " inches"
<< endl;
return 0;
}
7