K&R C Exercise 2-2: Loop Without && or ||

Exercise 2-2. Write a loop equivalent to the for loop below without using && or ||: for (i = 0; i < lim – 1 && (c = getchar()) != ‘\n’ && c != EOF; ++i) s[i] = c; Understanding the Problem The && operator in C is a short-circuit operator: if the left operand …

C Program to Print Multiplication Table – Single Table and N×N Grid

A multiplication table in C is printed using a for loop that multiplies a given number by each integer from 1 to 10. For a full N×N grid, two nested loops are used: the outer loop for the row, the inner loop for the column, with i * j at the intersection. This is one …

Sum of Digits of a Number in C – Loop and Recursion

Finding the sum of digits of a number in C is a classic programming exercise that teaches digit extraction using the modulo operator. You extract each digit by taking n % 10, add it to a running total, then divide n by 10 to drop the last digit. Repeat until no digits remain. This technique …