Program to find the Factorial of a
number
int inputNum;
int i;
int factorial = 1;
int value;
printf("Please Enter Number
less than or equal to 10:: ");
scanf("%d",&inputNum);
if(inputNum <= 10)
{
for(i =inputNum; i >= 1 ;
i--)
{
value = i * factorial;
printf("\n%d * %d =
%d\n" , i,factorial,value);
factorial = value;
}
printf("\nFactorial of %d is
%d", inputNum,factorial );
}
else
{
printf("Please enter
number less than or equal to 10");
}
Program to print out all
Armstrong numbers between given numbers
int inputNum;
int i;
int armstrongNum ;
int j;
int digit;
printf("Please Enter Number max
limit");
scanf("%d",&inputNum);
for(i =1; i<= inputNum ;
i++)
{
armstrongNum = 0;
j = i;
while( j > 0)
{
digit = j%10;
armstrongNum += digit*digit*digit;
j = j/10;
}
if(armstrongNum == i)
{
printf("%d\n",
armstrongNum);
}
}
No comments:
Post a Comment