write a C++ program to accept two numbers, a float and an integer and display the following :-a) sum of two numbers in integer form b) sum of two numbers in float form
Answers
Answer:
#include <iostream>
using namespace std;
int main() {
int first_number, second_number, sum;
cout << "Enter two integers: ";
cin >> first_number >> second_number;
// sum of two numbers in stored in variable sumOfTwoNumbers
sum = first_number + second_number;
// prints sum
cout << first_number << " + " << second_number << " = " << sum;
return 0;
}
Answer: An integer is a data type that represents a whole number which can be positive, negative, or zero. Integers are usually used to count, measure, and label. They are stored in memory as a group of bits, where each bit represents a single number.
Explanation:
#include <iostream>
using namespace std;
int main()
{
float num1;
int num2;
cout << "Enter the first number: ";
cin >> num1;
cout << "Enter the second number: ";
cin >> num2;
int intSum = num1 + num2;
float floatSum = num1 + num2;
cout << "The sum of two numbers in integer form is " << intSum << endl;
cout << "The sum of two numbers in float form is " << floatSum << endl;
return 0;
}
The program above accepts two numbers, a float and an integer, and displays the sum of the two numbers in both integer and float form. This is accomplished by first prompting the user to enter the two numbers. The float number is stored in the float variable num1, while the integer number is stored in the integer variable num2.
Then, the sum of the two numbers are calculated. The integer sum is calculated by adding the two numbers and storing the result in the integer variable int Sum. The float sum is calculated by adding the two numbers and storing the result in the float variable float Sum.
To learn more about variable
https://brainly.in/question/24541836
https://brainly.in/question/8732556
#SPJ3