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

ABBOTTABAD UNIVERSITY OF

SCIENCE &
TECHNOLOGY

Department of Computer Science

Name: Wazeer Gondal

Class: BS (Computer Science)

Roll No.: 232252

Section: C

Subject: Programming Fundamentals

Submitted To: Mam Arooba Akhter


Q1. Write, compile and run code to convert lent in feet to centimeter

CODE:
#include <iostream>
using namespace std;

int feetToCentimeters(int feet) {


return feet * 30.48;
}

int main() {
int lengthInFeet;
cout << "Enter length in feet: ";
cin >> lengthInFeet;
cout << lengthInFeet << " feet is equal to " <<
feetToCentimeters(lengthInFeet) << " centimeters." << endl;
return 0;
}

PUTTING CODE IN DEV C ++:


RESULT AFTER RUNNING:

Q2. Write compile and run the code that can determine value from
two values be generating input.

CODE

#include <iostream>

using namespace std;

int main() {
double value1, value2, largest;

cout << "Enter the first value: ";


cin >> value1;

cout << "Enter the second value: ";


cin >> value2;

// Determine the largest value


if (value1 > value2) {
largest = value1;
} else {
largest = value2;
}

cout << "The largest value is: " << largest << endl;

return 0;
}

PUTTING CODE IN DEV C++


RESULT AFTER RUNNING

Q3. Write compile and run a code that can read 3 numbers and can
tells the largest number.

CODE
#include <iostream>

using namespace std;

int main() {
double num1, num2, num3, largest;

cout << "Enter the first number: ";


cin >> num1;
cout << "Enter the second number: ";
cin >> num2;

cout << "Enter the third number: ";


cin >> num3;

largest = num1; // Assume num1 is the largest initially

if (num2 > largest) {


largest = num2;
}

if (num3 > largest) {


largest = num3;
}

cout << "The largest value is: " << largest << endl;

return 0;
}

PUTTING CODE IN DEV C++


RESULT AFTER COMPILING
Q4. Write a program in which If Nested used.

CODE
#include <iostream>

using namespace std;

int main() {
int marks;

cout << "Enter your marks: ";


cin >> marks;

if (marks >= 40) {


cout << "You passed the exam!" << endl;

if (marks >= 90) {


cout << "Congratulations! You achieved distinction." <<
endl;
}
} else {
cout << "You failed the exam." << endl;
}

return 0;
}

RUNNING IN DEV C++


RESULT AFTER COMPILING

You might also like