永发信息网

Visual Studio 2005 编程求助

答案:1  悬赏:0  手机版
解决时间 2021-04-30 01:25
  • 提问者网友:你给我的爱
  • 2021-04-29 08:51

Write a program in assembly that will:
1. Read a number, counter;
2. Go around in a loop where integers are read from the user. When an odd number (e.g. 1, 3, 5, 7 , etc) is read increase a variable, OddAmount by 1, and when an even number is read increase a variable, EvenAmount by 1.
3. Finally, print out the values of OddAmount and EvenAmount.

Your program should satisfy the following requirements.
1. If the input to counter is zero or negative, jump to the end without doing anything.
2. If the input to counter is positive, show the number before starting the loop.
3. In each round of the loop, show a message after the input to indicate whether the input is odd or even.

结果输出:

最佳答案
  • 五星知识达人网友:你可爱的野爹
  • 2021-04-29 09:57
#include <stdio.h>

int main()
{
int OddAmount = 0, EvenAmount = 0;
int counter, t;
printf( "Please input the number of loops: " );
scanf( "%d", &counter );
if ( counter <= 0 ) return 1;
printf( "\n\nThe loop will run %d times.\n\n", counter );
while ( counter-- > 0 ) {
printf( "\nPlease input a integer: " );
scanf( "%d", &t );
if ( t % 2 == 0 ) {
++EvenAmount;
printf( "The number is even.\n\n" );
} else {
++OddAmount;
printf( "The number is odd.\n\n" );
}
}
printf( "\nThe number of even integer is: %d.", EvenAmount );
printf( "\nThe number of odd integer is: %d.\n", OddAmount );
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯