Knowee
Questions
Features
Study Tools

Design a program that mimics a digital calculator. Take an integer as input, use a function named sumOfDigits with a pointer to calculate the sum of its digits, and display the result. This simulates the process of manually adding up the individual digits of a number as you would on a calculator.Note: This question helps in clearing Wipro technical coding tests.Input format :The input consists of an integer N.Output format :The output prints an integer representing the sum of digits of N.Code constraints :1 ≤ N ≤ 105Sample test cases :Input 1 :123Output 1 :6Input 2 :5698Output 2 :28Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks : 10Negative Marks : 0

Question

Design a program that mimics a digital calculator. Take an integer as input, use a function named sumOfDigits with a pointer to calculate the sum of its digits, and display the result. This simulates the process of manually adding up the individual digits of a number as you would on a calculator.Note: This question helps in clearing Wipro technical coding tests.Input format :The input consists of an integer N.Output format :The output prints an integer representing the sum of digits of N.Code constraints :1 ≤ N ≤ 105Sample test cases :Input 1 :123Output 1 :6Input 2 :5698Output 2 :28Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.Marks : 10Negative Marks : 0

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple C++ program that fulfills your requirements:

#include<iostream>
using namespace std;

int sumOfDigits(int *num) {
    int sum = 0;
    while(*num > 0) {
        sum += *num % 10;
        *num /= 10;
    }
    return sum;
}

int main() {
    int N;
    cin >> N;
    cout << sumOfDigits(&N);
    return 0;
}

This program works as follows:

  1. It includes the necessary libraries.
  2. It defines a function sumOfDigits that takes a pointer to an integer as an argument. This function calculates the sum of the digits of the number pointed to by the pointer.
  3. In the main function, it takes an integer N as input.
  4. It calls the sumOfDigits function with the address of N as the argument (which is effectively a pointer to N), and prints the result.
  5. It returns 0 to indicate successful termination of the program.

This program should be able to pass the Wipro technical coding test.

This problem has been solved

Similar Questions

James, a mathematics teacher, is developing a programming exercise to help his students practice continuously summing the digits of a number until it becomes a single-digit integer. He wants to create a simple program using a 'while' loop that takes a positive integer input and generates the final single-digit result. Input format :The input consists of a positive integer n.Output format :The output prints "The single-digit sum of n is Y." where n is the input integer and Y is its single-digit sum.Refer to the sample output for formatting specifications.Code constraints :1 ≤ n ≤ 1010Sample test cases :Input 1 :456Output 1 :The single-digit sum of 456 is 6.Input 2 :999Output 2 :The single-digit sum of 999

Java program that reads an integer between 0 and 1000 and adds all the digits in the integerWrite a Java program that reads an integer between 0 and 1000 and adds all the digits in the integer.An integer is a number that can be written without a fractional component. For example, 23, 6, 0, and −1245 are integers, while 3.25, ​7 1⁄2, and √3 are not. Click on the image for preview.Constraints:N/AExample:Inputan integer between 0 and 1000: 565Output:The sum of all digits in 565 is 16Explanation:-Public Test Cases:# INPUT EXPECTED OUTPUT1 56516

Sum of digitsA function, sumN, is defined that takes an integer n as argument and returns the sum of the integers from 1 through n. Write a C program to determine value of the expression shown below?  sumN(3456) - sumN(3455)Note: the arguments of function sumN() can be obtained from user at runtimeTestcases:Input:18041604Output:2Input:34563455Output:1

You need to create an app that calculates the sum of the numbers 1 to N, where N is taken from input.For example, for the number 5, the output should be 15, because 1+2+3+4+5=15.

Single File Programming QuestionProblem StatementOlivia is a curious mind exploring the world of digits. Create a simple program to assist Olivia in understanding the addition of the last two digits of a given number. Prompt Olivia to input an integer n, calculate, and display the sum of the last two digits.Input format :The input consists of an integer n.Output format :The output displays the sum of the last two digits of the input integer.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:10 ≤ n ≤ 105Sample test cases :Input 1 :10Output 1 :1Input 2 :231Output 2 :4Input 3 :7896Output 3 :15Input 4 :100000Output 4 :0Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.