Posts

Showing posts with the label Basic Arithmetic Operators

C: Basic Arithmetic Operators.

Image
 https://github.com/pereiradaniel/beginning_c/blob/master/ch2/arithm.c // arithm.c // Daniele Grech Pereira, 02 November 2022 // Use basic arithmetic operators. #include <stdio.h> int main (int argc, char* argv[]) { // Declare and initialize vars: int add[2] = {0}, mult[2] = {0}, div[2] = {0}; double div2[2] = {0}; printf("All vars have been declared and initialized:\n"); printf("add1: %d, add2: %d, mult1: %d, mult2: %d, div1: %d, div2: %d, div3: %.2lf, div4: %.2lf.\n", add[0], add[1], mult[0], mult[1], div[0], div[1], div2[0], div2[1]); printf("Enter first whole number to add: \n"); scanf(" %d", &add[0]); printf("Enter second whole number to add: \n"); scanf(" %d", &add[1]); printf("add1 + add2 = ?\n%d + %d = %d\n", add[0], add[1], add[0]+add[1]); printf("Enter first whole number to multiply: \n"); scanf(" %d", &mult[0]); ...