Write a program to assign the number 34.5678 to a variable named number. First display number rounded to the nearest integer value and then display number rounded to two decimal places.
Answers
Answer:
#include <stdio.h> int main()
{
char first_letter; first_letter = ‘A’;
printf("Character %c\n", first_letter); //display character printf("ASCII value %d\n", first_letter); //display ASCII value return 0;
}
Explanation:
Answer:
The following C++ program will assign the number 34.5678 to a variable named number. It will display number rounded to the nearest integer value and then will display number rounded to two decimal places.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double number = 34.4576 ;
int i = int(number+0.5);
/* round() is used to round off the given digit and returns the nearest integral value to provided parameter in round function. */
int j = round(number);
cout << i << endl;
cout << j << endl;
/* ceil() function returns the smallest integer which is greater than the given integer and will round up to the nearest integer. */
float b = ceil(number * 100.0) / 100.0;
cout << b;
return 0;
}