#include <stdio.h> //************************************** // Name: factors.c // Description:prints ALL the factors of number(s).. doesn't matter how many arguments you take, it'll calculate them all. // Inputs:./factors 256 512 18273 65536 981 numbers numbers numbers...... // // Returns:Factors of 981 are : +1, -1, +3, -3, +9, -9, +109, -109, +327, -327, +981, and -981 Factors of 65536 are : +1, -1, +2, -2, +4, -4, +8, -8, +16, -16, +32, -32, +64, -64, +128, -128, +256, -256, +512, -512, +1024, -1024, +2048, -2048, +4096, -409 6, +8192, -8192, +16384, -16384, +32768, -32768, +65536, and -65536 and so on.... // //Assumes:None // //Side Effects:None //************************************** #include <stdio.h> main(int argc, char *argv[]) { int fac; if(argc < 2) { printf("Usage: %s numbers, number, numbe, numb, num, nu, n, etc...\n", argv[0]); return 0; } for( ; argc > 1 ; argc--) { printf("Factors of %d are :", atoi(argv[argc-1])); for(fac=1 ; fac <= atoi(argv[argc-1]) ; fac++) { if(!(atoi(argv[argc-1])%fac)) { if(fac!=atoi(argv[argc-1])) printf(" +%d, -%d%s", fac, fac, (fac!=atoi(argv[argc-1])) ? "," : " "); else printf(" +%d, and -%d%s", fac, fac, (fac!=atoi(argv[argc-1])) ? "," : " "); } } putc('\n', stdout); } return 0; }
Hosted by www.Geocities.ws

1