Question

Problem 1: Write a program that reads a positive float number and displays the previous and...

Problem 1: Write a program that reads a positive float number and displays the previous and next integers. Sample Run: Enter a float: 3.5 The previous and next integers are 3 and 4.

Problem 2: Write a program that reads two integers and displays their sum, difference, product, and the result of their division. Sample Run: Enter two integers: 8 5 Sum: 8, Difference: 3, Product: 40, Division: 1.6

Problem 3: Write a program that reads a three-digit integer from the keyboard and prints out the sum of its digits. The number entered by the user is guaranteed to be three-digit and will not start from a zero. You can use divisions by powers of 10 to isolate each of the digits. Sample Run: Enter an integer: 358 The digit sum of 358 is: 16

Problem 4: Write a program that reads a number that represents seconds and converts it into hours, minutes, and seconds. Sample Run: Enter the time in seconds: 8140 8140 seconds equal 2h, 15m, and 40s

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note:

As U didnt mentioned In which language you want me to develop ,I developed in c++.Plz tell me if u need this in Java ,Python,or c
Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

1)

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;


int main() {
   //Declaring variables
float a;
  
   cout<<"Enter a float :";
   cin>>a;
  
   cout<<"The previous and next integers are "<<floor(a)<<" and "<<ceil(a)<<endl;
  
   return 0;
}

========================

Output:

================================

2)

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;


int main() {
   //Declaring variables
int a,b;
  
   cout<<"Enter two integers :";
   cin>>a>>b;
  
   cout<<"Sum :"<<(a+b)<<endl;
   cout<<"Difference :"<<(a-b)<<endl;
   cout<<"Product :"<<a*b<<endl;
   cout<<"Division :"<<(float)a/b<<endl;
     
   return 0;
}

Output:

===============================

3)

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;


int main() {
   //Declaring variables
int a,sum=0;
  
   cout<<"Enter a number :";
   cin>>a;
  
   while(a>0)
   {
       sum+=a%10;
       a=a/10;
   }
  
   cout<<" Sum of digits :"<<sum<<endl;
  
     
   return 0;
}

Output:

=============================

4)

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;


int main() {
   //Declaring variables
int secs,hours,mins;
  
   cout<<"Enter the time in seconds: ";
   cin>>secs;
  
hours=secs/3600;
secs%=3600;
mins=secs/60;
secs%=60;
  
   cout<<secs<<" seconds equal "<<hours<<"h, "<<mins<<"m, and "<<secs<<"s"<<endl;

   return 0;
}

=====================Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Problem 1: Write a program that reads a positive float number and displays the previous and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java ((without using array)) 3. Write a program that reads a 7-digit number and then shuffles...

    Java ((without using array)) 3. Write a program that reads a 7-digit number and then shuffles its digits randon Sample run: Please enter a number 123456 Wrong too small! Sample run: Please enter a number: 1234567 The shuffled number is: 4356271 Sample run: Please enter a number 1000001 The shuffled number is: 0100100

  • Write a program that reads k integers and displays their sum. Write a program that reads...

    Write a program that reads k integers and displays their sum. Write a program that reads k values representing family income from the keyboard and place them into the array. Find the maximum income among these values. Count the families that make less than 10 percent of the maximum income. (JAVA)

  • Write a C program that reads in a float constant (use %f in scanf) and displays...

    Write a C program that reads in a float constant (use %f in scanf) and displays its internal representation in hex. Use your program to check your answers to problem 1. Hint: a union is like a struct except that the fields overlap. Hint: the conversion code for hex is %x. union X { int a; float b; }; int main() { union X test; ... ; test.a and test.b refer to same word in memory but have ; different...

  • Problem 1. A palindrome is a sequence of characters that reads the same backward as forward....

    Problem 1. A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value. Problem 2. Modify the program to determine whether a seven-digit number...

  • Write a C program which reads sets of two integers and displays them and their sum....

    Write a C program which reads sets of two integers and displays them and their sum. Continue readings sets of integers until their sum is zero, at which point terminate the program.

  • I need to write a C++ program that reads two integers from a data filed called...

    I need to write a C++ program that reads two integers from a data filed called "integers.dat" The first integer should be low and the other one high. The program should loop through all integers between the low and high values and include the low and high integers and then display Display the integers in the file Displays the number of integers divisible by 5 OR 6, but not both. Displays the sum of the integers from condition 2 as...

  • 1. Write a program that reads a sequence of numbers from the keyboard, and displays the...

    1. Write a program that reads a sequence of numbers from the keyboard, and displays the smallest number. The sequence has at least one number and is terminated by -999(-999 will not appear in the sequence other than as the end marker). 2. Write a program which requests an integer input n from the keyboard and computes the sum of square of k for all k from 1 to n(inclusive). use java

  • how to solve this on c++? Write a program that reads a five digits integer, then...

    how to solve this on c++? Write a program that reads a five digits integer, then swaps the unit position digit with the ten thousandth position digit, also swap the tenth position digit with the thousandth position digit. Print the new number For example if the number is 37846 then the new number is 64873. Sample input / output: nter a five digits integer The new form of the number 37846 is 64873

  • A java program Write a program that prompts for and reads in a positive    integer...

    A java program Write a program that prompts for and reads in a positive    integer into a variable n. Your program should then sum    the first n ODD integers and display the sum. For    example, if 3 is entered for n, your program should display    the the sum 1 + 3 + 5. If 5 is entered, your program should    display the sum 1 + 3 + 5 + 7 + 9. What is the...

  • In Java Write a program that reads an arbitrary number of 25 integers that are positive...

    In Java Write a program that reads an arbitrary number of 25 integers that are positive and even. The program will ask the user to re-enter an integer if the user inputs a number that is odd or negative or zero. The inputted integers must then be stored in a two dimensional array of size 5 x 5. Please create 3 methods: 1. Write a method public static int sum2DArray( int [1] inputArray ) The method sums up all elements...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT