帮助理解代码。 [英] Help for understaning the code.

查看:76
本文介绍了帮助理解代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能帮助我理解代码吗



* C程序将N个整数读入数组A和



* a)找出负数之和



* b)找出正数之和



* c)查找所有数字的平均值



*以合适的标题显示结果



* /

can you please help me for understanding the code

* C program to read N integers into an array A and

* a) Find the sum of negative numbers

* b) Find the sum of positive numbers

* c) Find the average of all numbers

* Display the results with suitable headings

*/

#include  <stdio.h>
#define MAXSIZE 10

void main()

{
    int array[MAXSIZE];
    int i, num, negative_sum = 0, positive_sum = 0;
    float total = 0.0, average;
    printf ("Enter the value of N \n");
    scanf("%d", &num);
    printf("Enter %d numbers (-ve, +ve and zero) \n", num);
    for (i = 0; i < num; i++)
    {
        scanf("%d", &array[i]);
    }

    printf("Input array elements \n");
    for (i = 0; i < num; i++)
    {
       printf("%+3d\n", array[i]);
    }

    /*  Summation starts */
    for (i = 0; i < num; i++)
    {
        if (array[i] < 0)
        {
            negative_sum = negative_sum + array[i];
        }
        else if (array[i] > 0)
        {
            positive_sum = positive_sum + array[i];
        }

        else if (array[i] == 0)
        {
            ;
        }

        total = total + array[i] ;
    }

    average = total / num;
    printf("\n Sum of all negative numbers =  %d\n", negative_sum);
    printf("Sum of all positive numbers =  %d\n", positive_sum);
    printf("\n Average of all input numbers =  %.2f\n", average</stdio.h>)
}  

推荐答案





阅读本教程:

1) C教程

2) C编程

视频教程:

1)最受欢迎的视频 - C编程教程


您可以在这里找到它们: C Programming Tutorial [ ^ ]
You will find them all here: C Programming Tutorial[^]


这篇关于帮助理解代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆