Tuesday, January 16, 2018

Write a program that reads in 7 natural numbers and then writes out how many of them are divisible by 4

#include <iostream>
using namespace std;

int main()
{
    cout << "Enter a number that might be divisible by 4: " << endl;

    for (int i = 0; i < 7; i++)
    {
        int x;
        cin >> x;

       if (x % 4 == 0)
        cout << "It's divisible by 4!" << endl;

       else
       cout << "It's NOT divisible by 4" << endl;
    }

    return 0;
}

Write a program that reads in one number specifying the length of the film in seconds and then writes out the length of the film in hours, remaining minutes and remaining seconds.

// Chapter 15 - Exercise 3
#include <iostream>
using namespace std;

int main()
{
    cout << "Enter length of movie in minutes: " << endl;

    int length;
    cin >> length;

    int a = length / 60, b = length % 60, c = b * 60;

    cout << a << "hours & " << b << "min & " << c << "sec" << endl;

    return 0;
}