Question

using c# visual studio 3.28 (Digits of an Integer) Write an app that inputs one number...

using c# visual studio

3.28 (Digits of an Integer) Write an app that inputs one number consisting of five digits from the user, separates the number into its individual digits and displays the digits separated from one another by three spaces each. For example, if the user types 42339, the app should display

4 2 3 3 9

Assume that the user enters the correct number of digits. What happens when you execute the app and type a number with more than five digits? What happens when you execute the app and type a number with fewer than five digits? [Hint: It’s possible to do this exercise with the techniques you learned in this chapter. You’ll need to use both division and remainder operations to “pick off” each digit.]

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

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new console application in c# is created using Visual Studio with name "Demo_DigitsofanInteger".This application contains a class with name "Program.cs".Below is the code for this class.

Program.cs :

//namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace Demo_DigitsofanInteger
{
//class
class Program
{
//Main method
static void Main(string[] args)
{
//declaring variable
int number, digit, i = 4;
//declaring array
int[] numArray = new int[5];
string numberWithSpace = String.Empty;
//Asking user to Enter Number
Console.WriteLine("Enter Five digit number");
//reading number
number = int.Parse(Console.ReadLine());
//number will loop until number is greater than 0
while (number > 0)
{
//as num is integer this statement will return last digit
digit = number % 10;
//storing digit in array
numArray[i] = digit;
//dividing number by 10
number = number / 10;
i--;//decrementing value of i
}
//for loop is used for space
for (int j = 0; j < numArray.Length; j++)
{
//add space after each number from array
numberWithSpace = numberWithSpace + numArray[j] + " ";   
  
}
//displaying number with space
Console.WriteLine("Number seprated with three spaces :" + numberWithSpace);
}
}
}

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

Output : Run application using F5 , will get the screen as shown below

Screen 1 :Screen asking user to Enter five digit number

Screen 2 : Screen when number separated with space

Screen 3 :Screen when less then five digit number is entered

Screen 4 : Screen when greater then five digit number is entered

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
using c# visual studio 3.28 (Digits of an Integer) Write an app that inputs one number...
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
  • Using C# to build this program   Digits of an Integer (Project Name: DigitParser) - Write an...

    Using C# to build this program   Digits of an Integer (Project Name: DigitParser) - Write an app that inputs one number consisting of five digits from the user, separates the number into its individual digits and displays the digits separated from one another by three spaces each. For example, if the user types 42339, the app should display 4 2 3 3 9 Assume that the user enters the correct number of digits. What happens when you execute the app...

  • Write an application (SpaceDigits) that: (in java) a. inputs one number consisting of five digits from...

    Write an application (SpaceDigits) that: (in java) a. inputs one number consisting of five digits from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in the number 42339, the program should print “4 2 3 3 9.” (Hint: The number input is five digits long, dividing it by 10000 gives the leftmost digit. digit1 = number / 10000 ) b. determines...

  • Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program...

    Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program that works as described in the following scenario: The user enters a credit card number. The program displays whether the credit card number is valid or invalid. Here are two sample runs: Enter a credit card number as a long integer: 4388576018410707 4388576018410707 is valid Enter a credit card number as a long integer: 4388576018402626 4388576018402626 is invalid To check the validity of the...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • This is in C++ (using IDE Visual Studio). I am seeking assistance ASAP. Please include a...

    This is in C++ (using IDE Visual Studio). I am seeking assistance ASAP. Please include a static member in the class to automatically assign account numbers (used to process up to 10 accounts) and have the user include their first and last name. Thank you! 13. a. Define the class bankAccount to store a bank customer's account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide...

  • My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all th...

    My C++ program is not compiling. Please explain how you fixed with detailed inline comments. I am using Visual Studio 2017. It's a character count program that keeps and displays a count of all the upper, lower case and digits in a .txt file. The requirement is to use classes to implement it. -----------------------------------------------------------------HEADER FILE - Text.h--------------------------------------------------------------------------------------------- /* Header file contains only the class declarations and method prototypes. Comple class definitions will be in the class file.*/ #ifndef TEXT_H #define...

  • Hi any help is appreciated! I am using C++. The Julian Day Number (JDN) is a...

    Hi any help is appreciated! I am using C++. The Julian Day Number (JDN) is a sequential count of days since the beginning of the Julian Period. Day number zero corresponds to 1 January 4713 BCE. As a result of calendar reform in the 16th Century, we will only be computing day numbers since 15 October 1582 (which was the first day of the modern Gregorian calendar, having day number 2299161). 1 January 2001 was day number 2451911. To compute...

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