1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
krok68 [10]
2 years ago
6

Write a program that accepts a number as input, and prints just the decimal portion.

Computers and Technology
2 answers:
Olegator [25]2 years ago
8 0

<u>Answer:</u>

<em>There are 2 ways to do extract the decimal part: </em>

<u>Explanation:</u>

  • <em>First method using number  </em>

<em>int main() { </em>

<em>  double num = 23.345; </em>

<em>  int intpart = (int)num; </em>

<em>  double decpart = num - intpart; </em>

<em>  printf(""Num = %f, intpart = %d, decpart = %f\n"", num, intpart, decpart); </em>

<em>} </em>

  • <em>Second method using string: </em>

<em>#include <stdlib.h> </em>

<em>int main() </em>

<em>{ </em>

<em>    char* inStr = ""123.4567"";          </em>

<em>    char* endptr;                       </em>

<em>    char* loc = strchr(inStr, '.'); </em>

<em>    long mantissa = strtod(loc+1, endptr); </em>

<em>    long whole = strtod(inStr, endptr);  </em>

<em>    printf(""whole: %d \n"", whole);      </em>

<em>    printf(""mantissa: %d"", mantissa);   </em>

<em>} </em>

kirill [66]2 years ago
5 0

Answer:

The program to this question can be given as:

Program:

#include <iostream> //header file

using namespace std;

void cal(double number) //defining method cal

{

double decimal_part; //defining variable

int integer_part; //defining variable

integer_part = (int)number; //type casting

decimal_part = number - integer_part;  //holding decimal value

cout<<"number you inserted :"<<number<<endl;  //print value

cout<<"integer part :"<<integer_part<<endl;  //print integer part

cout<<"decimal part :"<<decimal_part<<endl; // print decimal part

}

int main()  //defining main method

{

double number; //defining variable number

cout<<"Input floating point number :"; //message

cin>>number; //taking input from user

cal(number); //calling function and passing value in function

return 0;  

}

Output:

Input floating point number :786.786

number you inserted :786.786

integer part :786

decimal part :0.786

Explanation:

  • In the above C++ language program, firstly include a header file then define a method that is "cal". This method accepts a double parameter and returns nothing because its return type is void.
  • Inside a method, two variable is defined that is "integer_part and decimal_part". In which variable integer_part is an integer variable that holds only integer value and variable decimal_part is used to holds decimal value only and to print function calculated value the cout (print function).
  • In the main method, a variable number defines that datatype is a double type that accepts a decimal or floating-point value from user input and passes the value in the function parameter and call the function.
You might be interested in
write a script to check command arguments. Display the argument one by one (use a for loop). If there is no argument provided, r
algol13

Answer and Explanation:

Using Javascript programming language, to write this script we define a function that checks for empty variables with if...else statements and then uses a for loop to loop through all arguments passed to the function's parameters and print them out to the console.

function Check_Arguments(a,b,c){

var ourArguments= [];

if(a){

ourArguments.push(a);}

else( console.log("no argument for a"); )

if(b){

ourArguments.push(b);}

else( console.log("no argument for b"); )

if(c){

ourArguments.push(c);}

else( console.log("no argument for c"); )

for(var i=0; i<ourArguments.length; i++){

Console.log(ourArguments[i]);

}

}

4 0
2 years ago
Some technologies like vertical farming have a number of negative effects. Which is a negative outcome of this technology? A. In
Tanya [424]
<span>Vertical farming is the exercise of creating foodstuff and medication in sheer laden layers, vertically inclined exteriors and/or combined in other structures. The modern thoughts of vertical farming use indoor farming methods and controlled-environment agriculture (CEA) technology, where all environmental issues can be well-ordered. So knowing all of this, the negative outcome would be D.</span>
4 0
3 years ago
Create an integer variable named ‘listSize’ and initialize the value to 1000.
Natalija [7]

Answer:

The code is given in C++. The variable name is arraySize. It should be replaced with listSize

Explanation:

// header file

#include<iostream>

#include<fstream>

#include<cstdlib>

#include<chrono>

using namespace std;

using namespace std::chrono;

// bubble sort algorithm

void bubbleSort(int *a, int size) {

for (int i = 0; i<size - 1; i++) {

for (int j = 0; j<size - i - 1; j++) {

if (a[j]>a[j + 1]) {

//swap

int temp = a[j];

a[j] = a[j + 1];

a[j + 1] = temp;

}

}

}

}

// selection sort

void selectionSort(int *a, int size) {

for (int i = 0; i<size - 1; i++) {

int m_i = i;

for (int j = i + 1; j<size; j++) {

if (a[j]<a[m_i]) {

m_i = j;

}

}

//swap

int temp = a[i];

a[i] = a[m_i];

a[m_i] = a[i];

}

}

// insertion sort

void insertionSort(int *a, int size) {

for (int i = 1; i<size; ++i) {

int key = a[i];

int j=i-1;

for (; (j >= 0 && key < a[j]); j--) {

a[j + 1] = a[j];

}

a[j + 1] = key;

}

}

// make partition on array

int getPartition(int *a, int l, int h) {

int pvt = a[h];

int i = (l - 1);

for (int j = l; j <= h - 1; j++) {

if (a[j]<pvt) {

i++;

//swap

int tmp = a[i];

a[i] = a[j];

a[j] = tmp;

}

}

//swap

int tmp = a[i + 1];

a[i + 1] = a[h];

a[h] = tmp;

return(i + 1);

}

// quick sort

void quickSort(int *a, int l, int h) {

if (l<h) {

int p = getPartition(a, l, h);

quickSort(a, l, p - 1);

quickSort(a, p + 1, h);

}

}

// merge array

void merge(int *a, int l, int m, int r) {

int n1 = m - l + 1;

int n2 = r - m;

int *L = new int[n1];

int *R = new int[n2];

for (int i = 0; i<n1; i++) {

L[i] = a[i + l];

}

for (int j = 0; j<n2; j++) {

R[j] = a[m + j + 1];

}

int i = 0, j = 0, k = 1;

while (i<n1 && j<n2) {

if (L[i] <= R[j]) {

a[k] = L[i];

i++;

}

else {

a[k] = R[j];

j++;

}

k++;

}

while (i<n1) {

a[k] = L[i];

i++;

k++;

}

while (j<n2) {

a[k] = R[j];

j++;

k++;

}

}

// merge sort

void mergeSort(int *a, int l, int r) {

if (l<r) {

int m = l + (r - l) / 2;

mergeSort(a, l, m);

mergeSort(a, m + 1, r);

merge(a, l, m, r);

}

}

int* randomData(int size) {

int *ar = new int[size];

for (int i = 0; i<size; i++) {

ar[i] = rand();

}

return(ar);

}

void copyAry(int *a, int *b, int size) {

for (int i = 0; i < size; i++) {

a[i] = b[i];

}

}

int main() {

int arraySize = 1000;

int *arrLst = new int[arraySize];

int *arLst = new int[arraySize];

arrLst = randomData(arraySize);

//copy array

// because after sorting arry will be sorted

copyAry(arLst, arrLst, arraySize);

auto start1 = high_resolution_clock::now();

bubbleSort(arLst, arraySize);

auto end1 = high_resolution_clock::now();

auto duration1 = duration_cast<microseconds>(end1 - start1);

cout << duration1.count()<<endl;

// copy array for new sort

copyAry(arLst, arrLst, arraySize);

auto start2 = high_resolution_clock::now();

selectionSort(arLst, arraySize);

auto end2 = high_resolution_clock::now();

auto duration2 = duration_cast<microseconds>(end2 - start2);

cout << duration2.count() << endl;

// copy array for new sort

copyAry(arLst, arrLst, arraySize);

auto start3 = high_resolution_clock::now();

insertionSort(arLst, arraySize);

auto end3 = high_resolution_clock::now();

auto duration3 = duration_cast<microseconds>(end3 - start3);

cout << duration3.count() << endl;

// copy array for new sort

copyAry(arLst, arrLst, arraySize);

auto start4 = high_resolution_clock::now();

mergeSort(arLst, 0,arraySize-1);

auto end4 = high_resolution_clock::now();

auto duration4 = duration_cast<microseconds>(end4 - start4);

cout << duration4.count() << endl;

// copy array for new sort

copyAry(arLst, arrLst, arraySize);

auto start5 = high_resolution_clock::now();

quickSort(arLst, 0,arraySize-1);

auto end5 = high_resolution_clock::now();

auto duration5 = duration_cast<microseconds>(end5 - start5);

cout << duration5.count() << endl;

ofstream out("GroupAssignment2Results.csv");

out << "Array Size,Bubble Sort Time,Selection Sort Time,Insertion Sort Time,Quick Sort Time,Merge Sort Time\n";

out << arraySize << "," << duration1.count() << "," << duration2.count() << "," << duration3.count() << "," << duration5.count() << "," << duration4.count();

cout << "\nOutput in File.";

out.close();

cin.get();

return(0);

}

3 0
3 years ago
printLarger is a method that accepts two int arguments and returns no value. Two int variables, sales1 and sales2, have already
gizmo_the_mogwai [7]

Answer:

<em>public static void printLarger(double sales1, double sales2){</em>

<em>        if (sales1>sales2){</em>

<em>            System.out.println(sales1+" is larger");</em>

<em>        }</em>

<em>        else {</em>

<em>            System.out.println(sales2+" is larger");</em>

<em>        }</em>

<em>    }</em>

<em>A complete code calling the printLarger method is given below</em>

Explanation:

<em>public class Larger{</em>

<em>    public static void main(String[] args) {</em>

<em>        int sales1 = 100;</em>

<em>        int sales2 = 120;</em>

<em>        printLarger(sales1,sales2);</em>

<em>    }</em>

<em>public static void printLarger(int sales1, int sales2){</em>

<em>        if (sales1>sales2){</em>

<em>            System.out.println(sales1+" is larger");</em>

<em>        }</em>

<em>        else {</em>

<em>            System.out.println(sales2+" is larger");</em>

<em>        }</em>

<em>    }</em>

}

6 0
3 years ago
1. Define lexemes. Give an example of an lexeme in any programming language.<br>​
tresset_1 [31]

The correct answer is; " a unit of lexical meaning that underlies a set of words that are related through inflection."

Further Explanation:

The lexeme is part of the stream where the tokens are taken and identified from. When these streams become broken, there is always an error message. The lexeme is known as "the building blocks of language."

These are a very important part of computer programming. If any string or character is misplaced this can stop the entire program or operation.

One example of a lexeme is;

  • the symbols (, ), and -> are for the letter C.

Learn more about computer programming at brainly.com/question/13111093

#LearnwithBrainly

4 0
3 years ago
Other questions:
  • You just read an msds for acetic acid. based on what you read, what type of information is included in an msds sheet? record you
    7·1 answer
  • Which of the following is a Microsoft solution that runs on a Microsoft Terminal Services server but appears, to end users, as i
    10·1 answer
  • Ryan has created a Word document to be used as a review quiz for students in a classroom setting. The document contains both que
    6·1 answer
  • Match the part of motherboard to its function
    15·1 answer
  • Discuss two advantages and two disadvantages of agile methods.
    6·1 answer
  • Which of the following is not one of DBA's tasks?
    14·1 answer
  • Many people in modern society have the notion that hard disks can be searched in an hour and files can be recovered from inciner
    10·1 answer
  • 2. Discuss CORBA functions<br><br>​
    6·2 answers
  • Write long answer to the following question. a. Define microcomputer. Explain the types of microcomputers in detail.​
    5·2 answers
  • To what extent do you agree with the assertion that “Collection development begins with community analysis”. (Give reasons to bu
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!