Computer Science, asked by vanshika1393, 1 year ago

Print+,-,+,-,+,- by usin for loop till 10th term

Answers

Answered by Rudhraa
0
in c++

for (int I=1;I<=10;I++)
if ( I %2==0 )
cout<< '-';
else cout<<'+';

vanshika1393: We have to print both +- in a serial order
vanshika1393: Yes please explain me
Answered by userIsDead
3
hlw MAte,

ur AnsWer.........

=====÷÷÷=====÷===÷÷




Loop and loop

We are assuming that you are practicing a lot. If not, then go to the practice section before proceeding. First solve a good number of problems of all the topics covered so far and then come back. In case of any doubt, ask your question in the discussion section

while Loop

What if someone ask you to print 'Hello World' 10 times?

One way is to write the printf statement 10 times. But that is definitely not a good choice if you have to write it 50 times!

So, here comes the while loop.

#include <stdio.h> int main() { int a = 1; while ( a <= 10 ) { printf ( "Hello World\n" ); a ++; } return 0; }

Output

Now, let's understand each line of the code.

First, have a look at the syntax of a while loop.

while(condition)
  {
    statement(s)
  }

While loop checks whether the condition written in '( )' is true or not.
If the condition is found true, then statements written in the body of the while loop i.e., inside the braces { } are executed. Then, again the condition is checked, and if found true then statements in the body of the while loop are executed again. This process continues until the condition becomes false.

For better understanding, let's consider our example step by step.





vanshika1393: In my school my teacher doesn't teach about while loop till now.
userIsDead: is it works??
vanshika1393: Yes
Similar questions