Computer Science, asked by sumonanusrat07, 6 months ago

Given a number N. Print all even numbers between 1 and N inclusive in separate lines.

Input
Only one line containing a number N (1 ≤ N ≤ 103).

Output
Print the answer according to the required above. If there are no even numbers print -1.

Answers

Answered by ama789238
1

Answer:

#include <stdio.h>

int main ()

{

int n, i;

scanf ("%d", &n);

for(i=1;i<=n;i++)

{

if(i%2==0)

{

printf ("%d\n",i);

}

else

printf ("-1");

}

Answered by ankhidassarma9
0

Answer:

#include <stdio.h>

int main()

{

   int  i, count=0, p, y;

   printf("Enter the number of intervals between 1 to 103: \n");

   scanf("%d", &y);

   

       for(i=1;i<=y; i++)

       {

           p=i%2;

           if(p==0)

           {

              printf(" %d", i);

              count ++;

           }

           

       }

      if(count==0)

           {

               printf(" No Even number \n");

               printf(" %d", -1);

           }

       return 0;

}

Explanation:

  • The above C program will print all even numbers between 1 and N (1 ≤ N ≤ 103) inclusive in separate lines.
  • If there are no even numbers, it will  print -1.

   Input: Enter the number for intervals between 1 to 103:

              1

  Output: No Even number

                 -1

  Input: Enter the number for intervals between 1 to 103:

              25

 Output: 2 4 6 8 10 12 14 16 18 20 22 24

For similar kind of answer, click here->

https://brainly.in/question/10556224

https://brainly.in/question/7157458

Similar questions