Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Use c language for loop to find factorial from 1 to 10
Use c language for loop to find factorial from 1 to 10

void

main()

Main function

{

int

i,a=1;

Define integer variable i,a (the initial value of a is 1)

int

sum

= 0;

Define the integer variable sum

The initial value is 0

for(i

=

1 ;i<=10;i++)

Suppose the value of i is 1. When i is less than or equal to 10, the answer will pop up. If it is not true, the value of i will be increased by 1

{

a

=

a

*i;

a=a times i

sum

=

sum

+

a;

sum record summation

}

printf("The factorial sum from 1 to 10 is

%d",sum);

Output result

end

End

}