Skip to content

Commit 861459f

Browse files
GOOD
1 parent c89bb99 commit 861459f

File tree

9 files changed

+83
-0
lines changed

9 files changed

+83
-0
lines changed
85.3 KB
Loading
63.6 KB
Loading
109 KB
Loading
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
#include <math.h>
3+
void calculate_the_maximum(int n, int k)
4+
{
5+
/* variables declaration with 0 to use relational operator, compare the values and store the maximum value */
6+
int and_maximum = 0, or_maximum = 0, xor_maximum = 0;
7+
for (int i = 1; i < n; i++)
8+
{
9+
for (int j = i+1; j <= n; j++)
10+
{
11+
/* storing the maximum value of bitwise expressions less than k */
12+
if ((i&j)>=and_maximum && (i&j)<k) and_maximum = i&j;
13+
if ((i|j)>=or_maximum && (i|j)<k) or_maximum = i|j;
14+
if ((i^j)>=xor_maximum && (i^j)<k) xor_maximum = i^j;
15+
}
16+
}
17+
printf("%d\n%d\n%d", and_maximum, or_maximum, xor_maximum);
18+
}
19+
int main()
20+
{
21+
int n, k;
22+
scanf("%d %d", &n, &k);
23+
/* funcion call if constrainsts are within limit */
24+
if ((n>=2 && n<=pow(10, 3)) && (k>=2 && k<=n)) calculate_the_maximum(n, k);
25+
return 0;
26+
}
20.2 KB
Loading
39.5 KB
Loading
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <stdio.h>
2+
int main() {
3+
int n;
4+
scanf("%d", &n);
5+
/* Constraints -> 1<=n<=1000 */
6+
if (n>=1 && n<=1000)
7+
{
8+
/* the upper part */
9+
for (int i = n; i>=1; i--)
10+
{
11+
/* left upper part */
12+
for (int j = n; j > i ; j--)
13+
{
14+
printf("%d ", j);
15+
}
16+
/* middle upper part */
17+
for (int j = 1; j <= (i*2)-1; j++)
18+
{
19+
printf("%d ", i);
20+
}
21+
/* right upper part */
22+
for (int j = i+1; j <= n; j++)
23+
{
24+
printf("%d ", j);
25+
}
26+
/* next line */
27+
printf("\n");
28+
}
29+
/* the lower part */
30+
for (int i = 2; i <= n ; i++)
31+
{
32+
/* left lower part */
33+
for (int j = n; j > i-1; j--)
34+
{
35+
printf("%d ", j);
36+
}
37+
/* middle lower part */
38+
for (int j = 1; j < i*2-2; j++)
39+
{
40+
printf("%d ", i);
41+
}
42+
/* right lower part */
43+
for (int j = i; j <= n ; j++)
44+
{
45+
printf("%d ", j);
46+
}
47+
/* next line */
48+
printf("\n");
49+
}
50+
}
51+
/* Out-range of constraints */
52+
else
53+
{
54+
return 1;
55+
}
56+
return 0;
57+
}

0 commit comments

Comments
 (0)