-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek5program32.cpp
More file actions
41 lines (38 loc) · 895 Bytes
/
week5program32.cpp
File metadata and controls
41 lines (38 loc) · 895 Bytes
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
//You are given an integer 'n' which denote the number of elements in an array a[ ]and an integer 'x'.
// You have to calculate the average of element a[i] and x and find out if that number exist in array or not.
// Do it for all the elements of array and store the count result in another array for each index i.
//Examples:
//Input : n=5 x=2 a={2 4 8 6 2}
//Output: 2 0 0 1 2
//Input : n=6 x=3 a={9 5 2 4 0 3}
//Output: 0 1 1 1 0 1
#include<stdio.h>
int main()
{
int i,j,n,x;
float sum=0;
printf("enter n:");
scanf("%d",&n);
int a[n],b[n];
printf("enter array elements:");
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
printf("enter x:");
scanf("%d",&x);
float avg=0;
for(i=0;i<n;i++){
avg=(x+a[i])/2;
for(j=0;j<n;j++){
if(avg==a[j]){
sum++;
}
}
b[i]=sum;
avg=0;
sum=0;
}
for(i=0;i<n;i++){
printf("%d ",b[i]);
}
}