About the problem of #c language # : known C language prepared good program, please modify the program prepared for PHP language

cuixingwei05 注册会员
2023-02-26 20:08

Part of this answer references GPT, GPT_Pro to better solve the problem
First, to convert the C language program to PHP language program, Understand the differences between C and PHP first, and then adapt to your needs.

C language is represented by characters, PHP language is represented by variables and functions, this is the biggest difference between PHP and C language.

Secondly, in the process of modification, we should pay attention to the changes to the code, if the improper changes may lead to program errors or exceptions.


int main()
     float score; 
     char grade; 
     printf("please input score:"); 
     while(score >=60 || score <0) 
          printf("input error,please reinput:"); 
     if(score>=90) grade = 'A'; 
     else if(score>=80) grade = 'B'; 
     else if(score>=70) grade = 'C'; 
     else if(score>=60) grade = 'D'; 
     else grade = 'E'; 

Above is the C language version of a small program, its function is: input a score, according to the score to judge the corresponding grade. To convert it to PHP, do this:






        echo "please input score:";  






    }else if($score>=80){  


    }else if($score>=70){  


    }else if($score>=60){  






    echo "grade:".$grade."\n";  

If the answer is helpful, please accept it.

About the Author

Question Info

Publish Time
2023-02-26 20:08
Update Time
2023-02-26 20:08