Showing posts with label factors in a given number in c. Show all posts
Showing posts with label factors in a given number in c. Show all posts

Thursday, February 16, 2017

Factors of a Number in C

Hi there in this article I would like to share with you guys a sample program that I wrote using C as my programming language. Our program will ask the user to give a number and then our program will display the factors of the given number using For loop statement in C. The code is very short and easy to understand. I hope you will learned from it. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

#include <stdio.h>

int main()
{
    int number=0,a=0;

    printf("\n\n");
    printf("FACTORS OF A NUMBER IN C");
    printf("\n\n");
    printf("Give any integer number : ");
    scanf("%d",&number);
    printf("\n\n");
    printf("The Factors of %d are: ",number);
     for (a=1; a<=number; a++){
         if (number % a == 0){
            printf(" %2d ",a);
         }
     }
    printf("\n\n");
    printf("END OF PROGRAM");
    printf("\n\n");
}