Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Problem: need to closing my program

$
0
0
bellow is my program to find abundant numbers; the code works I just can get it to exit properly.
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    
    // Declare and initialize variables.
    int n, num, sum=0, i, j;
    
    //prompting user for input
    printf("Please enter n followed by n numbers: ");
    scanf("%d", &n);
    
    //for loop for reading in the n amount of numbers
	for(i=0;i<=n;i++){
    	scanf("%d", &num);
    	//setting sum to zero
		sum=0;		    	
    	//for loop for finding factors of num
		for(j=1;j<=(num/2);j++){
    		//if the current j is a factor of num, add it to sum
			if((num%j)==0){
    			sum+=j;
    		}
    	}
		//print if number is abundant
		if (sum>num){
			printf("Test case %d: %d is abundant.\n",i+1,num);
		}
		//print if numer isnt abundant
		else{
			printf("Test case %d: %d is NOT abundant.\n",i+1, num);	
			
		}		 	
    }
    system("pause");
    return 0;
}

Any help will be very appreciated

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>