作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
想请您帮忙!!我在添加计时器和找到平均分方面遇到了困难。标记将由用户在特定时间输入。即每隔一分钟,用户将输入标记。第一分钟 - 输入第一个值
再等待 60 秒,然后
第二分钟 - 然后输入第二个值。第 3 分钟 - 然后输入第 3 个值。
因此用户输入的每第 n 个值相差 60 秒。
我已经添加了每一分钟倒计时,但在我输入 num=5 后输出给出了奇怪的值。
下面的代码添加了一分钟定时器:
printf("Enter the marks to find average: ");
scanf("%d",&num);//get input from user
// for num, i enter 5, so num=5 then 5 values should be entered
// time taken for entering 5 values will be 5 minutes.
//loop for get input from user
for(i=0; i<num; i++)
{
timer++;
//if timer is equal to 60 then, get 1st mark from user,
if (timer ==60)
{
printf("Enter marks %d: ",i+1);
scanf("%f", &arr[i]);
}
timer=0; //reset back to zero and loop again to get next marks!
}
包括计时器和查找平均值的完整代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main()
{
float arr[100];//array declaration-keep max to 100
int i,num;//variable declaration
double avg=0.0,sum=0.0;
static uint32_t timer = 0; //1min timer for getting marks
printf("Enter the marks to find average: ");
scanf("%d",&num);//get input from user
//if user enter "10", then 10 values should be entered 60secs apart.
// time taken for entering 10 values will be 10minutes.
//loop for get input from user
for(i=0; i<num; i++)
{
timer++;
//if timer is equal to 60 then, get 1st mark from user,
if (timer ==60)
{
printf("Enter marks %d: ",i+1);
scanf("%f", &arr[i]);
}
//timer=0; //reset back to zero
}
for(i=0; i<num; i++){ //loop calculating sum of array elements
sum=sum+arr[i];
avg=sum/num; //calculating average
}
printf("Average of entered numbers are: %.2f",avg);
getch();//display result on the screen
return 0;
}
最佳答案
在循环中,计时器只会增加 5 次。找到下面正确的代码。
for(i=0; i<num; i++)
{
printf("Enter marks %d: ",i+1);
scanf("%f", &arr[i]);
while(timer!=60)
timer++;
timer=0; //reset back to zero
}
您可以使用计时器功能来实现您的应用程序。 https://www.geeksforgeeks.org/time-delay-c/
关于c - 使用数组的平均分数 - 由用户在一定时间内输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59085723/
我正在尝试开发右边框/Angular 具有特定 Angular (30°) 的表格。我见过一些类似的解决方案,但它们都无法在一定程度上发挥作用。如果我想从 30° 改变到 20°,我不想花太多力气。
我是一名优秀的程序员,十分优秀!