Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
30290d4
Use of CMakeLists.txt
hsrai Sep 10, 2019
16c004a
Merge pull request #4 from Jasmine78/master
hsrai Sep 11, 2019
1faeaaf
odt file removed
hsrai Sep 11, 2019
c8126e6
Notes about Array
hsrai Sep 11, 2019
1f1b90a
Simplified
hsrai Sep 11, 2019
9eba5ba
Image added
hsrai Sep 11, 2019
9dd5d86
Add files via upload
hardeep4142 Sep 12, 2019
ef080b4
Merge pull request #5 from hardeep4142/master
hsrai Sep 12, 2019
0a6ef1c
Arithmetic Expressions
ranjodh-kaur Sep 13, 2019
e1cd819
Merge pull request #6 from ranjodh-kaur/master
hsrai Sep 13, 2019
ac69344
Draft version. Don't read it.
hsrai Sep 13, 2019
f20aabc
Broken link
hsrai Sep 14, 2019
311d855
Broken link moved
hsrai Sep 14, 2019
a7ccf56
Draft01
hsrai Sep 15, 2019
7626317
File moved
hsrai Sep 15, 2019
d7fbaef
Draft added
hsrai Sep 15, 2019
ff5c97e
Arithmetic Expression
ranjodh-kaur Sep 17, 2019
5b9cc01
Merge pull request #9 from ranjodh-kaur/master
hsrai Sep 18, 2019
6c3c196
Expreesion notes linked
hsrai Sep 18, 2019
a3c2686
All notes linked
hsrai Sep 18, 2019
c5046af
Merge branch 'master' of https://github.com/gne-ldh/PPS
hsrai Sep 30, 2019
4a4fc92
A few new C files and md file for C-Tutorial
hsrai Sep 30, 2019
eb947c5
A part of C-Tutorial
hsrai Sep 30, 2019
90ca208
Program about limits of numbers
hsrai Oct 1, 2019
32399c5
Files re-organised
hsrai Oct 1, 2019
cc0d970
Files moved to Bank folder
hsrai Oct 1, 2019
d3830a5
CMakeLists.txt added
hsrai Oct 1, 2019
6d8bbcb
Line on console
hsrai Oct 2, 2019
5a60940
Add files via upload
mansher0693 Nov 19, 2019
0da27c7
Add files via upload
mansher0693 Nov 19, 2019
a586788
Add files via upload
mansher0693 Nov 19, 2019
a6ff71d
Create pps1
mansher0693 Nov 19, 2019
ee38254
Create pps
mansher0693 Nov 19, 2019
a01aabe
Rename pps to pps.md
mansher0693 Nov 19, 2019
02c5dfc
Update pps.md
mansher0693 Nov 19, 2019
c0f8763
Update pps.md
mansher0693 Nov 19, 2019
12d21e0
Update pps.md
mansher0693 Nov 19, 2019
ad83f82
Add files via upload
mansher0693 Nov 29, 2019
9c914ff
Delete Array.md
mansher0693 Nov 29, 2019
679cb6e
Delete pps1
mansher0693 Nov 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added 10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,219 changes: 1,219 additions & 0 deletions 1915331-mansher.md

Large diffs are not rendered by default.

Binary file added 19a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 19b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 25a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 25b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 26.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 26a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 27.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 27a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 28.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 28a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 29.png
Binary file added 3.png
Binary file added 30a.png
Binary file added 30b.png
Binary file added 31.png
Binary file added 32.png
Binary file added 33.png
Binary file added 34.png
Binary file added 35.png
Binary file added 4.png
Binary file added 5.png
Binary file added 6.png
Binary file added 7.png
Binary file added 8.png
Binary file added 9.png
250 changes: 250 additions & 0 deletions Content/Notes/Files/Branching_and_looping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
# Branching and Looping
## Branching -:
Branching is a basic concept in computer science. It means an instruction that tells a computer to begin executing a different part of a program rather than executing statements one-by-one.

1. If Statement
2. The If else Statement
3. Compound Relational tests
4. Nested if Statement
5. Switch Statement

### If Statement
- If statement is the simplest form of the control statement. It is very frequently used in allowing the flow of program execution and decision making.
- The If structure has the following syntax
>if(condition)
statement;
- The command says that if the condition is true then perform the following statement or If the condition is fake the computer skips the statement and moves on to the next instruction in the program
##### The following program calculate the absolute value of an integer using if statement:

```sh
#include < stdio.h > //Include the stdio.h file
void main ( ) // start of the program
{
int numbers; // Declare the variables
printf (“Type a number:”); // message to the user
scanf (“%d”, & number); // read the number from standard input
if (number < 0) // check whether the number is a negative
number
number = – number; // If it is negative then convert it into
positive.
Printf (“The absolute value is % d \n”, number); // print the value
}
```
### The If else Statement
- The if else is actually just an extension of the general format of if statement. If the result of the condition is true, then program statement 1 is executed else program statement 2 will be executed.
- The syntax of the If else statement is as follows:

>If (condition)
Program statement 1;
Else
Program statement 2;


##### The following program find whether a number is negative or positive using if statement:
#
```sh
#include < stdio.h > //include the stdio.h header file in your program
void main ( ) // Start of the main
{
int num; // declare variable num as integer
printf (“Enter the number”); //message to the user
scanf (“%d”, &num); // read the input number from keyboard
if (num < 0) // check whether number is less than zero.
Printf (“The number is negative”) // If it is less than zero then it is negative.
Else // else statement.
Printf (“The number is positive”); //If it is more than zero then the given
number is positive.
```
### Compound Relational tests
- To perform compound relational tests,C language provides the necessary mechanisms. A compound relational test is simple one or more simple relational tests joined together by either the the logical OR operators or logical AND. These operators are represented by character pairs && // respectively. To form complex expressions in C,the compound operators can be used.
- The syntax of the Compound Relational tests is as follows:

> a> if (condition1 && condition2 && condition3)
> b>if (condition1 // condition2 // condition3)


### Nested if Statement
- The if statement may itself contain another if statement is called as nested if statement. - - The syntax of the Nested if Statement is as follows

>if (condition1)
if (condition2)
statement-1;
else
statement-2;
else
statement-3;


##### The following example print the given numbers along with the largest number using nested if statement.
#
```sh
#include < stdio.h > //includes the stdio.h file to your program
main ( ) //start of main function
{
int a,b,c,big; //declaration of variables
printf (“Enter three numbers”); //message to the user
scanf (“%d %d %d”, &a, &b, &c); //Read variables a,b,c,
if (a>b) // check whether a is greater than b if true then
if(a>c) // check whether a is greater than c
big = a ; // assign a to big
else big = c ; // assign c to big
else if (b>c) // if the condition (a>b) fails check whether b is
greater than c
big = b ; // assign b to big
else big = c ; // assign C to big
printf (“Largest of %d,%d&%d = %d”, a,b,c,big);
}
//print the given numbers along with the largest number.
```
### Switch Statement
- The switch-case statement is a multi-way decision making statement. Unlike the multiple decision statement that can be created using if-else, the switch statement evaluates the conditional expression and tests it against the numerous constant values.During execution,the branch corresponding to the value that the expression matches is taken.
- The value of the expressions in a switch-case statement must have to be an ordinal type i.e. integer, char, short, long, etc.Double and Float are not allowed.
- The syntax of switch statement is as follows :

>switch( expression )
{
case constant-expression1: statements1;
[case constant-expression2: statements2;]
[case constant-expression3: statements3;]
[default : statements4;]
}

##### The following program find whether a number is negative or positive using if statement:
#
```sh
#include <stdio.h>
main()
{
int n=7;
switch(n) {
case 0:
printf(“You typed zero.\n”);
break;
case 3:
case 5:
case 7:
printf(“n is a prime number\n”);
break;
case 2: printf(“n is a prime number\n”);
case 4:
case 6:
case 8:
printf(“n is an even number\n”);
break;
case 1:
case 9:
printf(“n is a perfect square\n”);
break;
default:
printf(“Only single-digit numbers are allowed\n”);
break;
}
}
```

## Looping -:
Looping statement are the statements execute one or more statement repeatedly several number of times. In
1. while loop
2. for loop
3. do while

### while loop
- In While Loop in C First check the condition if condition is true then control goes inside the loop body other wise goes outside the body. while loop will be repeats in clock wise direction.
- The syntax of the while statement is as follows:
>Assignment;
while(condition)
{
Statements;
......
Increment/decrements (++ or --);
}
Note: If while loop condition never false then loop become infinite loop.


##### Example of while loop:
#
```sh
#include<stdio.h>

void main()
{
int i;
clrscr();
i=1;
while(i<5)
{
printf("\n%d",i);
i++;
}
}
```

### for loop
- TFor Loop in C is a statement which allows code to be repeatedly executed. For loop contains 3 parts Initialization, Condition and Increment or Decrements.
- The syntax of the for loop statement is as follows:

>for(init; condition; increment)
{
loop body;
}


##### Example of for loop:
#
```sh
#include<stdio.h>

void main()
{
int i;
clrscr();
for(i=1;i<5;i++)
{
printf("\n%d",i);
}
}
```
### do-while
- TA do-while Loop in C is similar to a while loop, except that a do-while loop is execute at least one time.
- A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given condition at the end of the block (in while).
- The syntax of the do-while loop statement is as follows:

>do
{
Statements;
........
Increment/decrement (++ or --)
} while();


##### Example of do while loop:
#
```sh
#include<stdio.h>

void main()
{
int i;
clrscr();
i=1;
do
{
printf("\n%d",i);
i++;
}
while(i<5);
}
```













Loading