-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodevit.cpp
53 lines (51 loc) · 883 Bytes
/
codevit.cpp
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
44
45
46
47
48
49
50
51
52
53
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int lowest(int *a,int n)
{
int i,l;
l=a[0];
for(i=1;i<n;i++)
{
if(a[i]<l)
l=a[i];
}
return l;
}
int main()
{
int n,k,i,j,*a,*b,*s,x,m=0, t;
printf("enter the size of the arrays:");
scanf("%d",&n);
printf("\nenter how many modifications are allowed:");
scanf("%d",&k);
a=(int*)malloc(n*sizeof(int));
b=(int*)malloc(n*sizeof(int));
x=2*n;
s=(int*)calloc(x, sizeof(int));
printf("\nenter the values of modifiable array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n\nenter the values of unmodifiable array:");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{
t=a[i];
a[i]+=k*2;
for(j=0;j<n;j++)
s[m]+=(a[j]*b[j]);
m++;
a[i]=t;
a[i]-=k*2;
for(j=0;j<n;j++)
s[m]+=(a[j]*b[j]);
m++;
a[i]=t;
}
printf("\nthe required output is %d",lowest(s,m-1));
}