Subscribe:

Ads 468x60px

Jumat, 10 Desember 2010

C LANGUAGE SYNTAX PROGRAM part I

PART I ==> simple calculator

# include <stdio.h>
# include <conio.h>
main ()
{
float x, y, add, less, times, for;
printf ("\ t PROGRAM CALCULATOR \ n");
printf ("Input number # 1:"); scanf ("% f", & x);
printf ("Input number # 2:");
scanf ("% f", & y);

added  = x + y;
less   = x-y;
time   = x * y;
for    = x / y;

printf ("\ n Results% .1 f +% .1 f =% .1 f", x, y, add);
printf ("\ n Results% .1 f -% .1 f =% .1 f", x, y, or less);
printf ("\ n Results% .1 f x% .1 f =% .1 f", x, y, time);
printf ("\ n Results% .1 f:% .1 f  =% .2 f", x, y, for);

printf ("\ n Results% .1 f% c =% .1 f \ n", x, 1, sqrt (x));
getch ();
}

Save with the extension. C


Display program 


CALCULATOR PROGRAM

Input number into-1  : 4
Input numbers into-2 : 5
Results 4.0 + 5.0  = 9.0
Results 4.0 - 5.0  = -1.0
Results 4.0 X 5.0  = 20.0
Results 4.0 : 5.0  = 0.80
Results
4.0 ☺      = 2.0 

Description of program:


The program above will perform simple arithmetic functions  on figures that have been fed. As already described in the previous tutorial, that the function of 'printf ()' which is to display the output to the screen and the function 'scanf ()' for reading the input data. Operators are in use in the above program is the addition operator (+), reduction (-), multiplication (x), division (:) and the square root ( smile ) hehehee,, sorry I have not met the square root ascii code. OK ..., it seems easy enough until here ... to deepen knowledge in C programming language, you can see in my next tutorial,, see you ....!  


Download as PDF

Rabu, 08 Desember 2010

HOW TO INSTALLING GCC COMPILER


         As already described in the previous tutorial, the compiler is the translator source code into machine language to be recognized by the computer.  One of the compiler that can be used is GCC, here I'll explain how to compiler GCC can be used well on your computer.
For windows 7 :
    1. Download file GCC compiler which is known by the name of MinGW.
    2. Then install into your PC .
    3. When the installation is placed on drive C: (not in program files)
ex : C:\MinGW Ex รจ C: \ MinGW
    1. Then right click on my computer ==> properties
    2. Select advanced
    3. In advenced dialog box, click the environment variables
    4. In the system variables, double click the path variables
    5. Type (C: \ MinGW \ bin), do not forget to add a semicolon (;) before the letter C
    6. Restart your PC 

       To use it: 
      1. Open a commend prompt 
      2. open the drive where you put the file C that you created.
      3. Type (gcc *****.c -o *****.exe)  
example : ( gcc calculator.c –o calculator.exe ) 
       4. Your program is ready for use.                     

 Note: (****) extention file name .c
download MinGW whitout  Installer here...

iws_niws_niws_wiws_eiws_siws_siws_c
iw_niw_niw_wiw_eiw_s0iw_s0iw_c

You can use dev c++ to compile

Rabu, 01 Desember 2010

PROGRAMMING C - STANDARD INPUT OUTPUT

In the programming c used the function "scanf ()" to read input in the insert, and fungis "printf ()" to display the results entered. Here is a list of formats for input.

Kamis, 25 November 2010

COMMENT and TYPE VARIABLE DATA

1. Program Comments

To facilitate the reading process flow of a program, a programmer should write the comments in the syntax of the program. The definition of the commentary is part of the program itself (as text) in the program who was not executed during the compilation process. Comments in C made ​​by adding '/ *' and ends with'*/'.


2. Variable

The variable is a recognition in the program that allows you to save the value of a particular data type. The value stored in a variable is dynamic, meaning that value can be changed during program run. To use variables, of course we touched declare them first so the compiler can recognize them. Here are the general form for declaring variables in C language.



type name_variable _data;

For example:

int x; / * declare a variable x with type int * /


float y; / * declare a variable x with float data type * /


As for the terms of the naming of variables, namely:


1. C language is a language that is case-sensitive (use uppercase and lowercase letters in a very different variables),
2. The variable name must not be a number preceded by a character or a number. Example:

int 23 / ​​* incorrect * /

int s32 /*benar*/

int S32 / * true * /



1. The variable name must not contain spaces,
2. The variable name may not use the characters that are symbols (@,#,?, etc.).
3. The variable name must not use keywords or macro that has been defined in the C language

* Variable Scope

In a progarm, variable scope is determined by the spot where he declared. According to the scope, the variable can be divided into two, namely global variables and local variables.


1. Global Variables

Global variables are variables that are declared outside the function, both primary functions and other support functions.

2. Local Variables

Local variables are variables declared inside a function shingga can only be identified and accessed by function alone2.


* Variable Types

By type, variables in C can be divided into four kinds, namely automatic variables, static, external, and registers.


1. Variable Automatic

Automatic variables are variables known only within a block only (in sign {...}), either in block selection, repetition or function.

2. Static Variables

Is a variable that stores suati permanent value in a memory, meaning that the variable will store the last niali given.

3. External Variables

C language syntax allows us to write the program into a separate file with a program aimed to modularization. Therefore if we want to declare a variable that can be recognized and accessed by each of the separate file, then the variable that we have declare as external variables. As for how dalah adding the keyword extern at the time of declaration.

4. Register Variables

Unlike other variables that will be stored in memory, the register variables will be stored in CPU registers so that program execution will be faster.


*Data Type
The simplicity of this data type is, eg 10 is the data type integer, 11:45 is the real number data type and the 'A' type character.

1. Basic Data Type
In the language C are grouped into four categories, namely integer data type (integer), real numbers (floating-point), character or string and the type of logic (boolean).

3.1.1. Integer type

Integer type is a data type that is used to store the values ​​that shaped integers (numbers that do not contain a comma), eg 20, 10 and so forth. But the integer is divided again into 2 ie, positive integers and negative integers. In the C language integer divided in a certain range eg integer (int).

3.1.2. Type of Real Numbers

Is a number that contains the value of fractions (containing a comma), eg 1:20, 2:45 and so on.

3.1.3. Character and String Types

Used to represent data in the form of characters. Data will be considered as a character if enclosed by single quotation marks ("), such as 'A', 'B', 'C' and so forth. Whereas if enclosed by double quotes (""), it will be regarded as a string such as "A", "B", "C language" and so forth.

3.1.4. Logic Type
Is the data type that represents the true value (true) and false (false).

3.1.5. Data Type formation
It is self-defined data types to meet the needs of the program that we will create. As for which are included in the data type is the type of array formation and structure.

3.1.6. Enumersi
Is a data type whose value has been defined with certainty at the time of manufacture of that type. This type is generally used to express something whose value is certain, as the name of the day, month, and so forth. As for making a enumersi in C is to use the enum keyword.

Senin, 15 November 2010

INTRODUCTION TO C LANGUAGE

1. Preliminary

C is a powerful programming language and the flexibility that has been widely used by professional programmers to develop programs that vary widely in various fields. But before you learn more about the C language and its implementation, you should know in advance the components and basic knowledge of computer programming knowledge.

2. What is a Compiler?

Compiler can be interpreted as a translator, means the collection of program code written in a particular programming language will be translated by a compiler into assembly language, which would then be translated back into the object code so that the commands will be controlled by the computer (in this case the machine).
A compiler only recognizes certain languages ​​in accordance with what has been created by the creators of such compiler.

3. Doing Compilation Program code

Computers do not know the meaning of program code written in C language because the computer only understands binary instructions, known as machine language. Thus it is necessary to other programs in order to translate the program code into machine language. Programs such as this is known as a compiler.
Compiler will accept the input code and the program will generate a code object to be stored in a file object. In the Windows operating system, this object will usually file extension .c, whereas in Unix or Linux operating systems in general, object files will be ending .o (by default in Linux would generate a.out file)

Quote of the Day

if we plant the rice then it is definitely going to grow grass
but if we do not expect to plant grass to grow rice

if we do that then the world will follow hereafter
but if we do that the world then the afterlife will not participate

Followers