Computer Science, asked by ananyasinha51, 1 day ago

write a program to print the following series : 1 2 * 4 5 6 7 8​

Answers

Answered by MichMich0945
0

Program(s):

C/C++

#include <stdio.h>

int main()

{

   int num;

   for (num = 1; num <= 8; num++)

   {

       if (num == 3)

       {

           printf("* ");

       }

       else if (num == 8)

       {

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

       }

       else

       {

           printf("%d ", num);

       }

   }

   return 0;

}

Python

for num in range (1, 9):

   if num == 3:

       print("*", end=" ")

   else:

       print(num, end=" ")

Output

1 2 * 4 5 6 7 8

Hope this helps you <3

Similar questions