Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

C Program to Find Remainder Without Using % Operator

C Program to Find Remainder Without Using % Operator

✅ C Program to Find Remainder Without Using % Operator

#include <stdio.h>
int main() {
    int a, b;
    printf("Enter two numbers (a %% b): ");
    scanf("%d %d", &a, &b);

    int sign = 1;
    if (a < 0) { a = -a; sign = -sign; } // handle negative dividend
    if (b < 0) { b = -b; }               // divisor just made positive

    while (a >= b) {
        a -= b;   // keep subtracting divisor from dividend
    }

    printf("Remainder is: %d\n", sign * a);
    return 0;
}
  

πŸ“˜ Explanation:

This program calculates the remainder without using the modulus (%) operator. It repeatedly subtracts the divisor from the dividend until the remainder is smaller than the divisor.

  • Handles negative dividends by tracking the sign.
  • a -= b; keeps subtracting divisor until remainder is less.
  • Final result is adjusted using sign * a.

🧾 Sample Output:

Enter two numbers (a % b): 17 5
Remainder is: 2

Enter two numbers (a % b): -17 5
Remainder is: -2
  

πŸ”‘ Keywords:

C program remainder without %, modulus without operator, remainder using subtraction, arithmetic operators in C, tricky C programs

πŸ“Œ Hashtags:

#CProgramming #Modulo #InterviewPrep #LearnC #BitwiseTricks

πŸ” Search Description:

Learn how to find remainder in C without using modulus (%) operator. Uses repeated subtraction and handles negative numbers. Includes explanation and sample output.

Comments

Popular Posts

πŸŒ™