Minggu, 18 Oktober 2015

Arrays

In C language, arrays are reffered to as structured data types. An array is defined as finite ordered collection of homogenous data, stored in contiguous memory locations.
Here the words,
  • finite means data range must be defined.
  • ordered means data must be stored in continuous memory addresses.
  • homogenous means data must be of similar data type.
Example where arrays are used,
  • to store list of Employee or Student names,
  • to store marks of a students,
  • or to store list of numbers or characters etc.
Since arrays provide an easy way to represent data, it is classified amongst the data structures in C. Other data structures in c are structure, lists, queues and trees. Array can be used to represent not only simple list of data but also table of data in two or three dimensions.

Declaring an Array

Like any other variable, arrays must be declared before they are used. General form of array declaration is,
data-type variable-name[size];

for example :
int arr[10];
array declaraction in c
Here int is the data type, arr is the name of the array and 10 is the size of array. It means array arr can only contain 10 elements of int type. Index of an array starts from 0 to size-1 i.e first element of arr array will be stored at arr[0] address and last element will occupy arr[9].

Sabtu, 17 Oktober 2015

Recursion in C

Recursion is a programming technique that allows programmers to express in terms of its own operations. In C, this took the form of a function that calls itself. A useful way to think of a recursive function is to imagine them as a process conducted where one clue is to "repeat the process". This makes it sound very similar to a circle because repeating the same code, and in some ways similar to looping. On the other hand, recursion makes it easier to express ideas in which the result of the recursive call is needed to complete the task. Of course, it should be possible to "process" for sometimes can be resolved without the recursive call. One simple example is the idea of ​​building a wall ten feet; if I want to build a ten-foot high wall, then I will first build high walls 9 feet, and then add an extra foot brick. Conceptually, this is like saying "build walls" functions take the height and if the height is greater than one, the first call itself to build a low wall, and then add one foot of brick.

A simple example of recursion would be:
 
void recurse()
{
    recurse(); /* Function calls itself */
}

int main()
{
    recurse(); /* Sets off the recursion */
    return 0;
}

This program will not continue forever, however. The computer keeps function calls on a stack and once too many are called without ending, the program will crash. Why not write a program to see how many times the function is called before the program terminates?

#include <stdio.h>

void recurse ( int count ) /* Each call gets its own copy of count */
{
    printf( "%d\n", count );
    /* It is not necessary to increment count since each function's
       variables are separate (so each count will be initialized one greater)
     */
    recurse ( count + 1 );
}

int main()
{
  recurse ( 1 ); /* First function call, so it starts at one */
  return 0;
}
 
This simple program will show the number of times the recurse function has
been called by initializing each individual function call's count variable one
greater than it was previous by passing in count + 1. Keep in mind that it is
not a function call restarting itself; it is hundreds of function calls that
are each unfinished. 
 
The best way to think of recursion is that each function call is a "process"
being carried out by the computer.  If we think of a program as being carried
out by a group of people who can pass around information about the state of a
task and instructions on performing the task, each recursive function call is
a bit like each person asking the next person to follow the same set of
instructions on some part of the task while the first person waits for the
result.  

 
At some point, we're going to run out of people to carry out the instructions,
just as our previous recursive functions ran out of space on the stack.  There
needs to be a way to avoid this!  To halt a series of recursive calls, a
recursive function will have a condition that controls when the function will
finally stop calling itself. The condition where the function will not call
itself is termed the base case of the function.  Basically, it will usually be an
if-statement that checks some variable for a condition (such as a number being
less than zero, or greater than some other number) and if that condition
is true, it will not allow the function to call itself again. (Or, it
could check if a certain condition is true and only then allow the
function to call itself). 
 
A quick example:
 
void count_to_ten ( int count )
{
    /* we only keep counting if we have a value less than ten
       if ( count < 10 )   
       {
           count_to_ten( count + 1 );
       }
}
int main()
{
  count_to_ten ( 0 ); 
}  

Jumat, 16 Oktober 2015

Function,Argument and Parameter in C

Function is a group of statements which together perform a task. Every C program has at least one function, that is the main (), and all the most trivial programs may specify additional functions.
You can divide the code into a separate function. How do you divide your code between different functions up to you, but logically division usually once every function performs a specific task.
A function declaration tells the compiler about the name of this function, the return type, and parameters. A definition of functions providing the actual body functions.
C standard library provides a variety of built-in functions that you can call the program. For example, the function strcat () to combine two strings, the function memcpy () to copy one memory location to another location and more functions.
Function known by various names such as methods or sub-routine or procedure, etc.

Defining a Function:

The general form of a function definition in C programming language is as follows:
A function definition in C programming language consists of a function header and a function body. Here are all the parts of a function:
  • Return Type: A function may return a value. The return_type is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the return_type is the keyword void.
  • Function Name: This is the actual name of the function. The function name and the parameter list together constitute the function signature.
  • Parameters: A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters.
  • Function Body: The function body contains a collection of statements that define what the function does.
     

Function Arguments:

If a function is to use arguments, it must declare variables that accept the values of the arguments. These variables are called the formal parameters of the function.
The formal parameters behave like other local variables inside the function and are created upon entry into the function and destroyed upon exit.


Senin, 05 Oktober 2015

C Programming loops concept

In C programming language, a loop is a sequence of instruction s that is executed repeatedly until a certain condition is satisfied. Mostly, a specific process is done, such as getting data and changing it, and then some prescribed condition is checked such as whether a counter has reached a prescribed number. Here in this C programming tutorial we use almost all types of loops in our programs.
Below flowchart describes the working of a typical loop in C programming.

WHILE LOOP IN C
while a given condition is true, a statement or group of statements is executed continuously in c language. Initial condition is always checked before executing the loop body as shown below.

FOR LOOP IN C 
A variable which is initialized to a prescribed value is compared with a condition, if true then body of the loop is executed and variable is incremented the loop will continue to go no until it reached the prescribed value. for loop structure is like initialization, condition and finally increment. For loop is one of the best used loop in C programming.

NESTED LOOPS IN C
In nested loops, a loop is used with in another loop which makes a nested structure of loops in C language, C programming language provides this capabilities.

Minggu, 04 Oktober 2015

Decision Making In C programming Language

Decision making structures are one the tools which gives C language its power. In these structure the programmer specifically defines one or more conditions what he wants to be evaluated or tested by the c program, given a statement or statements to be executed if the condition is becomes true, and optionally, other statements to be executed if the condition is false.

Branching:
If refers to execute one of several possible options depending on the outcome of a logic, which is carried at some specific point within a c program.
:Example:
Nested if-else statement
if – else statement with in other if – else statement. Such statements are called nested if statements in c programming language.
if (expression1)
{
Execute if expression1 is true;
}
else if( expression2)
{
Execute if expression1 is false and 2 is true;
}
else if (expression 3)
{
Execute if text expression1 and 2 are false and 3 is true;
}

Else
{
Execute if all of the expressions are false;
}

exemple can be like this:

Sabtu, 03 Oktober 2015

Data Type in C (input and output)

Data type in C

This is basic code in C,with this code you can create any program in C there has input and output


Input : In any programming language input means to feed some data into program. This can be given in the form of file or from command line. C programming language provides a set of built-in functions to read given input and feed it to the program as per requirement.

Output : In any programming language output means to display some data on screen, printer or in any file. C programming language provides a set of built-in functions to output required data.

Here we will discuss only one input function and one putput function just to understand the meaning of input and output. Rest of the functions are given into C - Built-in Functions



Basic data types Of C language:

integer type
This type is used to define integer numbers. It is denoted as "int" in the C programs in this c programming tutorial
{
int number;
number = 5;
}
Floating-point types.
This type is used to define decimal numbers. It will be denoted as "float" in the c language
{
float Miles;
Miles = 5.6;
}
Boolean type
The Boolean type is used to define a variable that consists of only two values true or false
{
bool b = getc(stdin) == 't' ? true : false;
}

double - data type
Double in c language is used to define BIG decimal point numbers. The memory reserved for this datatype is twice as compared to int datatype. Likely to be 8 bytes.
{
double Atoms;
Atoms = 2500000;
}

char - data type
char data type defines characters in a c program.

{
char alphabet;
alphabet = 'x';
}
Enumerated types in C language:
They are also arithmetic types and they are used to define variables that can only be assigned certain discrete integer values throughout the c program.
The type void:
The type specified void returns no value, meaning no value is available. It is used mainly in functions which returning null or no value.


Jumat, 02 Oktober 2015

Tutorial how to make HELLO WORLD in C++ program

Tutorial how to make HELLO WORLD in C++ program

1.open your compailer program,in this case i used DEVC++

2.open your source project















3. write the source code














4.finally,compaile and running that


Kamis, 01 Oktober 2015

How to instal compailer

How to instal compailer

A compiler is a special program that processes statements written in a particular programming language and turns them into machine language or "code" that a computer's processor uses. Typically, a programmer writes language statements in a language such as Pascal or C one line at a time using an editor . The file that is created contains what are called the source statements . The programmer then runs the appropriate language compiler, specifying the name of the file that contains the source statements.

And this is tutorial how to instal a compailer,in this case i use DEVCPP:

1.click your instaler file before


2.chose your language your prefer

3.click 'I Agree' on license agreement
4.chose where do you want to save the file


5.wait your processing will be runing and click 'yes' in this part