English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

thr is a program given to me, where the user have to first enter a five digit number then its output will be the sum of those five digit number e.g. 12345 =15(o/p)
using modular division (%),,,,,,,,,,,
pls tell me the code in C..........
iam confused b'coz using array is not permitable...........

2007-02-11 03:36:27 · 2 answers · asked by smartboy 3 in Computers & Internet Programming & Design

2 answers

#include
#include
#include

int main(int argc, char *argv[])
{
// Add your method for inputting a value here.
int some_number = 12345;
//
int total = 0;
int index = 0;

for( index = 0; index < 5; index++) {
total += some_number % 10;
some_number = floor( some_number/10);
}

printf( "The sum is %d", total);
}

2007-02-11 06:32:51 · answer #1 · answered by Kookiemon 6 · 0 0

#contain iostream #contain cmath int substantial() {     int x, y, len = 0;     std::cout << "enter a 5 digit quantity: ";     std::cin >> x;     y = x;     mutually as ( y % 10 ) {         y = floor( y / 10 );         len++;     }     if ( len != 5 ) {         std::cout << "Invalid quantity";     } else {         for (int i = len - one million; i >= 0; i--) {             std::cout << (x % 10) << std::endl;             x /= 10;         }     } }

2016-12-17 14:08:33 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers