Advertisement
Dido09

C - OddEven/ProductSum

May 23rd, 2022
500
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int i, num1, num2, sum = 0, product = 1;
  6.  
  7.     printf("Enter the first number:  ");
  8.     scanf("%d", &num1);
  9.     printf("Enter the second number: ");
  10.     scanf("%d", &num2);
  11.  
  12.     for(i < num1 + 1; i <= num2; i++){
  13.         if(i % 2 == 0){
  14.             sum = sum + i;
  15.         }
  16.         if(i % 2 != 0){
  17.             product = product * i;
  18.         }
  19.     }
  20.     printf("\n");
  21.     printf("Sum of even numbers: %d\n", sum);
  22.     printf("Product of odd numbers: %d", product);
  23.  
  24.     return 0;
  25. }
  26.  
Advertisement
RAW Paste Data Copied
Advertisement