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

View File

@ -1,11 +1,11 @@
// PID: 730677144
// I pledge the COMP 211 honor code.
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
int main(int argc, char* argv[]) {
char input[33];
char output[33] = {'\0'};
@ -21,7 +21,8 @@ int main(int argc, char *argv[]) {
int carry = 1;
for (int i = 31; i >= 0 && carry; i--) {
output[i] = (input[i] == '0') ? '1' : '0';
if (input[i] == '0') carry = 0;
if (input[i] == '0')
carry = 0;
}
} else {
int i = 31;

View File

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

9
twos.c
View File

@ -1,10 +1,10 @@
// PID: 730677144
// I pledge the COMP 211 honor code.
#include <stdlib.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]));
char out[17] = "\0";
@ -15,12 +15,11 @@ int main(int argc, char *argv[]) {
for (int i = 15; i >= 0; i--) {
if (num >= (1 << i)) {
out[15-i] = '1';
out[15 - i] = '1';
num -= (1 << i);
} else {
out[15-i] = '0';
out[15 - i] = '0';
}
}
if (argv[1][0] == '-') {