From 39a09e24cdc4ce0bdc6c9e9c6ab95dee05bd1935 Mon Sep 17 00:00:00 2001 From: fdai7801 Date: Fri, 9 Feb 2024 20:10:43 +0100 Subject: [PATCH] kabrel conver_dectobin --- src/main/c/BasicMode.c | 62 ++++++++---------------------------------- 1 file changed, 12 insertions(+), 50 deletions(-) diff --git a/src/main/c/BasicMode.c b/src/main/c/BasicMode.c index a8dcc27..2c09276 100644 --- a/src/main/c/BasicMode.c +++ b/src/main/c/BasicMode.c @@ -2,58 +2,20 @@ #include #include #include +#include +// convert decimal to binary +long long int DecToBin(long long int n) { + long long int bin = 0; + long long int rem, i = 1; + while (n != 0) { + rem = n % 2; + bin += rem * i; + i *= 10; + n /= 2; + } -void BasicMode() { - char endtmp = '0'; //0 false, 1 true - double result = 0; - double numbers[100] = {0.0}; - char operators[100]; - - do { - //100 doubles in this array goes through the for loop till 100 numbers or = is entered - for (int i = 0; i < 100; i++) { - printf("Enter a Number: "); - numbers[i] = testForNumber(); //gets number - - printf("Enter a operation: "); - operators[i] = testForOperator(); //gets operator - } - } while (endtmp != '1'); - - - for (int i = 0; i < 100; i++) {//checks all operators to check for priority - if ((operators[i] == '/' || operators[i] == '*') && i > 1) { //if operators[i] == / or * and i>1 so you dont get numbers[-1] - if (operators[i] == '/') { - result += divide(numbers[i - 1], numbers[i]); //divides if char is / and adds number to the result - } - // for all calculations we take the number and the number before that - else { // and do the operation - result += multiply(numbers[i - 1], numbers[i]); //multiplys if char is * and adds number to the result - } - } - - else if ((operators[i] == '+' || operators[i] == '-') && i > 1) { - if (operators[i] == '+') { - result += add(numbers[i - 1], numbers[i]); //adds if char is + and adds number to the result - } - - else { - result += minus(numbers[i - 1], numbers[i]); //subtrakts if char is - and adds number to the result - } - } - - else if (i<=1 && operators[i] == '=') { //if there are less then 2 numbers in the array - result = numbers[i]; //set result to the 0 digit - } - - else if (operators[i] == '=') { //if char is = - printf("The result is: %f", result); //print out the result - i = 100; - break; - } - i++; - } + return bin; }