├── README.md ├── calc.py └── calc.java /README.md: -------------------------------------------------------------------------------- 1 | # Basic-Calc-in-multiple-languages 2 | 3 | ### Features: 4 | 1. Addition + - Addition of N Numbers. 5 | 2. Subtraction - - Subtraction of N Numbers. 6 | 3. Multipication * - Multipication of Two Numbers. 7 | 4. Division / - Division of two Numbers. 8 | 5. Modulus % - Modulus of Two Numbers. 9 | 6. Hypotenuse - Find Any Triangle's Hypotenuse. 10 | 7. Power of a Number - Find any Number Power using Base and Exponenent. 11 | 8. Random Number - Generate any Random Number. 12 | 9. Converter - Celcius to Fahrenheit and Fahrenheit to Celcius Converter. 13 | 10. Armstrong Number - You can Find any number is the sum of cubes of each digit is equal to the number itself or Not i.e., Armstrong Number. 14 | 11. Reverse a Number - Reverse any Number. 15 | 12. Circle - To Find Radius, Diameter, Circumference and Area. 16 | 13. Rectangle - To Find Area, Diagonal, Perimeter, Length and Width. 17 | 14. Tables - You can Get any Table of any Number. 18 | 15. Matrices - Addition, Subtraction, Multipication of two Matrices and Transpose of a Matrix. 19 | 20 | More Features will be uploaded soon. 21 | 22 | 23 | More Language Programs will be uploaded soon 24 | -------------------------------------------------------------------------------- /calc.py: -------------------------------------------------------------------------------- 1 | from os import system 2 | from math import sqrt 3 | 4 | def main(): 5 | system('cls'); 6 | print("1. Addition\n2. Subtraction\n3. Multipication\n4. Division\n5. Area of Triangle\n6. Quadratic Solutions\n7. Converter\n8. Print\n") 7 | option = int(input("Enter Your Choice: ")) 8 | switchers = { 9 | 1: addition, 10 | 2: substraction, 11 | 3: multipication, 12 | 4: division, 13 | 5: triangle, 14 | 6: quadratic, 15 | 7: converter, 16 | 8: printing 17 | } 18 | switchers.get(option)() 19 | 20 | def addition(): 21 | system('cls') 22 | a = float(input("Enter 1st Number: ")) 23 | b = float(input("Enter 2nd Number: ")) 24 | c = a + b 25 | print("\nSum of %0.2f and %0.2f is : %0.2f" % (a, b, c)) 26 | 27 | def substraction(): 28 | system('cls') 29 | a = float(input("Enter 1st Number: ")) 30 | b = float(input("Enter 2nd Number: ")) 31 | c = a - b 32 | print("\nDifference of %0.2f and %0.2f is : %0.2f" % (a, b, c)) 33 | 34 | def multipication(): 35 | system('cls') 36 | a = float(input("Enter 1st Number: ")) 37 | b = float(input("Enter 2nd Number: ")) 38 | c = a * b 39 | print("\nMultipication of %0.2f and %0.2f is : %0.2f" % (a, b, c)) 40 | 41 | def division(): 42 | system('cls') 43 | a = float(input("Enter 1st Number: ")) 44 | b = float(input("Enter 2nd Number: ")) 45 | c = a / b 46 | print("\nDivision of %0.2f and %0.2f is : %0.2f" % (a, b, c)) 47 | 48 | def triangle(): 49 | system('cls') 50 | a = float(input("Enter 1st Side: ")) 51 | b = float(input("Enter 2st Side: ")) 52 | c = float(input("Enter 3st Side: ")) 53 | s = (a + b + c)/2 54 | area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 55 | print('The area of the triangle is %0.2f' %area) 56 | 57 | def quadratic(): 58 | system('cls') 59 | print("Quadratic Function : (a * x^2) + b*x + c") 60 | a = float(input("Enter Value of a: ")) 61 | b = float(input("Enter Value of b: ")) 62 | c = float(input("Enter Value of c: ")) 63 | 64 | r = b**2 - 4*a*c; 65 | if r > 0: 66 | roots = 2 67 | x = (((-b) + sqrt(r))/(2*a)) 68 | y = (((-b) + sqrt(r))/(2*a)) 69 | print("There are two roots: %f an d %f" % (x, y)) 70 | elif r == 0: 71 | roots = 1 72 | x = (-b) / 2*a 73 | print("There is 1 root: ", x) 74 | else: 75 | roots = 0 76 | print("No Roots, Disctiminant is less than 0.") 77 | 78 | def converter(): 79 | system('cls') 80 | print("1. Celsius to Fahrenheit\n2. Fahrenheit to Celsius\n") 81 | option1 = int(input("Enter Your Choice: ")) 82 | switchers = { 83 | 1: celsius, 84 | 2: fahrenheit 85 | } 86 | switchers.get(option1)() 87 | 88 | def celsius(): 89 | system('cls') 90 | cel = float(input("Enter Temperature in Celsius: ")) 91 | f = (cel * 9/5) + 32; 92 | print("The Temperature of %f Celsius in Fahrenheit is : %f" % (cel, f)) 93 | def fahrenheit(): 94 | system('cls') 95 | f = float(input("Enter Temperature in Fahrenheit: ")) 96 | cel = (f - 32) * 5/9 97 | print("The Temperature of %f Fahrenheit in Celsius is : %f" % (f, cel)) 98 | 99 | def printing(): 100 | system('cls') 101 | print("\"Hello World\"") 102 | print('\'Hello World\'') 103 | message = "Hello World (Printed using a variable)" 104 | print(message) 105 | 106 | main() 107 | -------------------------------------------------------------------------------- /calc.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class calc { 4 | public static void main(String[] args){ 5 | double a, b, c = 0, e = 0, x, y, z; 6 | int d, numS; 7 | Scanner calc = new Scanner(System.in); 8 | System.out.print("\033[H\033[2J"); 9 | while(e == 0){ 10 | System.out.println("\n1. Addition + \n2. Subtraction - \n3. Multipication * \n4. Division / \n5. Modulus % \n6. Hypotenuse \n7. Power of a Number \n8. Random Number \n9. Converter \n10. Armstrong Number \n11. Reverse a Number \n12. Circle \n13. Rectangle \n14. Tables \n15. Matrices \n16. Exit \nEnter Your Choice: \n"); 11 | d = calc.nextInt(); 12 | switch(d){ 13 | case 1: 14 | System.out.print("\033[H\033[2J"); 15 | System.out.println("\nAddition\n"); 16 | System.out.println("Enter How many Numbers you want to SUM: \n"); 17 | numS = calc.nextInt(); 18 | System.out.println("Enter the " + numS + " Numbers: \n"); 19 | for(int i = 1; i <= numS; i++){ 20 | System.out.println("Enter Number " + (i) + " : \n"); 21 | a = calc.nextDouble(); 22 | c += a; 23 | } 24 | System.out.println("\nThe Sum of " + numS + " Numbers is " + c ); 25 | break; 26 | case 2: 27 | System.out.print("\033[H\033[2J"); 28 | System.out.println("\nSubtraction\n"); 29 | System.out.println("Enter How many Numbers you want to Substract: \n"); 30 | numS = calc.nextInt(); 31 | System.out.println("Enter Number 1: \n"); 32 | c = calc.nextDouble(); 33 | System.out.println("Enter the " + numS + " Numbers: \n"); 34 | for(int i = 2; i <= numS; i++){ 35 | System.out.println("Enter Number " + (i) + " : \n"); 36 | a = calc.nextDouble(); 37 | c -= a; 38 | } 39 | System.out.println("\nThe Difference of " + numS + " Numbers is " + c ); 40 | break; 41 | case 3: 42 | System.out.print("\033[H\033[2J"); 43 | System.out.println("\nMultipication\n"); 44 | System.out.println("Enter First Number: \n"); 45 | a = calc.nextDouble(); 46 | System.out.println("Enter Second Number: \n"); 47 | b = calc.nextDouble(); 48 | c = a * b; 49 | System.out.println("\nThe Combination of " + a + " and " + b + " is " + c ); 50 | break; 51 | case 4: 52 | System.out.print("\033[H\033[2J"); 53 | System.out.println("\nDivision\n"); 54 | System.out.println("Enter First Number: \n"); 55 | a = calc.nextDouble(); 56 | System.out.println("Enter Second Number: \n"); 57 | b = calc.nextDouble(); 58 | c = a / b; 59 | System.out.println("\nThe Divison of " + a + " and " + b + " is " + c ); 60 | break; 61 | case 5: 62 | System.out.print("\033[H\033[2J"); 63 | System.out.println("\nModulus\n"); 64 | System.out.println("Enter First Number: \n"); 65 | a = calc.nextDouble(); 66 | System.out.println("Enter Second Number: \n"); 67 | b = calc.nextDouble(); 68 | c = a % b; 69 | System.out.println("\nThe Modulus of " + a + " and " + b + " is " + c ); 70 | break; 71 | case 6: 72 | System.out.print("\033[H\033[2J"); 73 | System.out.println("Enter side x: "); 74 | x = calc.nextDouble(); 75 | System.out.println("\nEnter side y: "); 76 | y = calc.nextDouble(); 77 | z = Math.sqrt((x * x) + (y * y)); 78 | System.out.println("The Hypotenuse is " + z); 79 | break; 80 | case 7: 81 | System.out.print("\033[H\033[2J"); 82 | Scanner pow = new Scanner(System.in); 83 | int base, exp, oexp, result = 1; 84 | System.out.println("Enter Base Number: "); 85 | base = pow.nextInt(); 86 | System.out.println("Enter an Exponent: "); 87 | exp = pow.nextInt(); 88 | oexp = exp; 89 | while(exp != 0){ 90 | result *= base; 91 | --exp; 92 | } 93 | System.out.println("The Power of " + base + " Raised to " + oexp + " is " + result); 94 | break; 95 | case 8: 96 | System.out.print("\033[H\033[2J"); 97 | int min, max; 98 | Scanner randN = new Scanner(System.in); 99 | System.out.println("Enter the min number: "); 100 | min = randN.nextInt(); 101 | System.out.println("Enter the max number: "); 102 | max = randN.nextInt(); 103 | int randNumber = (int)(Math.random() * (max - min + 1) + min); 104 | System.out.println("Random Number Between " + min + " to " + max + " is " + randNumber); 105 | break; 106 | case 9: 107 | System.out.print("\033[H\033[2J"); 108 | double f, cel; 109 | int option; 110 | Scanner con = new Scanner(System.in); 111 | System.out.println("1. Celsius to Fahrenheit \n2. Fahrenheit to Celsius \nEnter Your Choice: "); 112 | option = con.nextInt(); 113 | switch(option){ 114 | case 1: 115 | System.out.println("Enter Temperature in Celsius: "); 116 | cel = con.nextDouble(); 117 | f = (cel * 9/5) + 32; 118 | System.out.println("The Temperature of " + cel + " Celsius in Fahrenheit is: " + f); 119 | break; 120 | case 2: 121 | System.out.println("Enter Temperature in Fahrenheit: "); 122 | f = con.nextDouble(); 123 | cel = (f - 32) * 5/9; 124 | System.out.println("The Temperature of " + f + " Fahrenheit in Celsius is: " + cel); 125 | break; 126 | } 127 | break; 128 | case 10: 129 | System.out.print("\033[H\033[2J"); 130 | int ce = 0, ae, temp, n; 131 | Scanner num = new Scanner(System.in); 132 | System.out.print("Enter number to be checked: "); 133 | n = num.nextInt(); 134 | temp = n; 135 | while(n > 0){ 136 | ae = n % 10; 137 | n = n/10; 138 | ce = ce+(ae*ae*ae); 139 | } 140 | if(temp == ce){ 141 | System.out.println(temp+" is an Armstrong Number."); 142 | }else{ 143 | System.out.println(temp+" is not an Armstrong Number."); 144 | } 145 | break; 146 | case 11: 147 | System.out.print("\033[H\033[2J"); 148 | Scanner revNum = new Scanner(System.in); 149 | int rnum, rev = 0, remainder; 150 | System.out.println("Enter an Integer: "); 151 | rnum = revNum.nextInt(); 152 | while(rnum != 0){ 153 | remainder = rnum % 10; 154 | rev = rev * 10 + remainder; 155 | rnum /= 10; 156 | } 157 | System.out.println("Reversed Number of " + rnum + " is " + rev); 158 | break; 159 | case 12: 160 | System.out.print("\033[H\033[2J"); 161 | Scanner circle = new Scanner(System.in); 162 | double radius, circumference, area, diameter; 163 | int choice; 164 | System.out.println("Circle\n1. Radius \n2. Diameter \n3. Circumference \n4. Area \nEnter Your Choice: "); 165 | choice = circle.nextInt(); 166 | switch(choice){ 167 | case 1: 168 | System.out.println("Enter Circumference of Circle: "); 169 | circumference = circle.nextDouble(); 170 | radius = circumference/(2 * 3.14); 171 | System.out.println("Radius of Circumference " + circumference + " = " + radius); 172 | break; 173 | case 2: 174 | System.out.println("Enter Radius of Circle: "); 175 | radius = circle.nextDouble(); 176 | diameter = 2 * radius; 177 | System.out.println("The Diameter of radius " + radius + " Circle = " + diameter); 178 | break; 179 | case 3: 180 | System.out.println("Enter Radius of Circle: "); 181 | radius = circle.nextDouble(); 182 | circumference = 2 * 3.14 * radius; 183 | System.out.println("The Circumference of Radius " + radius + " Circle = " + circumference); 184 | break; 185 | case 4: 186 | System.out.println("Enter Radius of Circle: "); 187 | radius = circle.nextDouble(); 188 | area = 3.14 * radius * radius; 189 | System.out.println("The Area of Radius " + radius + " Circle = " + area); 190 | break; 191 | } 192 | break; 193 | case 13: 194 | System.out.print("\033[H\033[2J"); 195 | double length, width, rectangleArea, perimeter, diagonal; 196 | int option1; 197 | Scanner rectangle = new Scanner(System.in); 198 | System.out.println("Rectangle\n1. Area \n2. Diagonal \n3. Perimeter \n4. Length \n5. Width \nEnter Your Choice: "); 199 | option1 = rectangle.nextInt(); 200 | switch(option1){ 201 | case 1: 202 | System.out.println("Enter Length of the Rectangle: "); 203 | length = rectangle.nextDouble(); 204 | System.out.println("Enter Width of the Rectangle: "); 205 | width = rectangle.nextDouble(); 206 | rectangleArea = length * width; 207 | System.out.println("The Area of the Rectangle " + length + " Length " + width + " Width is " + rectangleArea); 208 | break; 209 | case 2: 210 | System.out.println("Enter Length of the Rectangle: "); 211 | length = rectangle.nextDouble(); 212 | System.out.println("Enter Width of the Rectangle: "); 213 | width = rectangle.nextDouble(); 214 | diagonal = Math.sqrt((length * length) + (width * width)); 215 | System.out.println("The Diagonal of the Rectangle " + length + " Length " + width + " width is " + diagonal); 216 | break; 217 | case 3: 218 | System.out.println("Enter Length of the Rectangle: "); 219 | length = rectangle.nextDouble(); 220 | System.out.println("Enter Width of the Rectangle: "); 221 | width = rectangle.nextDouble(); 222 | perimeter = 2 * (length + width); 223 | System.out.println("The Perimeter of the Rectangle " + length + " Length " + width + " width is " + perimeter); 224 | break; 225 | case 4: 226 | System.out.println("Enter Width of the Rectangle: "); 227 | width = rectangle.nextDouble(); 228 | System.out.println("Enter Perimeter of the Rectangle: "); 229 | perimeter = rectangle.nextDouble(); 230 | length = (perimeter/2) - width; 231 | System.out.println("The Length of Rectangle whose Perimeter = " + perimeter + " and Width = " + width + " is " + length); 232 | break; 233 | case 5: 234 | System.out.println("Enter Length of the Rectangle: "); 235 | length = rectangle.nextDouble(); 236 | System.out.println("Enter Perimeter of the Rectangle: "); 237 | perimeter = rectangle.nextDouble(); 238 | width = (perimeter/2) - length; 239 | System.out.println("The Width of Rectangle whose Perimeter = " + perimeter + " and Length = " + length + " is " + width); 240 | break; 241 | } 242 | break; 243 | case 14: 244 | System.out.print("\033[H\033[2J"); 245 | Scanner tables = new Scanner(System.in); 246 | int tNum; 247 | System.out.println("Enter a Number Whose Table you want to see: "); 248 | tNum = tables.nextInt(); 249 | System.out.println("\n" + tNum + " x 1 = " + tNum * 1 + " \n"); 250 | System.out.println(tNum + " x 2 = " + tNum * 2 + " \n"); 251 | System.out.println(tNum + " x 3 = " + tNum * 3 + " \n"); 252 | System.out.println(tNum + " x 4 = " + tNum * 4 + " \n"); 253 | System.out.println(tNum + " x 5 = " + tNum * 5 + " \n"); 254 | System.out.println(tNum + " x 6 = " + tNum * 6 + " \n"); 255 | System.out.println(tNum + " x 7 = " + tNum * 7 + " \n"); 256 | System.out.println(tNum + " x 8 = " + tNum * 8 + " \n"); 257 | System.out.println(tNum + " x 9 = " + tNum * 9 + " \n"); 258 | System.out.println(tNum + " x 10 = " + tNum * 10 + " \n"); 259 | break; 260 | case 15: 261 | System.out.print("\033[H\033[2J"); 262 | int rows, rows1, columns, columns1, option2, i, j, k, rSum = 0; 263 | int[][] matrix1 = new int[100][100], matrix2 = new int[100][100], mSum = new int[100][100]; 264 | Scanner matrix = new Scanner(System.in); 265 | System.out.println("1. Addition \n2. Subtraction \n3. Multipication \n4. Transpose \nEnter Your Choice: "); 266 | option2 = matrix.nextInt(); 267 | switch(option2){ 268 | case 1: 269 | System.out.println("Enter Number of Rows: "); 270 | rows = matrix.nextInt(); 271 | System.out.println("Enter Number of Columns: "); 272 | columns = matrix.nextInt(); 273 | System.out.println("\nEnter elements of 1st matrix: \n"); 274 | for(i = 0; i < rows; ++i){ 275 | for(j = 0; j < columns; ++j){ 276 | System.out.format("Enter Element A%d%d: ", i + 1, j + 1); 277 | matrix1[i][j] = matrix.nextInt(); 278 | } 279 | } 280 | System.out.println("Enter element of 2nd matrix: "); 281 | for(i = 0; i < rows; ++i){ 282 | for(j = 0; j < columns; ++j){ 283 | System.out.format("Enter Element B%d%d: ", i + 1, j + 1); 284 | matrix2[i][j] = matrix.nextInt(); 285 | } 286 | } 287 | for(i = 0; i < rows; ++i){ 288 | for(j = 0; j < columns; ++j){ 289 | mSum[i][j] = matrix1[i][j] + matrix2[i][j]; 290 | } 291 | } 292 | System.out.println("\nSum of Two Matrices: \n"); 293 | for(i = 0; i < rows; ++i){ 294 | for(j = 0; j < columns; ++j){ 295 | System.out.format("%d ", mSum[i][j]); 296 | if(j == columns - 1){ 297 | System.out.println("\n"); 298 | } 299 | } 300 | } 301 | break; 302 | case 2: 303 | System.out.println("Enter Number of Rows: "); 304 | rows = matrix.nextInt(); 305 | System.out.println("Enter Number of Columns: "); 306 | columns = matrix.nextInt(); 307 | System.out.println("\nEnter elements of 1st matrix: \n"); 308 | for(i = 0; i < rows; ++i){ 309 | for(j = 0; j < columns; ++j){ 310 | System.out.format("Enter Element A%d%d: ", i + 1, j + 1); 311 | matrix1[i][j] = matrix.nextInt(); 312 | } 313 | } 314 | System.out.println("Enter element of 2nd matrix: "); 315 | for(i = 0; i < rows; ++i){ 316 | for(j = 0; j < columns; ++j){ 317 | System.out.format("Enter Element B%d%d: ", i + 1, j + 1); 318 | matrix2[i][j] = matrix.nextInt(); 319 | } 320 | } 321 | for(i = 0; i < rows; ++i){ 322 | for(j = 0; j < columns; ++j){ 323 | mSum[i][j] = matrix1[i][j] - matrix2[i][j]; 324 | } 325 | } 326 | System.out.println("\nDifference of Two Matrices: \n"); 327 | for(i = 0; i < rows; ++i){ 328 | for(j = 0; j < columns; ++j){ 329 | System.out.format("%d ", mSum[i][j]); 330 | if(j == columns - 1){ 331 | System.out.println("\n"); 332 | } 333 | } 334 | } 335 | break; 336 | case 3: 337 | System.out.println("Enter the number of rows of Matrix 1: "); 338 | rows = matrix.nextInt(); 339 | System.out.println("Enter the number of columns of Matrix 1: "); 340 | columns = matrix.nextInt(); 341 | matrix1 = new int[rows][columns]; 342 | System.out.println("Enter elements of Matrix 1: "); 343 | for(i = 0; i < rows; ++i){ 344 | for(j = 0; j < columns; ++j){ 345 | System.out.format("Enter Element A%d%d: ", i + 1, j + 1); 346 | matrix1[i][j] = matrix.nextInt(); 347 | } 348 | } 349 | System.out.println("Enter the number of rows of Matrix 2: "); 350 | rows1 = matrix.nextInt(); 351 | System.out.println("Enter the number of columns of Matrix 2: "); 352 | columns1 = matrix.nextInt(); 353 | if(columns != rows1){ 354 | System.out.println("The Matrices cant be multiplied with each other as Number of columns of Matrix 1 id not equal to Number of rows of Matrix 2."); 355 | }else{ 356 | int[][] second = new int[rows1][columns1]; 357 | int[][] multiply = new int[rows][columns1]; 358 | System.out.println("Enter Elements of Matrix 2: "); 359 | for(i = 0; i < rows1; ++i){ 360 | for(j = 0; j < columns1; ++j){ 361 | System.out.format("Enter Element A%d%d: ", i + 1, j + 1); 362 | second[i][j] = matrix.nextInt(); 363 | } 364 | } 365 | for(i = 0; i < rows; i++){ 366 | for(j = 0; j < columns; j++){ 367 | for(k = 0; k < rows1; k++){ 368 | rSum = rSum + matrix1[i][k] * second[k][j]; 369 | } 370 | multiply[i][j] = rSum; 371 | rSum = 0; 372 | } 373 | } 374 | System.out.println("Product of the Matrices: "); 375 | for(i = 0; i < rows; i++){ 376 | for(j = 0;j < columns1; j++){ 377 | System.out.format("%d\t", multiply[i][j]); 378 | if(j == columns1 - 1){ 379 | System.out.print("\n"); 380 | } 381 | } 382 | } 383 | } 384 | break; 385 | case 4: 386 | System.out.println("Enter Number of Rows: "); 387 | rows = matrix.nextInt(); 388 | System.out.println("Enter Number of Columns: "); 389 | columns = matrix.nextInt(); 390 | System.out.println("\nEnter elements of the matrix: \n"); 391 | for(i = 0; i < rows; ++i){ 392 | for(j = 0; j < columns; ++j){ 393 | System.out.format("Enter Element A%d%d: ", i + 1, j + 1); 394 | matrix1[i][j] = matrix.nextInt(); 395 | } 396 | } 397 | System.out.println("The Matrix is: "); 398 | for(i = 0; i < rows; i++){ 399 | for(j = 0; j < columns; j++){ 400 | System.out.print(matrix1[i][j] + " "); 401 | } 402 | System.out.println(); 403 | } 404 | int[][] transpose = new int[columns][rows]; 405 | for(i = 0; i < rows; i++){ 406 | for(j = 0; j < columns; j++){ 407 | transpose[i][j] = matrix1[j][i]; 408 | } 409 | } 410 | System.out.println("Printing Matrix After Transpose: "); 411 | for(i = 0; i < rows; i++){ 412 | for(j = 0; j < columns; j++){ 413 | System.out.print(transpose[i][j] + " "); 414 | } 415 | System.out.println(); 416 | } 417 | break; 418 | } 419 | break; 420 | case 16: 421 | System.out.print("\033[H\033[2J"); 422 | e = 1; 423 | System.out.println("\nThank You For Visiting\n"); 424 | System.exit(0); 425 | break; 426 | } 427 | } calc.close(); 428 | } 429 | } 430 | --------------------------------------------------------------------------------