Let us learn C in Code <9> pseudocode

Hi, everyone, this chapter just shows a very important method to handle the problem before coding .  In our daily life, we often depend on the schedule to do something which has been planed. The schedules are often wrote by ourselves to plan the further event. Is there the same way in code? Surely,  the "schedule" in C code is named pseudocode . Pseudocode belongs to a high-level description of a computer program. The pseudocode is intended for programmer reading rather than the machine reading. Using the pseudocode ,we can abstract the problem to a concrete one and  make the program easily understand  , so we can translate the pseudocode  into the programming code more efficiently.

Now let us analyze this situation , after we finish the pseudocode description , convert it to programming code.

0), Record the student whose grade is higher than 60 . note PASSED ,or FAILED

If the grade is higher than or equals to 60

   print PASSED

else the grade is lower than 60

  print FAILED

end


main()
{
  int student1 = 90;
  int student2 = 60;
  int student3 = 50;

  if(student1 >= 60)
  {
     printf("PASSED\n");
  }
  else
  {
     printf("FAILED\n");
  }

  if(student3 >= 60)
  {
     printf("PASSED\n");
  }
  else
  {
     printf("FAILED\n");
  }

  if(student1 >= 60)
  {
     printf("PASSED\n");
  }
  else
  {
     printf("FAILED\n");
  }

}


 1), Divided one value by another one and show the result. (When we meet the division , what we cared is whether the denominator  is zero or not.) 

If the one (denominator is zero)

  warn the denominator is zero and jump out the calculation.

else 

   divide one by the other and record the result

   then print the result

end

As the pseudocode ,we convert it to programming as below.

main()
{
  float a = 10;
  float b = 2.0;
  float c = 0.0;
 
  float nominator = 0.0;
  float denominator = 0.0;
  
  nominator = a;
  denominator = c;
  if(denominator == 0)
  {
     printf("Error! The denominator is ZERO!\n");
  }
  else
  {
     c = nominator/denominator;
     printf("The result is %f \n",c);
  }

}



2) In chapter "Let us C in Code <7> operators" , there is listed question labeled 1) about the presents, can you describe it use the pseudocode ?

The question detailed as this  " 1) My friend Jen. will have the birthday, i really want to give her a present,  but it really depends on the time and the money, if i have free time i can prepare a home made present, but if i don't have enough time , so just buy a present. How can i handle this situation? "

If i have free time

   I will prepare a home made present

else if i don't have time

  Just buy a present 

end


This question just is an example for us to get the description of pseudocode step by step. If there are some concrete value ,we can translate the pseudocode to programming code as above question. But here, we can't . It dosen't matter, you can set some related value by yourself ,then code it.


Conclusion:

The pseudocode just a high-level description language .this language's purpose is used to make us (our human ) clear about the program before coding. Actually, the pseudocode  just is  text based , next chapter we will learn another method to describe the program ,that method is more visible and more efficiency than the pseudocode.

Ok , time's limited!  Thanks everyone!  I hope you enjoy this chapter. See you next chapter!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值