0% found this document useful (0 votes)
41 views7 pages

Assignment 1

The document contains 6 C++ programs that demonstrate basic programming concepts like input/output, if/else statements, for loops, functions, and conversions. The programs include: 1) checking if a number is even or odd, 2) finding the maximum and minimum of two numbers, 3) calculating the product of the first 100 integers, 4) calculating the factorial of a number, 5) printing the Fibonacci sequence, and 6) converting temperatures between Celsius and Fahrenheit in a table.

Uploaded by

maythawtar266
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views7 pages

Assignment 1

The document contains 6 C++ programs that demonstrate basic programming concepts like input/output, if/else statements, for loops, functions, and conversions. The programs include: 1) checking if a number is even or odd, 2) finding the maximum and minimum of two numbers, 3) calculating the product of the first 100 integers, 4) calculating the factorial of a number, 5) printing the Fibonacci sequence, and 6) converting temperatures between Celsius and Fahrenheit in a table.

Uploaded by

maythawtar266
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment 1(C++)

Rollno.၁ကသ-၃၀
Name-Lay Pyay Pan Ei

1.
#include <iostream>
using namespace std;

int main() {
int number;
cout << "Enter a number: ";
cin >> number;
if (number % 2 == 0) {
cout << number << " is an even number.";
} else {
Cout << number << " is an odd number.";
}
return 0;
}
--------------------------------------------------

2.#include <iostream>
using namespace std;

int main() {
// Declare variables to store user input
int num1, num2;

// Prompt the user to enter the first number


cout << "Enter the first number: ";
cin >> num1;

// Prompt the user to enter the second number


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

// Check and print the maximum number


if (num1 > num2) {
cout << "Maximum number: " << num1<<"\n";
} else {
cout << "Maximum number: " << num2<<"\n";
}

// Check and print the minimum number


if (num1 < num2) {
cout << "Minimum number: " << num1<<"\n";
} else {
cout << "Minimum number: " << num2<<"\n";
}

return 0;
}

3.
#include <iostream>
using namespace std;
int main() {
unsigned long long product = 1;
for (int i = 1; i <= 100; ++i) {
product *= i;
}

cout << "Product of the first 100 integers: " << product;
return 0;
//can't show the right result because the product result is too long for variable
}
4.
#include <iostream>
using namespace std;
int main() {
// Declare variables
int number;
long long factorial = 1; // Use long long to handle larger results
cout << "Enter a number: ";
cin >> number;

if (number < 0)
{
cout << "Error: Factorial is not defined for negative numbers.";
}
else
{
for (int i = 1; i <= number; ++i)
{
factorial *= i;
}
cout << "Factorial of " << number << " is: " << factorial;
}

return 0;
}
5.
#include <iostream>
using namespace std;

int main() {
int numTerms;

cout << "Enter the number of Fibonacci terms: ";


cin >> numTerms;

if (numTerms <= 0) {
cout << "Please enter a positive integer for the number of terms.\n" ;
return 1;
}

int firstTerm = 1;
int secondTerm = 1;

cout << "Fibonacci sequence up to " << numTerms << " terms: ";

cout << firstTerm << " " << secondTerm << " ";

for (int i = 3; i <= numTerms; ++i) {


int nextTerm = firstTerm + secondTerm;
cout << nextTerm << " ";
firstTerm = secondTerm;
secondTerm = nextTerm;
}
cout<<"\n";

return 0;
}
6.
#include <iostream>

using namespace std;

int main() {
cout<<"fahrenheit centigrade\n";
for (int centigrade = 1; centigrade <= 100; ++centigrade) {
// Convert Centigrade to Fahrenheit
double fahrenheit = (centigrade * 9.0 / 5.0) + 32;

// Display in a simple format


cout << "\t"<<centigrade << " " << fahrenheit<<"\n";

// Add a newline every 20 Centigrade degrees


if (centigrade % 20 == 0) {
cout <<endl;
}
}

return 0;
}

You might also like