Question

In this example you are allowed to use from the C standard library only functions for...

In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf())

For this exercise you should be able to write a logical expression (i.e., with logical operators) which checks if some integer x consists of exactly 5 digits. Ex: 30498 and -14004 are 5-digit numbers, while 1018, -2 and 46 are not.

Complete the intQ2(intQ2_input) function that takes an input integer parameter and returns 1 if the number is five digits and 0.

Homework Answers

Answer #1

Answer;

Explanation:

Here is the function in Bold below which takes an integer input and then counts the number of digits present in that number.

If the digits are 5, it returns 1

Otherwise it returns 0.

Code:


#include <stdio.h>

int intQ2(int intQ2_input)
{
int digits = 0;
  
if(intQ2_input<0)
intQ2_input = -intQ2_input;
  
while(intQ2_input>0)
{
intQ2_input = intQ2_input/10;
digits = digits + 1;
}
  
if(digits==5)
return 1;
else
return 0;
}

int main()
{
printf("%d", intQ2(-14004));

return 0;
}

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!

Know the answer?
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
Similar Questions
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: a) Complete the int Q7a(intQ7_input) function takes a seven-digit positive integer as input and returns it reversed. For example, if the integer is 9806593, the program should print 3956089. You are not permitted to use any function of C standard library other than scanf()and printf().You are not permitted to use...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: Calculate the value of π from the infinite series: π = 4 – 4/3 + 4/5 – 4/7 + 4/9 – 4/11 + … Complete the double Q4(intQ4_input) function which reads a positive integer Q4_input as an input parameter and calculates the value of π by adding up the first...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following function using C programming language: Complete the function intQ3(floatQ3_input) that takes a student’s average as an input, which is a floating-point value, and returns: 4 if the average is in the range 90-100, 3 if it is in the range 80-89, 2 if it is in the range 70-79, 1 if it is in the...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: intQ1_for() intQ1_while() intQ1_do() To compute the sum of all numbers that are multiples of 4, between 30 and 1000, in 3 different ways: with a for loop, a while loop and a do-while loop, accordingly. After each loop print the value. Return the total sum at the end of each...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: A positive integer number is said to be a perfect number if its positive factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6=1+2+3. Complete the int Q6(intQ6_input, int perfect[])function that determines all perfect numbers smaller than or equal...
In Python: This will require you to write several functions, and then use them in a...
In Python: This will require you to write several functions, and then use them in a program. Logical Calculator The logical calculator does math, but with logical operators. In logic, we represent a bit with 0 as false and a bit with 1 as true. The logical operators are NOT, AND and OR. Bitwise logical calculations operate on each bit of the input. The NOT operator works on just one three-bit argument. NOT 011 = 100 The AND operator works...
This question is broken into 3 parts, each of which builds on the functions developed in...
This question is broken into 3 parts, each of which builds on the functions developed in the previous part. Note that you can (and should) still answer parts (b) and (c) even if you cannot answer the preceding parts - just assume that the functions work as they should, and continue. Please explain the code as well Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The...
using dr.racket programing language If we write a function that tests whether a list contains only...
using dr.racket programing language If we write a function that tests whether a list contains only strings, odd numbers, or even numbers, you will notice that the code that iterates through the list stays the same, with the only change being the predicate function that checks for the desired list element. If we were to write a new function for each of the tests listed above, it would be more error-prone and an example of bad abstraction. We could write...
in Java In this exercise, you'll write a Java version of the infix-to-postfix conversion algorithm. These...
in Java In this exercise, you'll write a Java version of the infix-to-postfix conversion algorithm. These same mechanisms can be used as a part of writing a simple compiler. Write class InfixToPostfixConverter co convert an ordinary infix arithmetic expression (assume a valid expression is entered) with single-digit integers (to make things easier) such as (6 + 2) • 5 - 8 / 4 to a postfix expression. The postfix version (no parentheses are needed) of this infix expression is 6...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...