Opacity: zIndex: Get 100000 0FP0EXP Token to input your own list (json format) or insert json link:

Get 80000 0FP0EXP Token to input your own list (json format) or insert json link:

My Playlist:

JSON Ready: Not Ready

Ready State:

Network State:

Name:

Album:

Reference:

Background Color

General HTML background color:

Header background color:

Menu background color:

Content background color:

Widget background color:

Footer background color:

Font Size

Get 150000 0FP0EXP Token to unlock this feature.

Heading 1 font size:

Heading 2 font size:

Heading 3 font size:

Heading 4 font size:

Heading 5 font size:

Heading 6 font size:

Header font size:

Header Widget font size:

Menu font size:

Widget font size:

Footer font size:

Content font size:

Font Color

Get 200000 0FP0EXP Token to unlock this feature.

Heading 1 font color:

Heading 2 font color:

Heading 3 font color:

Heading 4 font color:

Heading 5 font color:

Heading 6 font color:

Header font color:

Header Widget font color:

Menu font color:

Widget font color:

Footer font color:

Content font color:

Font Shadow

Get 250000 0FP0EXP Token to unlock this feature.

Heading 1 font shadow:

Heading 2 font shadow:

Heading 3 font shadow:

Heading 4 font shadow:

Heading 5 font shadow:

Heading 6 font shadow:

Header font shadow:

Header Widget font shadow:

Menu font shadow:

Widget font shadow:

Footer font shadow:

Content font shadow:

Other Styles Coming Soon



Source Code

Click the above image for basic sourced and click following button for processing token source code.

Ethereum Virtual Machine

Ethereum and EVM (ETC, BSC, AVAX-C-Chain, Polygon, etc).

Telegram Open Network

Telegram Open Network (TON) decentralized application.

Solana

Solana decentralized application.

Tron

Tron decentralized application.

Near

Near decentralized application.

Wax

Wax decentralized application.

Myalgo

Myalgo wallet for Algorand decentralized application.

Sync2

Sync2 wallet for Vechain decentralized application.

Scatter

Scatter wallet for EOS decentralized application.

Ontology

Ontology decentralized application.

Rabbet

Rabbet wallet for Stellar Lumen decentralized application.

Freighter

Freighter wallet for Stellar Lumen decentralized application.

Hivesigner

Hive Signer for Hive decentralized application.

Hivekeychain

Hive Key Chain for Hive decentralized application.

Zilpay

Zilpay wallet for Zilliqa decentralized application.

Neoline N2

Neoline wallet for Neo N2 decentralized application.

Neoline N3

Neoline wallet for Neo N3 decentralized application.

Keplr

Keplr wallet for Cosmos and other decentralized application.

Keeper

Keeper wallet for Waves decentralized application.

IWallet

IWallet for IOST decentralized application.

Starting Computer Programming

Get 60 0FP0EXP Token to remove widget entirely!

source code



source code
old source code

get any 0FP0EXP Token to automatically turn off or 10 0FP0EXP Token to remove this JavaScript Mining.

Get 50000 0FP0EXP Token to remove my NFTS advertisements!

Get 40000 0FP0EXP Token to remove this donation notification!

get 30000 0FP0EXP Token to remove this paypal donation.

View My Stats

get 20000 0FP0EXP Token to remove my personal ADS.

word number: 8934

Time: 2024-04-14 11:25:24 +0000

This section would like to introduce computer programming to starters, and for those who would like to dive into the world of programming. No advance topic will be covered here, instead focuses on wide of simple and easy programmings. We understand that you might not master the basics of programming after reading all the materials, but we expect you to have ideas of what materials you have read when you want to write a program. The author for example knows that he/she needs to use "if else" and "for" in his/her simple login program, but still searches on the Internet for the correct syntax in using those functions. Each programming language like Pascal, C, C++, Python, and Ruby had their own form of syntax but the pattern is similar, more ever the idea is still the same.

Course Outline

Course Overview and Introduction

This section would like to introduce computer programming to starters, and for those who would like to dive into the world of programming. No advance topic will be covered here, instead focuses on wide of simple and easy programmings. If you ever saw a program, or someone programming and it is hard, it's because you have never started in programming. It happens to me too, when someone just suddenly shows his program which hurts my eyes. I started learning programming which only contains 5 lines, then little by little increase the amount that I have wrote. The program that used to give me headache on Figure 1, now it's simple program that I could write.

<html>
<head>
<title>Practice PHP</title>
</head>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
	Username: <input type="text" name="user"><br>
	Password: <input type="text" name="pass"><br>
	<input type="submit">
</form>

<?php 
$username = array("Fajar","John","emanresu");
$password = array("Purnama","Doe","drowssap");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user = $_POST['user'];
$pass = $_POST['pass'];

//var_dump($username[0] == $user and $password[1] == $pass);

for ($c = 0; $c <= count($username)-1; $c++) {

if ($user == $username[$c] and $pass == $password[$c]) {
echo "Welcome!";
break;
} elseif ($c < count($username)-1) {
continue;
} else {
echo "Wrong username or password";
}
}
}

?>

</body>
</html>

Figure 0.1 My practice program in PHP

Learning Objective

This topic would like to cover only the simple part of the technical in programming. We can simply express in Figure 2.

  • It is hoped that you are able to write a simple program and it works.
  • No need to do analysis of the algorithms (efficiency, structures, etc).
  • You are only expected to solve mini problems by making a short script.
  • Ultimately at the end of this course you will be familiar with programming and easily adapt with different programming languages.
C C++ Python Javascript Java Ruby Pascal PHP ...

Figure 0.2 I speak many programming language

Assessment and Measurement

It's up to you of how to do this course but it is recommended to do the following:

  1. Read the contents.
  2. Do the quizzes to enrich your understanding of the content.
  3. Submit assignments whether they are essays or scripts.
  4. Try your programs in virtual programming lab (VPL).
  5. We never meant to place difficult materials so aim for perfect scores before proceeding to the next material since attempting a grade is unlimited.

Once again the top instructions are just our recommendation, do the course as you wish.

  • If your overall score is below 50% you should complete more materials or aim for higher grade.
  • If it's above you are ready to dive into computer programming world.
  • If you got 100% then you should have no problem in adapting or learning new programming languages.

1. About Computer Programming

1.1 Definition

A program is a set of instructions to do certain tasks. On daily life for example a program to turn on a computer:

  1. Plug the cable power.
  2. Turn on the computer.
  3. Turn on the display.
  4. Choose you operating system.
  5. Login.

There are variety of ways to do stuffs, and it's same with a program. That's why there tends to be many programs out there but do similar tasks. Usually programs tends to be unique for each people writing them, since they have their own ways. For example eating at a food court, you can:

  1. Pick a food.
  2. Eat food.
  3. Pay for the food.

Or in KFC or McDonalds:

  1. Pick a food.
  2. Pay for the food.
  3. Eat the food.

So a computer program is defined as a set of instructions that does specific things when executed by a computer. For example command 'printf("Hello World!!")' in C language will output a text display "Hello World!!"

1.2 Application

With computers today lots tasks are being helped by computers. They have done lots of things on our behalf for example on Figure 1.2.1 a calculator program that does calculation for us in a very short time. Figure 1.2.2 is an excel to perform tabulations where we can arrange our data or informations in form of tables. It can even perform calculations and other processes. Last example on Figure 1.2.3 is a web browser which is an application we used to surf the Internet for informations.

Windows Calculator Application

Figure 1.2.1 Calculator Application

Libre Office Calc

Figure 1.2.2 Excel application example

Ice Weasel Browser

Figure 1.2.3 Web Browser

Below is a list of todays popular programming language. I started with Pascal and C.

  • C
  • C++
  • C#
  • Visual Basic
  • Python
  • R
  • Ruby
  • Perl
  • PHP
  • Java
  • Javascript
  • HTML
  • CSS
  • Ladder Logic
  • Verilog HDL
  • Assembly

2. Start Writing

2.1 Note

There are many tutorials already available online if you want to start learning a programming language, but here we will try to give you a point of where to start, provide a comfortable track until you become familiar with beginner programming. I started with Pascal then C, so this will be first example for every content. Examples are written in various programming language (in the future we would like to make it available in all programming language). If you want to start quickly I suggest viewing the content that had online compiler available (NOTE: Online compiler coming soon!!). (Python, PHP, Ruby, C++ coming soon)

Following suggest setting up environments if you want to do programming at you own computer but you may skip to next section if don't want the hassle and later on you may come back here. The programmings that will be cover are freeware or opensource so programming like Visual Basic or Matlab will not be covered here. What you need for this course are:

  1. Operating System (OS): we suggest using Linux because most of the compiler are installed by default, but you may use other like MAC or Windows.
  2. Text editor: anything is ok even the simplest as notepad and wordpad, all that is needed is being able to write the script and save it. Some good example editors with color are VIM, GVIM, Notepad ++, or you may have an editor of certain programming language like Turbo Pascal and Codeblocks.
  3. Compiler: this is the last thing you need, most Linux distribution already equipped with a compiler. If you don't know or don't have the compiler just search on the Internet for Pascal compiler for example. For Windows may asked you to download Turbo Pascal, for Linux mainly Ubuntu or Debian distribution may ask you to install by type "apt-get install fp-compiler". If you want C compiler search on the Internet for C compiler.

2.2 First Script in Pascal

Here's a link to one of online pascal compiler provided by http://www.tutorialspoint.com/compile_pascal_online.php. You can search the Internet for online compilers. The code for now is not colored, we suggest copy and pasting the code into an online compiler, or your editor if supports color like GVIM and Notepad ++. The "Hello World!" script is very famous in programming world to be as the first program to write. The goal of the program is to produce an output "Hello World!".

Program HelloWorld;
begin
	writeln('Hello, world!');
end.

If you use the online compiler from tutorialspoint, overwrite the script, compile and execute. If you're using Linux save the file into "hello.pas" for example and write "fpc hello.pas". It will produce an executable file "hello" you type "./hello" to run the file.

The next lesson is using variables. We can define a variable as a boolean, number, string, and many other variables. It's recommended to copy, paste, run the script, and see its output first. That way is easier than thoroughly identifying the code first. The program example below is defining "firstname" and "lastname" as a string with the value of "firstname" is "Fajar" and "lastname" is Purnama. Then a variable from "a" to "g" is defined as integer with "a" and "b" initialized. Then we perform simple math operation.

program variables;
 
var
	firstname, lastname: string;
	a,b,c,d,e,f,g : integer;
 
begin
	firstname := 'Fajar';
	lastname := 'Purnama';
 
	write('Hi! My name is ', firstname, lastname); writeln('I would like to perform simple math operation');
 
	a := 9;
	b := 4;
	c := a+b;
	d := a-b;
	e := a*b;
	f := a div b;
	g := a mod b;
 
	writeln(a,' + ',b,' = ',c);
	writeln(b,' - ',a,' = ',d);
	writeln(a,' * ',b,' = ',e);
	writeln(b,' div ',a,' = ',f);
	writeln(b,' mod ',a,' = ',g);
end.

The last of this section is using user input. If the previous script we manually define "firstname", "lastname", "a", and "b", next we let the user define them after the program is run. Simply use the syntax "read" or "readln".

program variables;
 
var
	firstname, lastname: string;
	a,b,c,d,e : integer;
	f : real;
 
begin
	write('What is your firstname? '); readln(firstname);
	write('What is your lastname? '); readln(lastname);
 
	write('Hi! My name is ', firstname, lastname); writeln('. I would like to perform simple math operation');
 
	write('Input first number: '); readln(a);
	write('Input second number: '); readln(b);
 
	c := a+b;
	d := a-b;
	e := a*b;
	f := a / b;
 
	writeln(a,' + ',b,' = ',c);
	writeln(a,' - ',b,' = ',d);
	writeln(a,' * ',b,' = ',e);
	writeln(a,' / ',b,' = ',f);
end.

2.3 First Script in C

Here's a link to one of online C compiler provided by http://www.tutorialspoint.com/compile_c_online.php. You can search the Internet for online compilers. The code for now is not colored, we suggest copy and pasting the code into an online compiler, or your editor if supports color like GVIM and Notepad ++. The "Hello World!" script is very famous in programming world to be as the first program to write. The goal of the program is to produce an output "Hello World!".

#include<stdio.h>

int main() {
	printf("Hello, World!");
	return 0;
	}
	

If you use the online compiler from tutorialspoint, overwrite the script, compile and execute. If you're using Linux save the file into "hello.c" for example and write "gcc hello.c -o hello". It will produce an executable file "hello", then type "./hello" to run the file.

The next lesson is using variables. We can define a variable as a boolean, number, string, and many other variables. It's recommended to copy, paste, run the script, and see its output first. That way is easier than thoroughly identifying the code first. The program example below is defining "firstname" and "lastname" as a string with the value of "firstname" is "Fajar" and "lastname" is Purnama. Then a variable from "a" to "g" is defined as integer with "a" and "b" initialized. Then we perform simple math operation.

#include <stdio.h>

int main() {

	char * firstname = "Fajar";
	char * lastname = "Purnama";
	
	printf("Hi!, My name is %s %s.\n", firstname, lastname);
	printf("I would like to do simple math calculation:\n");
	
	int a,b,c,d,e,f,g;
	
	a = 6;
	b = 4;
	c = a + b;
	d = a - b;
	e = a * b;
	f = a / b;
	g = a % b;
	
	printf("%d + %d = %d\n", a, b, c);
	printf("%d - %d = %d\n", a, b, d);
	printf("%d * %d = %d\n", a, b, e);
	printf("%d / %d = %d\n", a, b, f);
	printf("%d mod %d = %d\n", a, b, g);
	
	return 0;
	}
	

The last of this section is using user input. If the previous script we manually define "firstname", "lastname", "a", and "b", next we let the user define them after the program is run. Simply use the syntax "scanf". For the numbers we have to change for "a" to "&a" and so. That's covered in advance topic for now.

#include <stdio.h>

int main () {

	char firstname[20], lastname[20];
	
	printf("What is your first name? "); scanf("%s", firstname);
	printf("What is your last name? "); scanf("%s", lastname);
	
	printf("Hi!, My name is %s %s.\n", firstname, lastname);
	printf("I would like to do simple math calculation:\n");
	
	float a,b,c,d,e,f;
	
	printf("Input first number: "); scanf("%f", &a);
	printf("Input second number: "); scanf("%f", &b);
	
	c = a + b;
	d = a - b;
	e = a * b;
	f = a / b;
	
	printf("%f + %f = %f\n", a, b, c);
	printf("%f - %f = %f\n", a, b, d);
	printf("%f * %f = %f\n", a, b, e);
	printf("%f / %f = %f\n", a, b, f);
	
	return 0;
	}
	

3. Conditional and Functions

3.1 In Pascal

The following is the simplest conditional program. If the input is "John" it will output "Hello John", if not it will output "Wrong Username". We personally think that no need for more explanation, just try the programs. This course is designed simple, explanations are for more advance materials. In Pascal ":=" gives a value to a variable while "=" compares whether "a" is equal to "b". It will return TRUE if correct and FALSE if incorrect.

program simple_login_1;
 
var
	username: string;
 
begin
	write('username: '); readln(username);
 
	if username = 'John' then
	writeln('Hello ', username)
	else
	writeln('Wrong username');
 
	writeln('Program terminate');
end.

Next program if we want more conditions, say that Mary is included as a username:

program simple_login_2;
 
var
	username: string;
 
begin
	write('username: '); readln(username);
 
	if username = 'John' then
	writeln('Hello ', username)
	else if username = 'Mary' then
	writeln('Hello ', username)
	else
	writeln('Wrong username');
 
	writeln('Program terminate');
end.

We can also use "or" for the above program:

program simple_login_2;
 
var
	username, password: string;
 
begin
	write('username: '); readln(username);
 
	if (username = 'John') or (username = 'Mary') then
	writeln('Hello ', username)
	else
	writeln('Wrong username');
 
	writeln('Program terminate');
end.

If we want to include password as well:

program simple_login_4;
 
var
	username, password: string;
 
begin
	write('username: '); readln(username);
	write('password: '); readln(password);
 
	if (username = 'John') and (password = 'Doe') then
	writeln('Hello ', username,' ', password)
	else if (username = 'Mary') and (password = 'Jane') then
	writeln('Hello ', username,' ', password)
	else if (username = 'Fajar') and (password = 'Purnama') then
	writeln('Hello ', username,' ', password)
	else
	writeln('Wrong username or password!');
 
	writeln('Program terminate!');
end.

Say this program is used on many pages or included in other programs. Should we paste the whole code? we can, but we prefer to refer this program as a procedure. There's another famous term called function, similar with only difference it returns a value.

program simple_login_5;
 
var
	username, password: string;
 
procedure simple_login(username:string; password:string);
	begin
	if (username = 'John') and (password = 'Doe') then
	writeln('Hello ', username,' ', password)
	else if (username = 'Mary') and (password = 'Jane') then
	writeln('Hello ', username,' ', password)
	else if (username = 'Fajar') and (password = 'Purnama') then
	writeln('Hello ', username,' ', password)
	else
	writeln('Wrong username or password!');
 
	writeln('Program terminate!');
	end;
 
begin
	write('username: '); readln(username);
	write('password: '); readln(password);
	simple_login(username, password);
end.

3.2 In C

Doing the simple login on C is not as simple as Pascal because of the string factor, but first we want to show that the concept of if else remains the same. The program states if the user input "1" it will say "the value is 1", if not it will say "the value is not 1". At the end of the program we use the function strncmp to compare strings since the usual method doesn't work. If the compare string is the same "string1 == test" then it will output 0. The final input in strncmp "20" is the max number of character, you may change it as you want.

#include <stdio.h>

int main() {
	int a,b;
	printf("input a value: "); scanf("%d", &a);
	
	if (a == 1) {
	printf("a is equal 1\n");
	} else {
	printf("a is not equal to 1\n");
	}
	
	char string1[] = "test";
	
	b = strncmp(string1, "test", 20);
	printf("b is %d\n", b);
	printf("is b == 0? %d(yes)", b == 0);
	
	return 0;
	}
	

The following is the simplest conditional program. If the input is "John" it will output "Hello John", if not it will output "Wrong Username". We personally think that no need for more explanation, just try the programs. This course is designed simple, explanations are for more advance materials. In C "=" gives a value to a variable while "==" compares whether "a" is equal to "b". It will return "1" (TRUE) if correct and "0" (FALSE) if incorrect. C seems intimidating at first, but in our experience, if we learn C, we can easily adapt to different programming languages.

#include <stdio.h>

int main() {

	char username[20];
	printf("Username: "); scanf("%s", username);
	
	if (strncmp(username, "John", 20) == 0) {
		printf("Hello %s.\n", username);
	} else {
		printf("Wrong username!\n");
	}
	
	return 0;
	}
	

Next program if we want more conditions, say that Mary is included as a username:

#include <stdio.h>

int main() {

	char username[20];
	printf("Username: "); scanf("%s", username);
	
	if (strncmp(username, "John", 20) == 0) {
		printf("Hello %s.\n", username);
	} else if (strncmp(username, "Mary", 20) == 0) {
		printf("Hello %s.\n", username);
	} else {
		printf("Wrong username!\n");
	}
	
	return 0;
	}
	

We can also use "or"/"||" for the above program:

#include <stdio.h>

int main() {

	char username[20];
	printf("Username: "); scanf("%s", username);
	
	if ((strncmp(username, "John", 20) ) == 0 || (strncmp(username, "Mary", 20)) == 0) {
		printf("Hello %s.\n", username);
	} else {
		printf("Wrong username!\n");
	}
	
	return 0;
	}
	

If we want to include password as well:

#include <stdio.h>

int main() {

	char username[20], password[20];
	
	printf("Username: "); scanf("%s", username);
	printf("Password: "); scanf("%s", password);
	
	if ((strncmp(username, "John", 20) == 0) && (strncmp(password, "Doe", 20)) == 0) {
		printf("Hello %s %s.\n", username, password);
	} else if ((strncmp(username, "Mary", 20) == 0) && (strncmp(password, "Jane", 20) == 0)) {
		printf("Hello %s %s.\n", username, password);
	} else if ((strncmp(username, "Fajar", 20) == 0) && (strncmp(password, "Purnama", 20)) == 0) {
		printf("Hello %s %s.\n", username, password);
	} else {
		printf("Wrong username or password!\n");
	}
	
	return 0;
	}
	

Say this program is used on many pages or included in other programs. Should we paste the whole code? we can, but we prefer to refer this program as a void. There's another famous term called function, similar with only difference it returns a value.

#include <stdio.h>

void login(char username[20], char password[20]) {

	if ((strncmp(username, "John", 20) == 0) && (strncmp(password, "Doe", 20)) == 0) {
		printf("Hello %s %s.\n", username, password);
	} else if ((strncmp(username, "Mary", 20) == 0) && (strncmp(password, "Jane", 20) == 0)) {
		printf("Hello %s %s.\n", username, password);
	} else if ((strncmp(username, "Fajar", 20) == 0) && (strncmp(password, "Purnama", 20)) == 0) {
		printf("Hello %s %s.\n", username, password);
	} else {
		printf("Wrong username or password!\n");
	}
	}
	
	int main() {
	char username[20], password[20];
	
	printf("Username: "); scanf("%s", username);
	printf("Password: "); scanf("%s", password);
	login(username, password);
	return 0;
	}
	

4. Arrays and Loops

4.1 In Pascal

This is not a formal definition but we see array as place to store many values. If you assign a variable as an array it may store many numbers, names, values, etc. For example we store the username and password into the array first hand:

program array1;
 
var
	username : array[0..5] of string = ('John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin');
	password : array[0..5] of string = ('Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda');
 
begin
	writeln(username[0]);
	writeln(username[1]);
	writeln(username[3]);
	writeln();
	writeln(password[0]);
	writeln(password[1]);
	writeln(password[3]);
 
end.

Or you may fill them afterward:

program array2;
 
var
	username : array[0..5] of string;
	password : array[0..5] of string;
begin
	username[0] := 'Fajar'; password[0] := 'Purnama';
	writeln(username[0]); writeln(password[0]);
end.

If we have many username and password, and we want to write a login script as in section 3 it will be very difficult. Instead why not the machine do it program? In other words we write a program telling the machine to automatically write the script. Our method here is using the loop method as following.

program for_loop;
 
var
	username : array[0..5] of string = ('John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin');
	password : array[0..5] of string = ('Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda');
	i: integer;
 
begin
	for i := 0 to 5 do
	begin
	writeln(i);
	end;
 
	writeln;
 
	for i := 0 to 5 do
	begin
	writeln(username[i], password[i]);
	end;
end.

The program above uses for loop up to 6x (0-5), the first for loop shows that the value if "i" changes in order from 0 to 5 every iteration, and the next for loop shows we can call the username and password using shorter script. Next let's implement the section 3 login script (again copy, paste, and try the program first for easier approach).

program many_login;
 
var
	username : array[0..5] of string = ('John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin');
	password : array[0..5] of string = ('Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda');
	i: integer;
	username_input, password_input: string;
 
begin
	write('Username: '); readln(username_input);
	write('Password: '); readln(password_input);
 
	for i := 0 to 5 do
	begin
 
	if (username_input = username[i]) and (password_input = password[i]) then
	begin
	writeln('Hello ', username_input, ' ', password_input, '!');
	break;
	end
	else if i = 5 then
	writeln('Wrong username or password!');
 
	end;
 
end.

The code above uses "begin" and "end" if we want to put more statement inside the if else. The "break" function forcefully ends the for loop if the correct username and password has been found. On the other hand if the for loop already on it's last iteration "5" and no username and password had been found, it will write "Wrong username or password". Other than For there's also While, maybe more at other programming language. "For" specifies the number of iterations, while "while" sets a goal which the process will not stop until it reaches its goal.

program while_test;
 
var
	a,i: integer;
 
begin
	a := 1;
	write('How much do you want to count? Insert a number: '); readln(i);
	while a <= i do
	begin
	writeln(a);
	a := a + 1;
	end;
 
end.

4.2 In C

This is not a formal definition but we see array as place to store many values. If you assign a variable as an array it may store many numbers, names, values, etc. For example we store the username and password into the array first hand:

#include <stdio.h>

int main() {
	const char * username[] = {"John", "Mary"};
	printf("This is string array: %s %s\n", username[0], username[1]);
	
	const char * password[] = {"Doe", "Jane"};
	printf("This is string array: %s %s\n", password[0], password[1]);
	
	int number[] = {10, 7, 3};
	printf("This is integer array: %d %d %d\n", number[0], number[1], number[2]);
	
	return 0;
	}
	

Or you may fill them afterward:

#include <stdio.h>

int main() {
	const char * username[6];
	username[0] = "John";
	username[1] = "Mary";
	printf("This is string array: %s %s\n", username[0], username[1]);
	
	const char * password[6];
	password[0] = "Doe";
	password[1] = "Jane";
	printf("This is string array: %s %s\n", password[0], password[1]);
	
	int number[3];
	number[0] = 10;
	number[1] = 7;
	number[2] = 4;
	printf("This is integer array: %d %d %d\n", number[0], number[1], number[2]);
	
	return 0;
	}
	

If we have many username and password, and we want to write a login script as in section 3 it will be very difficult. Instead why not the machine do it program? In other words we write a program telling the machine to automatically write the script. Our method here is using the loop method as following.

#include <stdio.h>

int main() {
	const char * username[] = {"John", "Mary", "Fajar", "emanresu", "root", "admin"};
	
	const char * password[] = {"Doe", "Jane", "Purnama", "drowssap", "toor", "nimda"};
	
	int i;
	
	for(i = 0; i <= 5; i++){
		printf("%d\n", i);
	}
	
	for(i = 0; i <= 5; i++){
		printf("This is string array: %s %s\n", username[i], password[i]);
	}
	
	return 0;
	}
	

The program above uses for loop up to 6x (0-5), the first for loop shows that the value if "i" changes in order from 0 to 5 every iteration, and the next for loop shows we can call the username and password using shorter script. Next let's implement the section 3 login script (again copy, paste, and try the program first for easier approach).

#include <stdio.h>

int main() {
	const char * username[] = {"John", "Mary", "Fajar", "emanresu", "root", "admin"};
	
	const char * password[] = {"Doe", "Jane", "Purnama", "drowssap", "toor", "nimda"};
	
	char username_input[20], password_input[20];
	
	printf("Username: "); scanf("%s", username_input);
	printf("Password: "); scanf("%s", password_input);
	
	int i;
	
	for(i = 0; i <= 5; i++){
		if((strncmp(username_input, username[i], 20) == 0) && (strncmp(password_input, password[i], 20) == 0)){
		printf("Hello %s %s\n", username_input, password_input);
		break;
		} else if(i == 5) {
		printf("Wrong username or password\n");
		}
	}
	
	return 0;
	}
	

The "break" function forcefully ends the for loop if the correct username and password has been found. On the other hand if the for loop already on it's last iteration "5" and no username and password had been found, it will write "Wrong username or password". Other than For there's also While, maybe more at other programming language. "For" specifies the number of iterations, while "while" sets a goal which the process will not stop until it reaches its goal.

#include <stdio.h>

int main() {
	int i,a;
	a = 1;
	
	printf("How much do you want to count? Insert a number: "); scanf("%d", &i);
	
	while(a<=i){
		printf("%d\n", a);
		a++;
	}
	
	return 0;
	}
	

What's Next?

Here's a list of programming tutorial website:

Paste your code online:

Examples Online: