9999
#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);
}
}
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);
}
}
}
you cant
scanf ("%[^\n]s", sentence);
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).
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 > b and a > c display a "is greatest" else if b > c display b "is greatest" else display c "is greatest". display " thank you". stop run.
/*PROGRAM TO ACCEPT TWO NUMBERS FROM THE USER AND PRINT THEIR MULTIPLICATION. */ #include<stdio.h> #include<conio.h> void main() { int a, b, c; // Declaration of Variables. Variables 'a' & 'b' to hold first & 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", &a); // To accept the first number. printf("\n Enter the second number : "); scanf("%d", &b); // To accept the second number. c = a*b; // Logic to get the product of the entered two numbers. printf("\n Multiplication of %d & %d = %d", a, b, c); // Displaying result. getch(); // To hold the output screen. }
public class PrintOctal { public static void main(String[] args) { int n = Integer.parseInt(args[0]); System.out.printf("%o\n", n); } }
Farmers produce. Farmers Produce Farmers Produce
dim a input a
write a c program to accept a number and generate a square root cube and exponential values
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 .
computer
you cant
no university in the world
scanf ("%[^\n]s", sentence);
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.
happy birthday...
Write a program to accept name and store the name in its short form (e.g. Sikkim Manipal University should be stored as SMU)