202k views
1 vote
Write a c program to find product of all even numbers between 10 t0 30

User Valerii
by
4.0k points

2 Answers

5 votes

CODE

#include <stdio.h>

int main() {

long long int product = 1;

for(int i = 10; i <= 30; i = i + 1) {

if(i%2 == 0) {

product = product * i;

}

}

printf("%lld",product);

return 0;

}

DISPLAY

111588212736000

EXPLANATION

Declare the variable product as a long long integer type to hold 8 bytes.

Use a for loop which initializes at 10 and maximizes at 30, and increases a point each time.

Use an if statement to check for even numbers by checking the remainder.

Display the product.

User Max Hampton
by
4.0k points
2 votes

Answer:

#include <stdio.h>

int main(void) {

unsigned long n = 1;

for(unsigned long i=10; i<=30; i+=2) {

n *= i;

}

printf("%lu",n);

return 0;

}

Step-by-step explanation:

The output is: 111588212736000

The answer will take 47 bits, so you have to use 64-bit longs. An int is 32 bit thus will give the wrong answer due to a numeric overflow.

User Silveri
by
4.4k points