c奇数循环

评价:
0
(0用户)

奇数循环 (Odd Loop)

There are situations when we need to execute a set of instructions until the user deny it. So we need to check if the user wants to repeat the set of instructions or not.

在某些情况下,我们需要执行一组指令,直到用户拒绝为止。 因此,我们需要检查用户是否要重复这组指令。

In that case programmer has no idea about the executing time and frequency of the program. This is called odd loop in C programming. So basically we have to make a program which will ask to the user about the re-execution of program.

在那种情况下,程序员不知道程序的执行时间和频率。 这在C编程中称为奇数循环。 因此,基本上我们必须制作一个程序,该程序将询问用户有关程序的重新执行。

  1. #include<stdio.h>
  2. void main()
  3. {
  4. char yes=‘Y’;
  5. int x,y;
  6. while(yes==‘Y’)
  7. {
  8.   printf(“Enter two values to perform additionn”);
  9.   scanf(“%d%d”,&x,&y);
  10.   printf(“Sum is %d n”,x+y);
  11.   printf(“Do you want to continue ? Press Y for Yes and N for Non”);
  12.   scanf(“%c”, &yes);
  13. }
  14. }

本文为原创文章,转载请注明出处!

注册并通过认证的用户才可以进行评价!

admin:支持一下,感谢分享!,+10,  

发表评论