C Program to find and display all the factors of a number entered by an user

/* C to find and display all the factors of a number entered by an user.. */
 
#include <stdio.h>
int main()
{
	int n, i;
	printf("Enter a positive integer: ");
	scanf("%d", &n);
	printf("Factors of %d are: ", n);
	for (i = 1; i <= n; ++i)
	{
		if (n%i == 0)
			printf("%d ", i);
	}
	return 0;
}

Capture.PNG
Output
 
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s