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

NAMA : IRFA IRSYA BINTI SUHAIZAN

NO MATRIC : BI22160523

ANSWER LAB 2
___________________________________________________________________________________
_______________

PRACTICE 1 :

#include <iostream>
using namespace std;
#define YEAR 1990

int main()
{
/*

Predicted Sabah state population for 2022 (in thousands) :123.854

*/
short int year;
cout << "POPULATION GROWTH ESTIMATION";
cout << "***********";
cout << "Enter a year after " << YEAR << ":";
cin >> year;

unsigned short int y = year - YEAR;

float result = 53.966 + (2.184 * y);

cout << "Predicted Sabah state population for 2022 (in thousands) :" << result;

return 0;

PRACTICE 2 :

#include <iostream>
using namespace std;

int main()
{
cout << "Please enter a positive integer between 0 and 65535: ";

unsigned short int numberInput;


cin >> numberInput;

unsigned short int d1 = numberInput % 10;


unsigned short int d2 = numberInput % 100 / 10;
unsigned short int d3 = numberInput % 1000 / 100;
unsigned short int d4 = numberInput % 10000 / 1000;
unsigned short int d5 = numberInput % 100000 / 10000;

cout << "The forward sequence : " << d5 << d4 << d3 << d2 << d1 << endl;
cout << "The reversed sequence : " << d1 << d2 << d3 << d4 << d5 << endl;

return 0;
}

PRACTICE 3 :

#include <iostream>
using namespace std;

int main()
{
cout << "Please enter a positive four-digit integer: ";

int numberInput;
cin >> numberInput;

int d1 = (numberInput % 10 + 7) % 10;


int d2 = (numberInput % 100 / 10 + 7) % 10;
int d3 = (numberInput % 1000 / 100 + 7) % 10;
int d4 = (numberInput % 10000 / 1000 + 7) % 10;

cout << "The encrypted value is: " << d4 << d1 << d3 << d2 << endl;

return 0;
}

You might also like