Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: units in economics
Description: they are in PDF and Microsoft word format,precise and easy to understand.well arranged

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


Computer Programming
Tutorial

COMPUTER PROGRAMMING TUTORIAL

Simply Easy Learning by tutorialspoint
...
com
i

ABOUT THE TUTORIAL

Computer Prgramming Tutorial
Computer programming is the act of writing computer programs, which are a sequence of instructions
written using a Computer Programming Language to perform a specified task by the computer
...
This tutorial will
take you through simple and practical approach while learning computer programming
...
I'm confident that after
completing this tutorial you will be at a level where you can code in C Programming language and will
have basic understanding of Java and Python programming languages as well and you can continue
further from that point onwards
...
First reading will not give you much idea, but during your second reading, you will
start grasping most of the concepts and you will enjoy while writing great computer programs
...
If you know more than this like word editor, good typing speed, internet search, etc
...


Copyright & Disclaimer Notice
All

the content and graphics on this tutorial are the property of tutorialspoint
...
Any content from
tutorialspoint
...
com
...

This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the
accuracy of the site or its contents including this tutorial
...
com site
or this tutorial content contains some errors, please contact us at webmaster@tutorialspoint
...
2
Audience
...
2
Copyright & Disclaimer Notice
...
6
What is Computer Program?
...
7
What Computer Program can do?
...
8
What is Algorithm?
...
9
Programming - Environment
...
12
What is Compiler?
...
13
Online Compilation
...
15
Hello World Program in C
...
15
FUNCTIONS
...
16
WHITESPACES
...
17
PROGRAM EXPLANATION
...
18
Hello World Program in Java
...
18
Conclusion
...
20
C & Java Data Types
...
21

Programming - Variables
...
23
Store values in variables
...
25
Variables in Java
...
26
TUTORIALS POINT
Simply Easy Learning

Programming - Keywords
...
28
Java programming reserved keywords
...
28

Programming - Operators
...
30
Relational Operators
...
33
Operators in Java
...
34

Programming - Decisions
...
else statement
...
elseif
...
39
The switch statement
...
42
Decisions in Python
...
43
The while Loop
...
while Loop
...
47
The continue statement
...
49
Loops in Python
...
50
Math Operations on Numbers
...
52
Numbers in Python
...
55
Escape Sequences:
...
57
Characters in Python
...
59
Create Arrays
...
60
Accessing Array Elements
...
61
Arrays (Lists) in Python
...
64
Basic String Concepts
...
66
Strings in Python
...
68
Defining a Function:
...
70
Functions in Java
...
71

Programming – File I/O
...
73
File Input/Output
...
73
Opening Files
...
74
Writing a File
...
75
File I/O in Java
...
77

Programming - Summary
...
You are curious to know what

exactly is computer programming? Before you understand what is computer programming, you need to understand
what is computer program?
I'm making an assumption that you know a little about what is computer and how to use it for Internet browsing,
Exploring Facebook or Checking e-mail using Gmail, etc
...
What
exactly do you do to tell him the way to go to KFC?
You will use Human Language to tell the way to go to KFC something as follows:
First go straight, after half kilometer, take left from the red light and then drive around one kilometer and you will find
KFC at the right
...
If they will be followed in
the following sequence, then you will reach KFC:
1
...

3
...

5
...
Above sequence of instructions is actually aHuman
Program written in English Language, which instructs on how to reach to KFC from a given starting point
...

Now, let's go back and try to understand about a computer program, which is a sequence of instructions written in a
Computer Language to perform a specified task by the computer
...






A computer program is also called a computer software, which can range from two lines to millions of lines of
instructions
...

A computer machine without a computer program is just a dump box and thus computer program brings a
computer machine to live state
...
e
...
We will
see several computer programming languages in subsequent chapters
...

As I mentioned earlier, there are 100s of programming languages, which can be used to write computer programs
and following are few of them:



Java



C



C++



Python



PHP



Perl



Ruby

What Computer Program can do?
Today computer programs are being used in almost every field, household, agriculture, medical, entertainment,
defense, communication, etc
...
, are example of computer programs
...




Computer programs are being used to perform Ultrasounds, X-Rays, and other medical examinations
...


Who is Computer Programmer?
If you understood what is computer program and what is computer programming, then simply apply common sense
to understand who is computer programmer?
Someone, who can write computer programs or in other words, someone who can do computer programming is
called Computer Programmer
Based on computer programming language expertise, we can name computer programmers as follows:



C Programmer



C++ Programmer



Java Programmer



Python Programmer



PHP Programmer



Perl Programmer



Ruby Programmer

What is Algorithm?
From programming point of view, an algorithm is a step-by-step procedure to resolve any problem
...

Thus, a computer programmer lists down all the steps required to resolve a problem before jumping to write actual
code
...

2
...

4
...

6
...

8
...
LN
Assume L1 is the largest, Largest = L1
Take next number Li from the list and do the following
If Largest is less than Li
Largest = Li
If Li is last number from the list then
Print value stored in Largest and come out
Else repeat same process starting from step 3

Above algorithm has been written in very crude way just because to make it clear to beginners, otherwise if you will
study computer algorithm subject then you will find standardized way of writing computer algorithm
...
English

has a predefined grammar, which needs to be followed to write English statements in a correct way
...
) are made of several elements like
verbs, nouns, adjectives, adverbs, propositions, and conjunctions, etc
...
I
will take you through the basics of those elements and put some effort to make you comfortable to use them in
various programming languages
...

First we will try to understand meaning of all these terms in general and then we will see how these terms can be
used in different programming language
...

I designed this tutorial to give you an idea about the following most popular programming languages:



C Programming



Java Programming



Python Programming

Major part of the tutorial has been explained by taking C as programming language and then I tried to show how
similar concepts work in Java and Python
...


TUTORIALS POINT
Simply Easy Learning

3

CHAPTER

Programming - Environment

T

hough Environment Setup is not an element of any Programming Language, it is the first thing we need to

start programming with any Programming Language
...
Thus, we need to have required software setup, i
...
, installation on our PC which will be used to write
our Computer Program, Compile and Execute it
...




Web Browser like Internet Explorer, Chrome, or Safari, etc
...
com
...




A text editor to create computer program
...




An interpreter to execute program directly
...
So, I suggest you
take help from any technical person around you to set up programming environment on your machine from where
you can start
...


What is Text Editor?
This is a Software, which will be used to write your computer program
...
You can launch it by following these steps:
Start Icon → All Programs → Accessories → Notepad → Mouse Click on Notepad
This will launch Notepad with the following window:

You can use this software to type your computer program and save it in a file at any location
...

If you are Mac user, then you will have TextEdit or you can install some other commercial editor likeBBEdit, etc
...


What is Compiler?
You write your computer program using your favorite programming language and save it in a text file called program
file
...
Actually, computer cannot understand your program directly given in the text format, so we need to
convert this program in a binary format, which can be understood by the computer
...
Finally, you can execute
binary file to perform the programmed task
...

Following flow diagram gives an illustration of the process:

So, if you are going to write your program in any such language, which needs compilation like C, C++, Java and
Pascal, etc
...


What is Interpreter?
We just discussed about Compiler and Compilation Process
...
Few
examples of such programming languages are C, C++, Java
...


So, if you are going to write your program in any such language, which does not need compilation like PHP, Python,
Perl, and Ruby, etc
...


Online Compilation
If you are not able to set up any editor, compiler or interpreter on your machine, then tutorialspoint
...

So do not worry and let’s proceed further to have thrilling experience to become a computer programmer in simple
and easy steps
...
I’m going to write a single-line

computer program to write Hello, World! on your screen
...
This Try it option is available at the top rightcorner of the following code box
...
It just prints whatever you keep inside two double quotes
...
h>
main()
{
/* printf() function to write Hello, World! */
printf( "Hello, World!" );
}
This little Hello World program will help us in understanding various basic concepts related to C Programming
...
h> statement, but keep a note that you have to put this statement at the
top of a C program
...

Rest of the program instruction is written in between and finally a right curly brace ends the program
...
The left curly brace can be in the same line as
main(){ or in the next line like it has been mentioned in the above program
...
For example, above program
makes use of two functions (a) main() and (b) printf()
...

You can write your own functions which we will see in separate chapter, but C programming itself provides various
built-in functions like main(), printf(), etc
...


TUTORIALS POINT
Simply Easy Learning

Few programming languages use word sub-routine instead of function but their functionality is more or less same
...
Such statements are called comments and these
comments are used to make program user friendly and easy to understand the program
...
So you can whatever language you
want to write your comments
...
These printable characters are a, b, c,
...
Z, 1, 2, 3,
...
Hope I'm not missing any printable characters from your
keyboard
...
These characters are called whitespaces
...


\n

Tab

This will be used to create a tab
...


empty space

A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally
ignores it
...
So you can
write printf("Hello, World!" ); as follows
...

#include ...
h>\n
\n
main()\n
{
\n
\t/* printf() function to write Hello, World! */
\n
\tprintf(\t"Hello, World!"\t);\n
\n
}\n

TUTORIALS POINT
Simply Easy Learning

SEMICOLONS
Every individual statement in C Program, must be ended with a semicolon ; For example, if you want to write "Hello,
World!" twice, then it will be written as follows:
#include ...
Let us see what happens if I do not
use this new line character:
#include ...


PROGRAM EXPLANATION
Let's try to understand how the above C program to print “Hello, World!” works
...
So let’s put this code in test
...
c -o demo
If there is any grammatical error (Syntax errors in computer terminologies), then we fix it before converting it into
binary format
...
Finally we execute produced binary
demo as follows:
$
...
out file, what computer does is, it enters inside the program starting from main()
and encounters a printf() statements
...
*/ is a comment so it is filtered at the time of
compilation
...
Finally it
encounters a right curly brace which indicates the end of main() function and exit of the program
...
From syntax point of view, even a single dot or comma or single semicolon
matters and you should take care of such small syntax as well
...
h>
main()
{
printf("Hello, World!")
}
This program will produce following result:
main
...
c:7:1: error: expected ';' before '}' token
}
^
So bottom-line is that if you are not following proper syntax defined by the programming language in your program
then you will get similar type of syntax errors and before trying next compilation you will need to fix them and then
proceed
...
This program will also produce same result Hello,
World!
...
out
...
This program will also produce same resultHello, World!
...
As I explained in previous chapter, Python is an
interpreted language and it does not need intermediate step called compilation
...


TUTORIALS POINT
Simply Easy Learning

Conclusion
Not sure if you understood what I taught you above in this chapter, but if you did not understand then I will suggest
to go through it once again and make sure you understood all the above concepts
...


TUTORIALS POINT
Simply Easy Learning

5

CHAPTER

Programming – Data Types

L

et’s discuss about a very simple but very important concept available in almost all the programming

languages which is called data types
...
It can be numeric, alphanumeric, decimal, etc
...
50 & 20
...
50 + 20
...
Here is following important information, which we can record:
Name:
Class:
Section:
Age:
Sex:

Now, let's put one student record as per the given requirement:
Name: Zara Ali
Class: 6th
Section: J
Age: 13

TUTORIALS POINT
Simply Easy Learning

Sex: F

First example dealt whole numbers and second example added two numbers with decimals where as third example
is dealing with a mix of different data
...




Student class "6th" has been represented by a mix of whole number and a string of two characters
...




Student section has been represented by single character which is 'J'
...




Student sex has been represented by a single character which is 'F'
...

Similar way when we write our computer program to process different types of data, we need to specify its type
clearly otherwise computer does not understand how different operations can be performed on that given data
...
For example C and Java
programming languages use int to specify integer data whereas charspecifies a character data type
...
For now let's check what
are the important data types available in C, Java and Python programming languages and what are the keywords
we will use to specify those data types
...
For now, we are taking few common data types supported by both the programming languages:
Type

Keyword

Value range which can be represented by this data type

Character

char

-128 to 127 or 0 to 255

Number

int

-32,768 to 32,767 or -2,147,483,648 to 2,147,483,647

Small Number

short

-32,768 to 32,767

Long Number

long

-2,147,483,648 to 2,147,483,647

Decimal Number

float

1
...
4E+38 till 6 decimal places

These data types are called primitive data types and you can use these data types to build more complex data
types, which are called user-defined data type, for example a string will be a sequence of characters
...


TUTORIALS POINT
Simply Easy Learning



Numbers



String



List



Tuple



Dictionary

Here, Number specifies all types of numbers including decimal numbers and string represents a sequence of
characters with a length of 1 or more characters
...


TUTORIALS POINT
Simply Easy Learning

6

CHAPTER

Programming - Variables

T

his session will teach you another most important concept of computer programming which is

calledvariables
...

For example, assume you want to store two values 10 and 20 in your program and at later stage you want to use
these two values
...




Store your values in those two variables
...


Creating variables
Creating variables is also called declaring variables in C programming language
...
For example, C programming language
has the following simple way of creating variables:
#include ...
e
...
We created these
variables using int keyword to specify variable data type which means we want to store integer values in these two
variables
...
For example:
/* variable to store long value */
long a;
/* variable to store float value */
float b;
You can create variables of similar type by putting them in a single line but separated by comma as follows:

TUTORIALS POINT
Simply Easy Learning

#include ...
For example, if variable a has been defined inttype, then it can
store only integer
...
e
...
You
can not use a variable name in your program without creating it, though programming language like Python
allows you to use a variable name without creating it
...
For example, if a variable a has been defined to
store an integer value, then you can not define a again to store any other type of value
...
, which do not want you to specify data type at
the time of creating variables
...




You can give any name to a variable like age, sex, salary, year1990 or anything else you like to give, but most
of the programming languages allow to use only limited characters in their variables names
...
z, A
...
9 in your variable names and start their names using alphabets only
instead of digit
...




Every programming language provides more rules related to variables and you will learn them when you will go in
further detail of that programming language
...


Store values in variables
You have seen how we created variables in previous section
...
h>
main()
{
int a;
int b;
a = 10;
b = 20;
}
Above program has two additional statements where we are storing 10 in variable a and 20 is being stored in
variable b
...

Now, we have completed two steps, first we created two variables and then we stored required values in those
variables
...
In other words we can say, when above
program is executed, the memory location named a will hold 10 and memory location b will hold 20
...
We know that above program has two variables a and b and they store values 10 and 20, respectively
...
Following is a C program, which prints the values stored in
variables:
#include ...
This time, we
are using it to print the values of variables
...
We can print both values using a single printf() statement as follows:
#include ...
Similar way, different data types can be printed using different
% and characters
...
This program will create two
variables a and b and very similar to C programming, then we assign 10 and 20 in these variables and
finally print the values of the two variables in two ways:
public class DemoJava

TUTORIALS POINT
Simply Easy Learning

{
public static void main(String []args)
{
int a;
int b;
a = 10;
b = 20;
System
...
println("Value of a = " + a);
System
...
println("Value of b = " + b);
System
...
println("Value of a = " + a + " and value of b = " + b);
}
}

Variables in Python
Following is the equivalent program written in Python
...

Python does not want you to specify data type at the time of variable creation and there is also no need of creating
variable in advance before using it
...
h>
main()
{
int a = 10;
int b = 20;
printf( "Value of a = %d and value of b = %d\n", a, b );
}

TUTORIALS POINT
Simply Easy Learning

7

CHAPTER

Programming - Keywords

S

o far, you have covered two important concepts called variables and their data types
...
You also have seen how we named our
variables to store different values
...

Like int, long, and float, there are many other keywords supported by C programming language which we will use for
different purpose
...

For example, if you will try to use any reserved keyword for the purpose of variable name, then you will get syntax
error, as follows:
#include ...
c: In function 'main':
main
...

But now let's give proper name to our integer variable, then above program should compile and execute
successfully:
#include ...
So just be careful while giving a name to your variable, you should not use any
reserved keyword for that programming language
...
This chapter will explain you what are
the operators and will take you through important arithmetic and relational operators available in C, Java and
Python programming languages
...
We can write a computer program which can do
simple calculation like adding two numbers (2 + 3) and we can also write a program, which can solve a complex
4
3
equation like P(x) = x + 7x - 5x + 9
...
Similar concept exists in Computer Programming
...

These two statements are called arithmetic expressions in a programming language and plus, minusused in these
expressions are called arithmetic operators and values used in these expressions like 2, 3 and x, etc
...
In their simplest form such expressions produce numerical results
...
Following table lists down few of the
important arithmetic operators available in C programming language
...
h>

TUTORIALS POINT
Simply Easy Learning

main()
{
int a, b, c;
a = 10;
b = 20;
c = a + b;
printf( "Value of c = %d\n", c);
c = a - b;
printf( "Value of c = %d\n", c);
c = a * b;
printf( "Value of c = %d\n", c);
c = b / a;
printf( "Value of c = %d\n", c);
c = b % a;
printf( "Value of c = %d\n", c);
}
When above program is executed, it produces the following result:
Value
Value
Value
Value
Value

of
of
of
of
of

c
c
c
c
c

=
=
=
=
=

30
-10
200
2
0

Relational Operators
Consider a situation where we create two variables and assign them some values as follows:
A = 20
B = 10
Here, it is obvious that variable A is greater than B in values
...
If we make use of C programming language, then it will be written as follows:
(A > B)
Here, we used a symbol > and it is called relational operator and in their simplest form they produce boolean results
which means result will be either true or false
...
Following table lists down few of the important relational operators available in C programming
language
...


(A == B)
is not
true
...


(A != B)
is true
...


is not
true
...


(A < B)
is true
...


(A >= B)
is not
true
...


(A <= B)
is true
...
Though
this statement will be discussed later in a separate chapter, but in short we use if statement to check a condition
and if condition is true then body of if statement is executed otherwise body of if statement is skipped
...
h>
main()
{
int a, b;
a = 10;
b = 20;
/* Here we check whether a is equal to 10 or not */
if( a == 10 )
{
/* if a is equal to 10 then this body will be executed */
printf( "a is equal to 10\n");
}
/* Here we check whether b is equal to 10 or not */
if( b == 10 )
{
/* if b is equal to 10 then this body will be executed */
printf( "b is equal to 10\n");
}
/* Here we check if a is less b than or not */
if( a < b )
{
/* if a is less than b then this body will be executed */
printf( "a is less than b\n");
}
/* Here we
if( a != b
{
/* if a
printf(
}

check whether a and b are not equal */
)
is not equal to b then this body will be executed */
"a is not equal to b\n");

}
When above program is executed, it produces the following result:
a is equal to 10
a is less than b
a is not equal to b

TUTORIALS POINT
Simply Easy Learning

Logical Operators
Logical operators are very important in any programming language and they help us in taking decision based on
certain conditions
...

Following table shows all the logical operators supported by C language
...
If both the operands are non-zero, then condition becomes
true
...


||

Called Logical OR Operator
...


(A || B) is
true
...
Use to reverses the logical state of its operand
...


!(A &&
B) is
true
...
h>
main()
{
int a = 1;
int b = 0;
if ( a && b )
{
printf("This will never print because condition is false\n" );
}
if ( a || b )
{
printf("This will be printed print because condition is true\n" );
}
if ( !(a && b) )
{
printf("This will be printed print because condition is true\n" );
}
}
When you compile and execute the above program, it produces the following result:
This will be printed print because condition is true
This will be printed print because condition is true

Operators in Java
Following is the equivalent program written in Java programming language
...
This program will create two
variables a and b and very similar to C programming, then we assign 10 and 20 in these variables and finally we will
use different arithmetic and relation operators:

TUTORIALS POINT
Simply Easy Learning

You can try to execute the following program to see the output, which must be identical to the result generated by
the above example
...
out
...
out
...
out
...
out
...
out
...
out
...
This program will create two variables a and b and same time
assign 10 and 20 in those variables
...
This program will create two variables a and b and very similar to C
programming, then we assign 10 and 20 in these variables and finally we will use different arithmetic and relation
operators
...

a = 10
b = 20
c = a + b
print "Value of c = ", c
c = a - b
print "Value of c = ", c
c = a * b
print "Value of c = ", c

TUTORIALS POINT
Simply Easy Learning

c = a / b
print "Value of c = ", c
c = a % b
print "Value of c = ", c
if( a == 10 ):
print "a is equal to 10"

TUTORIALS POINT
Simply Easy Learning

9

CHAPTER

Programming - Decisions

D

ecision making is critical to computer programming
...
For example, we want to
print a remark about a student based on secured marks and following is the situation:
1
...

3
...

5
...

7
...
Almost all the programming languages
provide conditional i
...
, decision making statements which work based on the following flow diagram:

TUTORIALS POINT
Simply Easy Learning

Let's write a C program with the help of if conditional statements to convert above given situation into
programming code:
#include ...
Here, first if statement checks whether given condition
i
...
, variable x is greater than 95 or not and if it finds condition is true, then the conditional body is entered to
execute given statements
...

Similar way, second if statement works
...
If final result is true then conditional statement will be executed, otherwise no statement will be
executed
...
Different programming languages provide different type of decision making
statements but basic concept will remain same as explained in this tutorial
...
else statement
An if statement can be followed by an optional else statement, which executes when the boolean expression is
false
...
else statement in C programming language is:
if(boolean_expression)
{
/* Statement(s) will execute if the boolean expression is true */
}
else
{
/* Statement(s) will execute if the boolean expression is false */
}
Above syntax can be represented in the form of a flow diagram as shown below:

An if
...
For example, if student secures
more marks than 95, then student is brilliant otherwise no, such situation can be coded as follows:
#include ...
elseif
...
else statement, which is very useful to test various
conditions using single if
...

When using if , else if , else statements, there are few points to keep in mind:



An if can have zero or one else's and it must come after any else if's
...




Once an else if succeeds, none of the remaining else if's or else's will be tested
...
else if
...
elseif
...
h>
main()
{
int x = 45;
if( x > 95)
{
printf( "Student is brilliant\n");
}
else if( x < 30)

TUTORIALS POINT
Simply Easy Learning

{
printf( "Student is poor\n");
}
else if( x < 95 && x > 30 )
{
printf( "Student is average\n");
}
}
When above program is executed, it produces the following result:
Student is average

The switch statement
A switch statement is an alternative of if statements which allows a variable to be tested for equality against a list
of values
...
This
has following syntax:
switch(expression){
case ONE :
statement(s);
break;
case TWO:
statement(s);
break;

...
Wherever, expression value matches with case value, the body of that case will be executed
and finally switch will be terminated using break statement
...
If none of the cases matches, then
default case body is executed
...
Then, it
can be coded as follows:
#include ...
\n");

}
When above program is executed, it produces the following result:
Two

TUTORIALS POINT
Simply Easy Learning

Decisions in Java
Following is the equivalent program written in Java programming language
...
else, if
...
else and switch statements
...

public class DemoJava
{
public static void main(String []args)
{
int x = 45;
if( x > 95)
{
System
...
println(
}
else if( x < 30)
{
System
...
println(
}
else if( x < 95 && x >
{
System
...
println(
}

"Student is brilliant");

"Student is poor");
30 )
"Student is average");

}
}

Decisions in Python
Following
is
the
equivalent
program
written
in
Python
...
else, if
...
else andswitch statements
...

You can try to execute following program to see the output:
x = 45
if x > 95:
print "Student
elif x < 30:
print "Student
elif x < 95 and x
print "Student

is brilliant"
is poor"
> 30:
is average"

print "The end"
When above program is executed, it produces the following result:
Student is average
The end

TUTORIALS POINT
Simply Easy Learning

CHAPTER

10
Programming - Loops

L

et’s consider a situation when you want to write Hello, World! five times
...
h>
main()
{
printf(
printf(
printf(
printf(
printf(

"Hello,
"Hello,
"Hello,
"Hello,
"Hello,

World!\n");
World!\n");
World!\n");
World!\n");
World!\n");

}
When above program is executed, it produces the following result:
Hello,
Hello,
Hello,
Hello,
Hello,

World!
World!
World!
World!
World!

It was simple, but again let's consider another situation when you want to write Hello, World! thousand times, what
you will do in such situation? Are we going to write printf() statement thousand times? No, not at all
...
All high-level programming languages provide various forms of loops, which can be used
to execute one or more statements repeatedly
...
h>
main()
{
int i = 0;
while ( i < 5 )
{
printf( "Hello, World!\n");
i = i + 1;

TUTORIALS POINT
Simply Easy Learning

}
}
When above program is executed, it produces the following result:
Hello,
Hello,
Hello,
Hello,
Hello,

World!
World!
World!
World!
World!

Above program makes use of while loop, which is being used to execute a set of programming statements
enclosed within {
...
e
...
Here, we have the following
two statements in the loop body:




First statement is printf() function, which prints Hello World!
Second statement is i = i + 1, which is used to increase the value of variable i

After executing all the statements given in the loop body, computer goes back to while( i < 5) and given condition, (i
< 5), is checked again, and the loop is executed again if condition is true
...

To conclude, a loop statement allows us to execute a statement or group of statements multiple times and following
is the general form of a loop statement in most of the programming languages:

This tutorial has been designed to present programming's basic concepts to non-programmers, so let's discuss
about two important loops available in C programming language
...


TUTORIALS POINT
Simply Easy Learning

The while Loop
A while loop available in C Programming language has following syntax:
while ( condition )
{
/*
...
*/
}
Above code can be represented in the form of a flow diagram as shown below:

There are following important points to note about a while loop:



A while loop starts with a keyword while followed by a condition enclosed in ( )
...




A while loop body can have one or more lines of source code to be executed repeatedly
...




A while loop keeps executing its body till given condition is true
...




A condition is usually a relational statement, which is evaluated to either true or false values
...


TUTORIALS POINT
Simply Easy Learning

The do
...
C
programming provides another form of loop, which is called do
...
This has following syntax:
do
{
/*
...
while loop body
...
while loop, then Hello, World will produce the same result:
#include ...
The syntax for a break statement in C is as follows:
break;
A break statement can be represented in the form of a flow diagram as shown below:

Following is a variant of the above program, but it will come out after printing Hello World! only three times:
#include ...
Instead of forcing
termination, however, continue forces the next iteration of the loop to take place, skipping any code in between
...
h>
main()
{
int i = 0;
do
{
if( i == 3 )
{
i = i + 1;
continue;
}
printf( "Hello, World!\n");
i = i + 1;
}while ( i < 5 );
}
When above program is executed, it produces the following result:
Hello,
Hello,
Hello,
Hello,

World!
World!
World!
World!

TUTORIALS POINT
Simply Easy Learning

Loops in Java
Following is the equivalent program written in Java programming language
...
while loops
...

public class DemoJava
{
public static void main(String []args)
{
int i = 0;
while ( i < 5 )
{
System
...
println("Hello, World!");
i = i + 1;
}
}
}
The break and continue statements in Java programming work very similar way, what they work in C
programming
...
Python also provides while and do
...
Following
program will be used to print Hello, World! five times as we did in case of C Programming
...

You can try to execute following program to see the output
...

i = 0
while (i < 5):
print "Hello, World!"
i = i + 1
print "Loop ends"
When above program is executed, it produces the following result:
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Loop ends
The break and continue statements in Python programming work very similar way as they work in C programming
...
The programming languages like C, Java and Python categorize these numbers in
several categories based on their nature
...
2E-38 to 3
...

We have seen various mathematical and logical operations on numbers during a discussion on operators
...

First let's see how to print various types of numbers available in C programming language:
#include ...
47;
30949
...
3f\n", f);
%
...
3f to print float and double, which indicates number of digits after
decimal to be printed
...
470
30949
...

For example, if you want to calculate square root of a number for example, 2304, then you have built-in function
available to calculate square root for this number
...
N
...


2

double sin(double);
This function takes an angle (as a double) and returns the sine
...


4

double log(double);
This function takes a number and returns the natural log of that number
...


6

double hypot(double, double);
If you pass this function the length of two sides of a right triangle, it will return you the length of the
hypotenuse
...


8

int abs(int);
This function returns the absolute value of an integer that is passed to it
...


10

double floor(double);
Finds the integer which is less than or equal to the argument passed to it
...
To utilize these functions, you need to
include the math header file ...
h:
#include ...
h>
main()
{
short
int
long
float
double
s
i
l
f
d

=
=
=
=
=

s;
i;
l;
f;
d;

10;
1000;
1000000;
230
...
374;

printf(
printf(
printf(
printf(
printf(

"sin(s): %f\n", sin(s));
"abs(i): %f\n", abs(i));
"floor(f): %f\n", floor(f));
"sqrt(f): %f\n", sqrt(f));
"pow(d, 2): %f\n", pow(d, 2));

}
When above program is executed, it produces the following result:
sin(s): -0
...
544021
floor(f): 230
...
181238
pow(d, 2): 5
...


Numbers in Java
Following is the equivalent program written in Java programming language
...

You can try to execute the following program to see the output, which is identical to the result generated by the
above C example
...
47f;
30949
...
out
...
out
...
out
...
out
...
out
...
470001
30949
...


Numbers in Python
Python is little different from C and Java and categorize numbers in int, long, float and complex
...
0

3
...
20

45
...
9

9
...
3+e18


...


-
...
54e100

3e+26J

0x69

-4721885298529L

70
...
53e-7j

Following is the equivalent program written in Python:
s
i
l
f
d

=
=
=
=
=

10
1000
1000000
230
...
374

print
print
print
print
print

"s:
"i:
"l:
"f:
"d:

",
",
",
",
",

s
i
l
f
d

When above program is executed, it produces the following result:
s:
i:

10
1000

TUTORIALS POINT
Simply Easy Learning

l:
f:
d:

1000000
230
...
374

Python also provides a full range of built-in functions for mathematical calculation and you can use them in very
similar way you have used them in C programming
...
Numbers

are simple 1, 2, 3
...
20, 300
...

It's even further easy to learn about characters in computer programming because you are playing with characters
even before you started playing with numbers
...
A, B, C, D,
...
and special characters like $,
%, +, -
...
, are also treated as characters and to assign them in a character type variable you simply need to put
them inside a single quotes
...
Not only a, b, c,
...
or any
special character like !, @, #, #, $,
...
Bottom-line is that a character
data type can store any of the characters available on your keyboard including special characters like !, @, #, #, $,
%, ^, &, *, (, ), _, +, {, }, etc
...
So following statements are
invalid in C programming:
char ch1 = 'ab';
char ch2 = '10';
Following is a simple example, which shows how to define, assign and print characters in C Programming language:
#include ...
When above program is executed, it produces the following result:
ch1:
ch2:
ch3:
ch4:

a
1
$
+

Escape Sequences:
Many programming languages support a concept called Escape Sequence
...
For example, following
is a valid character and it is called new line character:
char ch = '\n';
Here, character n has been preceded by a backslash (\), so now it has special meaning which is a new line but keep
in mind that backslash (\) has special meaning with few characters only, so following will not have any meaning in C
programming and it will be assumed as an invalid statement:
char ch = '\1';
Following table shows correct escape sequences available in C programming language:
Escape Sequence

Description

\t

Inserts a tab in the text at this point
...


\n

Inserts a newline in the text at this point
...


\f

Inserts a form feed in the text at this point
...


\"

Inserts a double quote character in the text at this point
...


Following is a simple example which shows how the compiler interprets an escape sequence in a print statement:
#include ...
Java programming language handles
character data type in similar way as we have seen in C programming language
...

You can try to execute the following program to see the output, which must be identical to the result generated by
the above C example
...
out
...
out
...
out
...
out
...


TUTORIALS POINT
Simply Easy Learning

Characters in Python
Python does not support any character data type but all the characters are treated as string, which is a sequence of
characters and we will study strings in a separate chapter
...

Following is the equivalent program written in Python:
ch1
ch2
ch3
ch4

=
=
=
=

print
print
print
print

'a';
'1';
'$';
'+';
"ch1:
"ch2:
"ch3:
"ch4:

",
",
",
",

ch1
ch2
ch3
ch4

When above program is executed, it produces the following result:
ch1:
ch2:
ch3:
ch4:

a
1
$
+

Python also supports escape sequence in very similar way you have used them in C programming
...
If we use programming's simple variable

and data type concepts, then we need 5 variables of int data type and program will be something as follows:
#include ...
Now let's assume we have to store 5000 integer
numbers, so what is next? Are we going to use 5000 variables?
To handle such situation, almost all the programming languages provide a concept called the array
...
An array is used to store a
collection of data, but it is often more useful to think of an array as a collection of variables of the same type
...
, and number99, you just declare one
array variable number of integer type and use number1[0], number1[1], and
...
Here, 0, 1, 2,
...

All arrays consist of contiguous memory locations
...


TUTORIALS POINT
Simply Easy Learning

Create Arrays
To create an array variable in C, a programmer specifies the type of the elements and the number of elements to be
stored in that array
...
The arraySize must be an integer constant greater than zero
and type can be any valid C data type
...


Initializing Arrays
You can initialize array in C either one by one or using a single statement as follows:
int number[5] = {10, 20, 30, 40, 50};
The number of values between braces { } cannot be larger than the number of elements that we declare for the
array between square brackets [ ]
...
Therefore, if you write:
int number[] = {10, 20, 30, 40, 50};
You will create exactly the same array as you did in the previous example
...
All arrays have 0 as the index of
their first element which is also called base index and last index of an array will be total size of the array minus 1
...
This is done by placing the index of the element within square
brackets after the name of the array
...
Following is an
example, which will use all the above-mentioned three concepts viz
...
h>
int main ()
{
int number[10]; /* number is an array of 10 integers */
int i = 0;
/* Initialize elements of array n to 0 */
while( i < 10 )
{
/* Set element at location i to i + 100 */
number[ i ] = i + 100;
i = i + 1;
}
/* Output each array element's value */
i = 0;
while( i < 10 )
{
printf("number[%d] = %d\n", i, number[i] );
i = i + 1;
}
return 0;
}
When the above code is compiled and executed, it produces the following result:
number[0]
number[1]
number[2]
number[3]
number[4]
number[5]
number[6]
number[7]
number[8]
number[9]

=
=
=
=
=
=
=
=
=
=

100
101
102
103
104
105
106
107
108
109

Arrays in Java
Following is the equivalent program written in Java programming language
...

You can try to execute the following program to see the output, which must be identical to the result generated by
the above C example
...
out
...

Following is the equivalent program written in Python:
# Following defines an empty list
...
append(i + 100)
i = i + 1
i = 0
while i < 10:
# Accessing elements from the list
print "number[", i, "] = ", number[ i ]
i = i + 1
When above program is executed, it produces the following result:
number[
number[
number[
number[
number[
number[
number[
number[
number[

0
1
2
3
4
5
6
7
8

]
]
]
]
]
]
]
]
]

=
=
=
=
=
=
=
=
=

100
101
102
103
104
105
106
107
108

TUTORIALS POINT
Simply Easy Learning

number[ 9 ] =

109

TUTORIALS POINT
Simply Easy Learning

CHAPTER

14
Programming - Strings

D

uring our discussion about characters in computer programming, we learnt that character data type deals

with a single character and you can assign any character from your keyboard to a character type variable
...
We have seen that C programming does not allow to store more than one character in a character type
variable
...
If
recap then, here is the syntax to store and print 5 numbers in an array of int type:
#include ...
h>
main()
{

TUTORIALS POINT
Simply Easy Learning

char ch[5] = {'H', 'e', 'l', 'l', 'o'};
int i = 0;
while( i < 5 )
{
printf("ch[%d] = %c\n", i, ch[i] );
i = i + 1;
}
}
Here, we used %c to print character value
...
C programming simplified the assignment and
printing of strings
...
h>
main()
{
char ch[5] = "Hello";
int i = 0;
/* Print as a complete string */
printf("String = %s\n", ch);
/* Print character by character */
while( i < 5 )
{
printf("ch[%d] = %c\n", i, ch[i] );
i = i + 1;
}
}
Here, we used %s to print full string value using array name ch, which is actually beginning of the memory address
holding ch variable as shown below:

Though it's not visible from the above examples, but internally C program assigns null character '\0' as the last
character of every string
...


TUTORIALS POINT
Simply Easy Learning

Now if the above code is compiled and executed, it produces the following result:
String = Hell
ch[0] = H
ch[1] = e
ch[2] = l
ch[3] = l
ch[4] = o

Basic String Concepts
Based on the above discussion we can conclude the following important points to remember about strings in C
programming language:



Strings in C are represented as arrays of characters
...




We can constitute a string in C programming by assigning a complete string enclosed in double quote
...




Though it's not visible from the above examples, but internally C program assigns null character'\0' as the last
character of every string
...




Most of the programming languages provide built-in functions to manipulate strings, i
...
, you can concatenate
strings, you can search from a string, you can take sub string from the string
...


Strings in Java
Though you can use character array to store strings but Java is an advanced programming language and its
designers tried to provide additional functionality like Java provides string as a built-in data type like any other data
type
...

Following is the equivalent program written in Java programming language
...
out
...

To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring
...
Functions

provide better modularity for your application and a high degree of code reusing
...
These are called built-in functions provided by the language itself, but we can
write our own functions as well and this tutorial will teach you how to write and use those functions in C
programming language
...
Different programming languages name
them differently like functions, methods, sub-routines, procedures, etc
...

Let's start with a program where we will define two arrays of numbers and then from each array, we will find the
biggest number
...

2
...

4
...

6
...

8
...
LN
Assume L1 is the largest, Set max = L1
Take next number Li from the list and do the following
If max is less than Li
Set max = Li
If Li is last number from the list then
Print value stored in max and come out
Else prepeat same process starting from step 3

Let's translate above program in C programming language:
#include ...
Here
in above example, I took only two sets of numbers set1, and set2 but consider a situation we have 10 or more
similar sets of numbers to find out maximum numbers from each set
...
To handle such
situation, we write our functions where we try to keep source code which will be used again and again in our
programming
...
Here are all the
parts of a function:





Return Type: A function may return a value
...

Some functions perform the desired operations without returning a value
...

Function Name: This is the actual name of the function
...

Parameter List: A parameter is like a placeholder
...
This value is referred to as actual parameter or argument
...
Parameters are optional; that is, a function may contain no
parameters
...


Calling a Function:
While creating a C function, you give a definition of what the function has to do
...

Now, let's write above example with the help of a function:
#include ...
If you understood this concept
then you can proceed for a detailed tutorial to drill it down further
...
Java
programming names them as methods , but rest of the concepts remain more or less same as we discussed in C
programming
...
You can try to execute the following
program to see the output:
public class DemoJava
{
public static void main(String []args)
{
int[] set1 = {10, 20, 30, 40, 50};
int[] set2 = {101, 201, 301, 401, 501};
int max;
/* Process first set of numbers available in set1[] */
max = getMax(set1);
System
...
format("Max in first set = %d\n", max );
/* Now process second set of numbers available in set2[] */
max = getMax(set2);
System
...
format("Max in second set = %d\n", max );
}
public static int getMax( int set[] )
{
int i, max;
max = set[0];
i = 1;
while( i < 5 )
{
if( max < set[i] )
{
max = set[i];
}
i = i + 1;
}
return max;
}
}
When above program is executed, it produces the following result:
Max in first set = 50
Max in second set = 501

Functions in Python
Once again, if you already understood the concept of functions in C and Java programming, then Python is not
much different in defining and calling functions
...

OK, let's start with learning what are files in computer terminology?

Computer Files
A computer file is used to store data in digital format like plain text, image data or any other content
...
htm and it's keeping HTML text, which you are
reading
...
This tutorial is using minilogo image with a file
name cp-mini-logo
...
Computer files can be organized inside different directories
...

Computer files can be considered as the digital counterpart of paper documents, which traditionally are kept in
office
...
c extension, Java programming files have
...
py
...
, but many
times, we need to create files using computer program as well
...

File input means data, which we write into a file and file output means data, which we read from a file
...

For now, it's enough to remember that writing into a file is file input and reading something from the file is file output
...
In either case, we can open a file in the following modes:

TUTORIALS POINT
Simply Easy Learning



Read Only Mode: If you are going just to read an existing file and you do not want to write any further content
in the file, then you will open file in read only mode
...

Write Only Mode: If you are going to write into either an existing file or newly created file but you do not want
to read any written content in the file, then you will open file in write only mode
...

Read & Write Mode: If you are going to read as well as write into the same file, then you will open file in read &
write mode
...

Append Mode: When you open a file for writing, it allows you to start writing your content from the beginning of
the file but writing content from the beginning in a file, which already has some content, will overwrite already
existing content
...
So in such situation, we open file in append mode
...
Almost, all the programming languages
provide syntax to open file in append mode
...


Opening Files
You can use the fopen( ) function to create a new file or to open an existing file, this call will initialize an object of
the type FILE, which contains all the information necessary to control the stream
...
e
...


w

Opens a text file for writing, if it does not exist then a new file is created
...


a

Opens a text file for writing in appending mode, if it does not exist then a new file is created
...


r+

Opens a text file for reading and writing both
...
It first truncate the file to zero length if it exists otherwise
create the file if it does not exist
...
It creates the file if it does not exist
...


Closing a File
To close a file, use the fclose( ) function
...
e
...
This
function actually flushes any data still pending in the buffer to the file, closes the file, and releases any memory used
for the file
...
h
...
Let us see few of them in the next section
...
It returns
the written character written on success, otherwise EOF if there is an error
...
It returns a non-negative value on success,
otherwise EOF is returned in case of any error
...
) function as
well to write a string into a file
...
h>
main()
{
FILE *fp;
fp = fopen("/tmp/test
...
\n");
fputs("This is testing for fputs
...
txt in /tmp directory and writes two lines
using two different functions
...


Reading a File
Following is the simplest function to read a text file character by character:
int fgetc( FILE * fp );
The fgetc() function reads a character from the input file referenced by fp
...
The following functions allow you to read a string from a stream:
char *fgets( char *buf, int n, FILE *fp );
The functions fgets() reads up to n - 1 characters from the input stream referenced by fp
...

If this function encounters a newline character '\n' or the end of the file EOF before they have read the maximum
number of characters, then it returns only the characters read up to that point including new line character
...
) function to read strings from a file but it stops reading after
the first space character encounters
...
h>
main()
{
FILE *fp;
char buff[255];
fp = fopen("/tmp/test
...

3: This is testing for fputs
...
First fscanf() method read just This because after that it
encountered a space, second call is for fgets(), which reads the remaining line till it encountered end of line
...


File I/O in Java
Java programming language provides even richer set of functions to handle File I/O
...

Here, we will see a simple Java program, which is equal to C program explained above
...
Finally, same file is opened and then read that text
from already created file
...
io
...
txt");
// Create a File
file
...
write("This is testing for Java write
...
write("This is second line
...
flush();
writer
...
read(a);
System
...
println( a );
// Close the file
reader
...

This is second line
...
txt", "w")
# Writes the content to the file
fo
...
\n");
fo
...
\n");
# Close the file
fo
...
txt", "r")
# Read file content in a variable
str = fo
...
close()
When the above code is executed, it produces the following result:
This is testing for Python write
...


TUTORIALS POINT
Simply Easy Learning

CHAPTER

17
Programming - Summary

T

hanks for your patience and going through this lengthy tutorial though I tried my best to keep it concise but

because this subject is really very interesting to me so, I could not stop myself to write such a big content
...

There are many other subjects related to computer programming which I did not cover intentionally to avoid your
confusion, but I'm sure those concepts will not give you a pain as long as you make yourself comfortable with the
concepts explained in this tutorial
...


Kindly share with me your experience with this tutorial mentioning tutorial name in the subject line atwebmaster et
tutorialspoint
...
If you have further suggestion to improve this tutorial further, then I will welcome your
suggestions
Title: units in economics
Description: they are in PDF and Microsoft word format,precise and easy to understand.well arranged