-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.c
63 lines (63 loc) · 1.14 KB
/
activity.c
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
54
55
56
57
58
59
60
61
62
63
// Online C compiler to run C program online
#include <stdio.h>
void swap();
void sort(int a[], int b[], int n)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n - 1; j++)
{
if (a[j] > a[j + 1])
{
swap(&a[j], &a[j + 1]);
swap(&b[j], &b[j + 1]);
}
}
}
}
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void printarray(int arr[], int n)
{
for (int i = 0; i < n; i++)
{
printf("%d ", arr[i]);
}
}
void printmax(int s[], int f[], int n, int ans[])
{
int i = 0, j;
int a = 1;
ans[0] = 0;
for (j = 1; j < n; j++)
{
if (s[j] >= f[i])
{
ans[a++] = j;
i = j;
}
}
printarray(ans, a);
}
int main()
{
int s[100], f[100], ans[100], n;
printf("\n Enter n \n");
scanf("%d", &n);
printf("\nEnter array s\n");
for (int i = 0; i < n; i++)
{
scanf("%d", &s[i]);
}
printf("\nEnter array f\n");
for (int i = 0; i < n; i++)
{
scanf("%d", &f[i]);
}
sort(f, s, n);
printmax(s, f, n, ans);
}