├── Bitwise_Operator in C ├── Conditional Statement in C └── For loop in C /Bitwise_Operator in C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void calculate_the_maximum(int n, int k) { 7 | int max_and = 0, max_or = 0, max_xor = 0; 8 | for (int i = 1; i <= n; i++) { 9 | for (int j = i + 1; j <= n; j++) { 10 | int temp_and = i & j; 11 | int temp_or = i | j; 12 | int temp_xor = i ^ j; 13 | if (temp_and > max_and && temp_and < k) { 14 | max_and = temp_and; 15 | } 16 | if (temp_or > max_or && temp_or < k) { 17 | max_or = temp_or; 18 | } 19 | if (temp_xor > max_xor && temp_xor < k) { 20 | max_xor = temp_xor; 21 | } 22 | } 23 | } 24 | printf("%d\n%d\n%d", max_and, max_or, max_xor); 25 | } 26 | 27 | 28 | int main() { 29 | int n, k; 30 | 31 | scanf("%d %d", &n, &k); 32 | calculate_the_maximum(n, k); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Conditional Statement in C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | char* readline(); 12 | 13 | int main() 14 | { 15 | char* n_endptr; 16 | char* n_str = readline(); 17 | int n = strtol(n_str, &n_endptr, 10); 18 | 19 | if (n_endptr == n_str || *n_endptr != '\0') { exit(EXIT_FAILURE); } 20 | 21 | // Write Your Code Here 22 | if(n>=1 && n<=9) 23 | { if(n==1) 24 | printf("one"); 25 | if(n==2) 26 | printf("two"); 27 | if(n==3) 28 | printf("three"); 29 | if(n==4) 30 | printf("four"); 31 | if(n==5) 32 | printf("five"); 33 | if(n==6) 34 | printf("six"); 35 | if(n==7) 36 | printf("seven"); 37 | if(n==8) 38 | printf("eight"); 39 | if(n==9) 40 | printf("nine"); 41 | } 42 | else 43 | printf("Greater than 9"); 44 | 45 | return 0; 46 | } 47 | 48 | char* readline() { 49 | size_t alloc_length = 1024; 50 | size_t data_length = 0; 51 | char* data = malloc(alloc_length); 52 | 53 | while (true) { 54 | char* cursor = data + data_length; 55 | char* line = fgets(cursor, alloc_length - data_length, stdin); 56 | 57 | if (!line) { break; } 58 | 59 | data_length += strlen(cursor); 60 | 61 | if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; } 62 | 63 | size_t new_length = alloc_length << 1; 64 | data = realloc(data, new_length); 65 | 66 | if (!data) { break; } 67 | 68 | alloc_length = new_length; 69 | } 70 | 71 | if (data[data_length - 1] == '\n') { 72 | data[data_length - 1] = '\0'; 73 | } 74 | 75 | data = realloc(data, data_length); 76 | 77 | return data; 78 | } 79 | -------------------------------------------------------------------------------- /For loop in C: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | int a, b; 8 | scanf("%d\n%d", &a, &b); 9 | 10 | for (int i = a; i <= b; i++) { 11 | if (i == 1) { 12 | printf("one\n"); 13 | } else if (i == 2) { 14 | printf("two\n"); 15 | } else if (i == 3) { 16 | printf("three\n"); 17 | } else if (i == 4) { 18 | printf("four\n"); 19 | } else if (i == 5) { 20 | printf("five\n"); 21 | } else if (i == 6) { 22 | printf("six\n"); 23 | } else if (i == 7) { 24 | printf("seven\n"); 25 | } else if (i == 8) { 26 | printf("eight\n"); 27 | } else if (i == 9) { 28 | printf("nine\n"); 29 | } else if (i % 2 == 0) { 30 | printf("even\n"); 31 | } else { 32 | printf("odd\n"); 33 | } 34 | } 35 | 36 | return 0; 37 | } 38 | --------------------------------------------------------------------------------