formatted files

This commit is contained in:
Rushil Umaretiya 2024-02-21 14:59:01 -05:00
parent 7ef18644e8
commit 5de9838a15
No known key found for this signature in database
GPG Key ID: 4E8FAF9C926AF959
4 changed files with 20 additions and 20 deletions

2
f32.c
View File

@ -1,4 +1,4 @@
// PID: 730677144 // PID: 730677144
// I pledge the COMP 211 honor code. // I pledge the COMP 211 honor code.
#include <math.h> #include <math.h>

View File

@ -1,12 +1,12 @@
// PID: 730677144 // PID: 730677144
// I pledge the COMP 211 honor code. // I pledge the COMP 211 honor code.
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
int main(int argc, char *argv[]) { int main(int argc, char* argv[]) {
char input[33]; char input[33];
char output[33] = {'\0'}; char output[33] = {'\0'};
strncpy(input, argv[1], 32); strncpy(input, argv[1], 32);
@ -14,14 +14,15 @@ int main(int argc, char *argv[]) {
for (int i = 0; i < 32; i++) for (int i = 0; i < 32; i++)
output[i] = (input[i] == '0') ? '1' : '0'; output[i] = (input[i] == '0') ? '1' : '0';
output[32] = '\0'; output[32] = '\0';
if (input[0] == '1') { if (input[0] == '1') {
int carry = 1; int carry = 1;
for (int i = 31; i >= 0 && carry; i--) { for (int i = 31; i >= 0 && carry; i--) {
output[i] = (input[i] == '0') ? '1' : '0'; output[i] = (input[i] == '0') ? '1' : '0';
if (input[i] == '0') carry = 0; if (input[i] == '0')
carry = 0;
} }
} else { } else {
int i = 31; int i = 31;
@ -32,7 +33,7 @@ int main(int argc, char *argv[]) {
output[i] = '1'; output[i] = '1';
} }
printf("%s\n", output); printf("%s\n", output);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,10 +1,10 @@
// PID: 730677144 // PID: 730677144
// I pledge the COMP 211 honor code. // I pledge the COMP 211 honor code.
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) { int main(int argc, char* argv[]) {
int num = atoi(argv[1]); int num = atoi(argv[1]);
if (num < -32768 || num > 32767) { if (num < -32768 || num > 32767) {
@ -27,7 +27,7 @@ int main(int argc, char *argv[]) {
printf("0"); printf("0");
} }
} }
printf("\n"); printf("\n");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

15
twos.c
View File

@ -1,12 +1,12 @@
// PID: 730677144 // PID: 730677144
// I pledge the COMP 211 honor code. // I pledge the COMP 211 honor code.
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) { int main(int argc, char* argv[]) {
int num = abs(atoi(argv[1])); int num = abs(atoi(argv[1]));
char out[17] = "\0"; char out[17] = "\0";
if (num > 65535) { if (num > 65535) {
printf("not possible\n"); printf("not possible\n");
@ -15,12 +15,11 @@ int main(int argc, char *argv[]) {
for (int i = 15; i >= 0; i--) { for (int i = 15; i >= 0; i--) {
if (num >= (1 << i)) { if (num >= (1 << i)) {
out[15-i] = '1'; out[15 - i] = '1';
num -= (1 << i); num -= (1 << i);
} else { } else {
out[15-i] = '0'; out[15 - i] = '0';
} }
} }
if (argv[1][0] == '-') { if (argv[1][0] == '-') {
@ -40,7 +39,7 @@ int main(int argc, char *argv[]) {
break; break;
} }
} }
} }
printf("%s\n", out); printf("%s\n", out);