100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Loops $8.59   Add to cart

Class notes

Loops

 1 view  0 purchase
  • Course
  • Institution

This document will help you to cover basic knowledge of loops and build a foundation for further coding level from basic to advanced level.

Preview 1 out of 1  pages

  • February 27, 2023
  • 1
  • 2022/2023
  • Class notes
  • Charlie
  • All classes
avatar-seller
Lecture 1: If-Else, While loop & Lots of
Patterns
- by Adi

In this 3rd lecture, we will learn the syntax of conditional statements in
CPP. We will make a simple program , where we will ask computer to
print A if A is bigger than B , else print B. Coding Ninjas has supported
us in providing this free DSA course. If you are given a number A , and
you are told that print +ve if A is positive, otherwise, print not +ve. If
a block is not executed, then 'else ' block will be executed. If A is 5 ,
then 'if A is -2 and if a is -5, then it will print anything. If I enter -5 ,
then it did n't print anything because if block was not executed this
time. But if I add a 'else' block here, then this block is executed. Cin.
get ( ) takes input in the form of characters. It took ' 1 ' as a character
but we are assigning this value to an integer so that 's why it printed
ASCII value of that character. Cin do n't read SPACE , TAB , ENTER and
TAB. But we have an another method to take input. Let 's code that
tells us which number is greater.

If ( a > 0) { print +ve } else { if ( a < 0 ) { print negative } , otherwise
print 0 } } Let 's run it again. Entered A as 15 It printed A is positive
This time I entered -1. A is negative. Correct output. We solved it using
loop using loop to understand loops clearly. You just have to enter a
condition and the statements which you want to execute. You can
check your answer by applying this formula Bhaiya. Here is your
homework question. Q1- Find sum of all even numbers from 1 to N. We
have to tell whether n is prime or not prime number is a number which
has only 1 and N as it 's factor We will use this % operator for this
question. % tells us remainder when we divide 2 numbers. If any of
these numbers gave modules as 0, then N is not prime. If no such
number exists, then it is a prime number.

We will run a loop from 1 to n , ( for all rows ) We declared a variable i
to keep the track of the row number and then we are simply printing
star in each column Then we wrote this cout < endl , to come to a new
line , and after that this code will get executed for every row. We will
do many patterns problems in the next video. We will code this
triangular figure also in next video. But first let 's understand this
code. We will run a loop from 1 to n , ( for all rows ) Then we declared
a variable J for columns. J will also run from 1- N and we simply have to
print the row number. Then we incremented J inside the column loop
and Incrementing i inside the row loop after printing ENTER.

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller adisaxena. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $8.59. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79223 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$8.59
  • (0)
  Add to cart