Skip to content

Commit 96ddb88

Browse files
committed
init
1 parent 4ed2757 commit 96ddb88

30 files changed

+625
-0
lines changed

1.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
#include<math.h>
4+
#include<stdlib.h>
5+
6+
int main (void) {
7+
8+
char firstName[] = "A";
9+
char lastName[] = "N";
10+
int age = 27;
11+
char profession[] = "Programmer";
12+
13+
printf("My name is %s %s, I am %d years old and I am a %s.\n", firstName, lastName, age, profession);
14+
}

1.exe

248 KB
Binary file not shown.

TestPattern.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <math.h>
4+
#include <stdlib.h>
5+
6+
int main()
7+
{
8+
9+
int n, i, j;
10+
scanf("%d", &n);
11+
// Complete the code to print the pattern.
12+
for(i=n; i>=1; i--){
13+
for(j=n; j>i; j--){
14+
printf("%d ", j);
15+
}
16+
for(j=1; j<=(i*2-1); j++){
17+
printf("%d ", i);
18+
}
19+
for(j=i+1; j<=n; j++){
20+
printf("%d ", j);
21+
}
22+
printf("\n");
23+
}
24+
for(i=1; i<n; i++){
25+
for(j=n; j>i; j--){
26+
printf("%d ", j);
27+
}
28+
for(j=1; j<=(i*2-1); j++){
29+
printf("%d ", i+1);
30+
}
31+
for(j=i+1; j<=n; j++){
32+
printf("%d ", j);
33+
}
34+
printf("\n");
35+
}
36+
return 0;
37+
}

TestPattern.exe

404 KB
Binary file not shown.

TestPattern2.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <math.h>
4+
#include <stdlib.h>
5+
6+
void check(int i, int j, int first, int last, int n) {
7+
if(n >=1 ){
8+
if (i == first || i == last || j == first || j == last)
9+
printf("%d ", n);
10+
else
11+
check(i, j, first + 1, last - 1, n - 1);
12+
}
13+
}
14+
15+
int main()
16+
{
17+
int n;
18+
scanf("%d", &n);
19+
int rows = 2 * n - 1;
20+
21+
for (int i = 0; i < rows; i ++) {
22+
for (int j = 0; j < rows; j ++) {
23+
check(i, j, 0, rows - 1, n);
24+
}
25+
printf("\n");
26+
}
27+
return 0;
28+
}
29+

TestPattern2.exe

404 KB
Binary file not shown.

bitWise.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <math.h>
4+
#include <stdlib.h>
5+
//Complete the following function.
6+
7+
8+
void calculate_the_maximum(int n, int k) {
9+
//Write your code here.
10+
int and1, or1, xor1;
11+
and1 = or1 = xor1 = 0;
12+
for(int a = 1; a < n; a++) {
13+
for(int b = a + 1; b <= n; b++){
14+
and1 = (a & b) > and1 && (a & b) < k ? a & b : and1;
15+
or1 = (a | b) > or1 && (a | b) < k ? a | b : or1;
16+
xor1 = (a ^ b) > xor1 && (a ^ b) < k ? a ^ b : xor1;
17+
}
18+
}
19+
printf("%d\n", and1);
20+
printf("%d\n", or1);
21+
printf("%d\n", xor1);
22+
}
23+
24+
int main() {
25+
int n, k;
26+
27+
scanf("%d %d", &n, &k);
28+
calculate_the_maximum(n, k);
29+
30+
return 0;
31+
}

bitWise.exe

404 KB
Binary file not shown.

conditional.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <assert.h>
2+
#include <limits.h>
3+
#include <math.h>
4+
#include <stdbool.h>
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
#include <string.h>
10+
11+
char* readline();
12+
13+
14+
15+
int main()
16+
{
17+
char* n_endptr;
18+
char* n_str = readline();
19+
int n = strtol(n_str, &n_endptr, 10);
20+
21+
if (n_endptr == n_str || *n_endptr != '\0') { exit(EXIT_FAILURE); }
22+
23+
// Write Your Code Here
24+
25+
if(n >= 1 && n<= 9) {
26+
if(n == 1) {
27+
printf("one\n");
28+
} else if(n == 2) {
29+
printf("two\n");
30+
} else if(n == 3) {
31+
printf("three\n");
32+
} else if(n == 4) {
33+
printf("four\n");
34+
} else if(n == 5) {
35+
printf("five\n");
36+
} else if(n == 6) {
37+
printf("six\n");
38+
} else if(n == 7) {
39+
printf("seven\n");
40+
} else if(n == 8) {
41+
printf("eight\n");
42+
} else if(n == 9) {
43+
printf("nine\n");
44+
}
45+
} else {
46+
if(n > 9) {
47+
printf("Greater than 9");
48+
}
49+
}
50+
return 0;
51+
}
52+
53+
char* readline() {
54+
size_t alloc_length = 1024;
55+
size_t data_length = 0;
56+
char* data = malloc(alloc_length);
57+
58+
while (true) {
59+
char* cursor = data + data_length;
60+
char* line = fgets(cursor, alloc_length - data_length, stdin);
61+
62+
if (!line) { break; }
63+
64+
data_length += strlen(cursor);
65+
66+
if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; }
67+
68+
size_t new_length = alloc_length << 1;
69+
data = realloc(data, new_length);
70+
71+
if (!data) { break; }
72+
73+
alloc_length = new_length;
74+
}
75+
76+
if (data[data_length - 1] == '\n') {
77+
data[data_length - 1] = '\0';
78+
}
79+
80+
data = realloc(data, data_length);
81+
82+
return data;
83+
}

conditional.exe

249 KB
Binary file not shown.

0 commit comments

Comments
 (0)