Hi,
I have to write a program that displays the nature of a number (perfect, defficient, or abundant) and DISPLAY ITS DIVISORS. and this is actually the bad part (lol). i have to use a while loop. i'll post it here what i've written so far. but it always displays a huge sam enumber as a divisor.
Could anybody correct me?? It's due on monday.
Thanks a lot.
Code:#include <stdio.h> int main (void) { int n, cnt, sum_div; char ans; do{ printf("-------------------\n"); printf("Enter a number:\n"); scanf("%d", &n); while((n%cnt==0) && (cnt<=n/2));{ printf("Divisors: %d,\n", cnt); sum_div+=cnt; if(sum_div==n) printf("---%d is Perfect\n", n); else if(sum_div>n) printf("---%d is Abundant\n", n); else printf("---%d is Defficient\n", n); } printf("Continue? <Y/N>:\n"); scanf(" %c", &ans); while(ans=='Y'||ans=='y') } printf("Bye:>_\n"); return(0); }



LinkBack URL
About LinkBacks



