/*Homework2

Wednesday, September 21st, 2011 1:02 PM

Homework 2: The program asks user for a positve integer greater than 0 and less than 10. Program prints out:

1. whether number is even or odd

2. cube of number

3. square root of number

4. Sum of the digits

5. factorial

If an unsuitable number is entered, program exits only printing that an invalid number was entered.*/

Code:

#include <stdio.h>
#include <math.h> /* for sqrt*/
/* ask user to input a number between 1 and 10.
program will check number and terminate if input invalid
Otherwise the program will prnt out if the number is odd or even
value cubed, sqare root of the number, sum of the digits and factoral*/
int main()
{
int number, i, sumx, productx, cubed, sqrt, factoral;
printf(" enter a postive number between 1 and 10:");
scanf("%d", &number);
/* if ((number > 0 ) && (number < 11)).....*/
{ number/2 = even
printf ("the number %d is even\n");
else
printf ("the number %d is odd\n"); /* 1 */
}
{cubed = (number*number*number)
printf (" the number cubed is %d\n"); /*2*/
}
{sqrt = (sqrt(number))
printf (" the number square root is %d\n"); /*3*/
}
{sumx=0;
for (i=1;i<=number;i=i+1)
sumx =sumx+ i;
printf("the sum of the digits is %d\n", sumx); /* 4 */
for (i=1; i<= number; i=i+1)
productx=productx*i;
}
{factoral=0;
for (i=1;i<=number;i=i*1)
factoral =factoral* i;
printf("factoral of this is %d\n", factoral); /* 5 */
for (i=1; i<= number; i=i*1)
factoral=factoral*i;
}
system("PAUSE");
return 0;
}