新型均值计算算法Use the “>>“ operator to calculate the average value of an array instead of using buf

本文展示了如何使用C语言编写一个程序,通过位移操作计算给定数组的平均值,结果为64。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


// Use the ">>" operator to calculate the average value of an array instead of using buf

#include "stdio.h"

typedef unsigned char uint8_t;
#define ARRAY_N  (200)

void main(void)
{
    uint8_t array[ARRAY_N] ;
    uint8_t i;
    uint8_t aver = 0;

    for(i = 0; i < ARRAY_N; i++)
    {
       array[i] = 64;
    }

    for(i = 0; i < ARRAY_N; i++)
    {
       aver = aver - (aver>>5) + (array[i] >> 5); // calculat the average
    }
    printf("\nhello Lihua Long, good job!!\n");
    printf("The aver is : %d\n",aver);
}

// PS E:\006-Programing\007-c> gcc -o main  main.c
// PS E:\006-Programing\007-c> ./main

// hello Lihua Long, good job!!
// The aver is : 64
// PS E:\006-Programing\007-c> 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值