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...........
How to use modulus division % in a C program??????
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;math.h%26gt;
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 %26lt; 5; index++) {
total += some_number % 10;
some_number = floor( some_number/10);
}
printf( "The sum is %d", total);
}
garden design
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment