this is compiling but giving an error not dislaying the sum


A function Count is passed a double array along with two other parameters val and dval, val indicates the number of elements in the aarray and dval is a user entered double value. The function computes and returns the number of values in the array that are greater than dval.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  #include<stdio.h>
 main(){

int i, val,dval;
printf("enter the  no of elements\n");
scanf("%d",&val);
double arr[val];
printf("enter the elements\n");
    for (i = 0; i < val; i++)
    {

        scanf("%u",&arr[i]);
    }
    printf("the array entered by you is\n");
    for (i = 0; i < val; i++)
    {
        printf("%u,",arr[i]);
    }

    printf("\nenter double type value\n");
    scanf("%u",&dval);
    printf("%u",dval);
    printf("\nsum = %d\n",count(arr,val,dval));
}
int count(double arr[],int val,double dval)
{
    int i;
    int sum=0;
    for(i=0;i<val;i++)
    {
        if(arr[i] > dval)
        { printf("%d",arr[i]);
            sum++;


        }

    }
return sum;


}
I don't know how you got it to compile. line 7 is not valid. Array size must be known at compile time, you can't use a variable.

There is also no declaration for count(). You have to declare a function before you can use it. (just move it above main())

Oh, and main() should be int main().
Last edited on
Topic archived. No new replies allowed.