Welcome To My Blog!! Enjoy Your Time Reading! - Vino00031

Divisors of a Number in C

A program in c++ where the user inputs a whole number.If the number inputted is negative,it will display, “Input Error!!”. But if the number is positive,then it would display its divisors.
#include<stdio.h> //preprocessor directive
#include<conio.h>
int main()
{
long int numb=0,divisor=1;
printf("\nInput a whole number:");
scanf("%li",&numb);
if(numb<=0)
printf("\nInvalid Input!!");
else
{
printf("The divisors of %li are ",numb);
for(divisor=1; (divisor<=numb);divisor++)
{
if (divisor==1)
{
printf("%li",divisor);
continue;
}
if(divisor==numb)
printf(" and %li.",divisor);
else if(numb%divisor==0)
printf(", %li",divisor);
else
continue;
}
}
getch();
return 0;
}

No comments:

Post a Comment

GOOGLE AD

Flag Counter

free counters
. . . . . . . . .