-4
#include <stdio.h>
int main()
{
    int n, range, i;
    printf("Enter an integer to find multiplication table: ");
    scanf("%d",&n);
    printf("Enter range of multiplication table:");
    scanf("%d",&range);
    for(i=1;i<=range;++i)
{
    printf("%d * %d = %d\n", n, i, n*i);
}
return 0;

}

I need to display odd next to multiples that are odd and even next to even multiples.

Muroo
  • 1
  • 3

3 Answers3

1

Use the modulo

if ((n*i)%2 == 0)
  printf("EVEN : %d * %d = %d\n", n, i, n*i);
else
  printf("ODD : %d * %d = %d\n", n, i, n*i);
Yann
  • 194
  • 13
1

Modify your printf() statement to:

printf ( "%d * %d = %d : %s\n", n, i, n*i, (n*i % 2 == 0) ? "EVEN" : "ODD" );

The modulus operator gives the remainder of n divided by 2.

Mahesh Bansod
  • 1,021
  • 1
  • 19
  • 31
1

The best way to check if a number is even or odd is by using bitwise operators.

if (i & 1) { // It's odd }

else { //it is even }

Parag Gangil
  • 1,168
  • 2
  • 11
  • 26