answersLogoWhite

0


Best Answer

9999

User Avatar

Romaine Aufderhar

Lvl 10
3y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

#include<stdio.h>

main()

{

int N,num,sum=0;

do

{

printf("Enter a number:\n");

scanf("%d",&N);

if((N>9999)(N<0))

{

printf("Wrong Number\n");

}

while((N>9999))(N<0));

num=N;

while(N>0)

{

sum=sum+N%10;

N=N/10;

}

printf("Sum of digits of the number%d is%d",N,sum);

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

I don't have a C compiler, I used to, not anymore. I know this is not what you want. But I have coded it in C#. May be you can translate to C. I will keep looking for a C compiler and update the answer if successful. In the meantime, see if you can use the following.

using System;

using System.Collections.Generic;

using System.Linq;

namespace SumDigits

{

class Program

{

static void Main(string[] args)

{

int i;

int ierr;

int isumofdigits;// To store sum of digits

string strInput;// Define input string

string strOutput;// Define output string

string str4Digits;// Define string to hold 4 digits

do

{

ierr = 0;

strInput = "";

Console.WriteLine("Enter a number between 0 and 9999, / to Exit");// Prompt the user

strInput = Console.ReadLine();//Read input from keyboard

if (strInput.Length != 0)// Check if not zero length

{

if (strInput.Substring(0, 1) != "/") // Check if not "/"

{

if (strInput.Length > 4)// Check if more than 4 characters

str4Digits = strInput.Substring(0, 4);// Get utmost 4 characters

else

str4Digits = strInput.Substring(0, strInput.Length);// Else get chars entered

for (i = 0; i < str4Digits.Length; i++)// Do this loop for length of 4 digit buffer

{

char ch;// Define temporary character

ch = Convert.ToChar(str4Digits.Substring(i, 1));// Convert character from 4 digit string to chars

if (!(char.IsDigit(ch)))// Check if character is a digit (0 -9)

{

Console.WriteLine("One or more digits entered is not numeric");// Error message

ierr = 1;

break;

}

}

if (ierr "/")// User entered "/"

{

Console.WriteLine("Thanks for using the program");// Display parting message

Console.WriteLine("Press the Enter Key to End Program");// Display prompt message

Console.ReadLine();// Wait for user acknowledgement

break;

}

}

else//User entered nothing, continue

{

continue;

}

} while (true);

}

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What a C program that will accept an integer N as input if and only if that integer N lies within 0-9999 Then it will produce the summation of its digits and lastly prints the integer as well as the?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How to write a program to accept the user name and password and then shop this is your Password?

you cant


C program to accept a sentence using scanf?

scanf ("%[^\n]s", sentence);


How do you write a program for counting and displaying occurrence of a number in an array?

Your first step is accepting input, which is done using the scanf() function:scanf("%d", &number);This means that you want scanf() to accept input, convert the input to a number, and store it in the memory at the address of number.Use a for() loop, counting from 0 to 9, and an array of integers to hold the numbers. Then simply scanf("%d", &intarray[counter]);The next step is a little tricky, but not very if you plan it out in advance.Each integer can contain 256, 65,536 or 4,294,967,296 different numbers. Creating an array to hold the count of each of those numbers is a waste of RAM.Instead, you'll want an "associative" array as follows:int numcount[MAXNUM][2];MAXNUM is 10, or the number of integers in the array you're checking. The second dimension, 2, consists of the number and its count.Obviously, you'll want a way to keep track of how many integers you've stored in numcount. An int called numcountnuminitialized to 0 would be the fastest way.Use a for() loop to iterate through the integers. If the integer does not exist in numcount, then set numcount[numcountnum][0] to the integer, set numcount[numcountnum][1] to 1, and increment numcountnum. Otherwise, if the integer exists, increase numcount[the integer index][1].Once the for() loop is finished, display the results. The only thing you have left to figure out is the function that searches the numcount array for an integer, and returns its index (or -1 if it's not found).


Write a program in COBOL to find the largest of N number?

identification division. program-id. greatest. environment division. data division. working-storage section. 77 a pic 999. 77 b pic 999. 77 c pic 999. procedure division. greatest. display "ENTER THE THREE NUMBERS:". accept a. accept b. accept c. if a &gt; b and a &gt; c display a "is greatest" else if b &gt; c display b "is greatest" else display c "is greatest". display " thank you". stop run.


A c program for multiplication of two integers a and b?

/*PROGRAM TO ACCEPT TWO NUMBERS FROM THE USER AND PRINT THEIR MULTIPLICATION. */ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int a, b, c; // Declaration of Variables. Variables 'a' &amp; 'b' to hold first &amp; second number. And 'c' to hold result. clrscr(); // To clear the output screen every time program is executed. printf("\n Enter the first number : "); scanf("%d", &amp;a); // To accept the first number. printf("\n Enter the second number : "); scanf("%d", &amp;b); // To accept the second number. c = a*b; // Logic to get the product of the entered two numbers. printf("\n Multiplication of %d &amp; %d = %d", a, b, c); // Displaying result. getch(); // To hold the output screen. }

Related questions

What is a program to accept a 3 digit integer and display its octal conversion value?

public class PrintOctal { public static void main(String[] args) { int n = Integer.parseInt(args[0]); System.out.printf("%o\n", n); } }


What did rich's accept in lieu of paper money during the Great Depression?

Farmers produce. Farmers Produce Farmers Produce


How do you write BASIC program to accept variables?

dim a input a


Write a c program to accept a numbers and generate square root cube and exponential values?

write a c program to accept a number and generate a square root cube and exponential values


Why does Java accept any input as string by default?

Java doesn't always accept any input as a string it only do that when the input is entered from the " JOptionPane.InputDialog" but it can accept any other data type like integer or short from the console though Scanner class .


Can accept and process data and produce and store information for future use?

computer


How to write a program to accept the user name and password and then shop this is your Password?

you cant


Colleges who accept 5.5 band in Canada under spp program?

no university in the world


C program to accept a sentence using scanf?

scanf ("%[^\n]s", sentence);


What is the computer definition of launch?

Launching is where a new computer program is loaded from disk, copied into memory and then the program goes through its startup routines. A program is launched when it is ready to accept user input.


Write a c program to accept name and store the name in its short form?

happy birthday...


Write a program to accept name and store the name in it's short form as eg sikkim manipal university SMU?

Write a program to accept name and store the name in its short form (e.g. Sikkim Manipal University should be stored as SMU)