Написать программу для вычисления факториалов всех нечётных чисел от 1 до 9 на С++

13.06.2014 17:09 Администратор
Печать
(6 голоса, среднее 5.00 из 5)

Решение:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <iostream.h>  
unsigned int factor(int x) 
{
unsigned int f = 1;
for (int i = 2; i <= x; i++)
f *= i;
return(f) ; }
void main()
{
unsigned int f;
printf ("\nThe Program of the calculation of the amount factorial uneven from 1 before 9\n");
printf ("\nTable factorial uneven from 1 before 9\n");
for (int n = 1; n <= 1; n++)
{
f = factor(n); printf("%i %u\n", n,f); 
}
for (int n1 = 3; n1<= 3; n1++)
{
f = factor(n1); printf("%i %u\n", n1,f); 
}
for (int n2 = 5; n2<= 5; n2++)
{
f = factor(n2); printf("%i %u\n", n2,f); 
}
for (int n3 = 7; n3<= 7; n3++)
{
f = factor(n3); printf("%i %u\n", n3,f); 
}
for (int n4 = 9; n4<= 9; n4++)
{
f = factor(n4); printf("%i %u\n", n4,f);
}
int c; 
printf ("\nAmount factorial from 1 before 9\n");
if (n--,n1--,n2--,n3--,n4--,c,f)
{
c=factor(n)+factor(n1)+factor(n2)+factor(n3)+factor(n4);
printf ("\n  %d+%d+%d+%d+%d",factor(n),factor(n1),factor(n2),factor(n3),factor(n4));
printf ("=%d",c);
}  
getch();
}

Download SocComments v1.3