Computer Science, asked by vishruti800, 1 year ago

write a short program to print the following series 1 -4 7 -10....-40​

Answers

Answered by vcharithacherry
70

Answer:

a = 1

while a<=40:

      if a%2==0:

           print(-a, end=' ')

      else:

           print(a,end=' ')

       a=a+3

Answered by ParvezShere
17

Using C++ to answer

#include<iostream>

using namespace std;

int main()

{

for(int i = 1; i <=40; i = i + 3)

{

if (i%2==0)

cout<<-i+" ";

else

cout<<i+" ";

}

}

Similar questions