Repeating the road test

1. If the variable has been defined correctly, the program segment is required to complete the calculation of seeking 5!, the program segment that cannot complete this operation is

A.

#include <stdio.h>
int main( )
{
    int i;
    int p;
    for(i=1;i<=5;i++ )
    {
        p=1;
        p*=i;
    }
    printf("5!=%d\n", p);
    return 0;
}

    Each time the loop body is executed, the value of the variable p is reset to 1, which does not comply with the rules of factorial operation.

 

 

B.

#include <stdio.h>
int main( )
{
    int i;
    int p;
    i=1;
    p=1;
    while(i<=5)
    {
        p*=i;
        i++;
    }
    printf("5!=%d\n", p);
    return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_42048463/article/details/115195147