Question #60476

(i)Write a C++ Program to accept a four digit number and print whether it is an odd or even number.write a program to print the digits of the number in reverse order.(e.g 1234 is an even number.The reverse of the number is 4321)
(ii) Give an example of implicit conversion
(iii) If you want to store marks of the ten students in memory.What Would you prefer array or structure? Give reason.
1

Expert's answer

2016-06-24T09:04:02-0400

Answer on Question #60476, Programming & Computer Science / C++

i. Write a C++ Program to accept a four digit number and print whether it is an odd or even number. Write a program to print the digits of the number in reverse order. (e.g 1234 is an even number. The reverse of the number is 4321:


#include <iostream>
using namespace std;
void revers(int n)
{
    cout << n % 10;
    if (n / 10 != 0)
        revers(n / 10);
}
int main()
{
    int number;
    cout << "Enter the number: ";
    cin >> number;
    if (number & 1) cout << "Odd number.\n";
    else cout << "Even number.\n";
    cout << "Revers: ";
    revers(number);
    cout << endl;
    system("pause");
    return 0;
}


ii. Give an example of implicit conversion:


#include <iostream>
using namespace std;
int main()
{
    int number1;
    float result, number2;
    cout << "Enter the first number: ";
    cin >> number1;
    cout << "Enter the second number: ";
    cin >> number2;
    result = number1 / number2;
    cout << "Compiler implicit conversion to float type";
    cout << "\nResult: " << result << endl;
    system("pause");
    return 0;
}


iii. If you need to store the information of the same type, it is better to use arrays. If your program needs to store related information of different types, it can use the structure. The structure is a variable, grouping related pieces of information, called elements, types of which may vary. By grouping the data in one variable in this way, you simplify your program by reducing the number of variables that must be managed, passed to functions.

http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS