Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads a sequence of integer values from the user, slopping

ID: 3757719 • Letter: W

Question

Write a program that reads a sequence of integer values from the user, slopping when the user enters a negative integer. After that, output only odd numbers. If the sequence of integer lances did not include any odd numbers, output an appropriate message like There is no odd number in the sequence. An example is shown below, where the user enters ease enter 1 0 5 8 9 5 -9 please enter a whitespace-separated sequence of integers: 10 5 8 19 51 -9 Odd number: 5, 19, 51 where the user enters 2 8 34 -2. please enter a whitespace-separated sequence of integers: 2 8 34 -2 There is no odd number in the sequence.

Explanation / Answer

Try this it might help you

#include <stdio.h>

int main()

{

      int num = 0, remainder = 0;

   

      // while -1 not entered...

      while(num != -1)

      {

            // prompt user for input

            printf("Enter an integer (-1 to stop): ");

            // read and store input, then modulus by 2

            scanf_s("%d", &num, sizeof(int));

            // ready to stop if -1 else...

            if(num != -1)

            {

                  remainder = num % 2;

                  // test for even/odd. If the modulus yields 0, it is even

                  if(remainder == 0)

                        printf("%d is an even number. ", num);

                  else

                        printf("%d is an odd number. ", num);

            }

      }

      // -1 was entered

      printf("%d is an odd number. ", num);

      printf("You ask to stop! Thank you. ");

      return 0;

}