Affichage des articles dont le libellé est C Programming. Afficher tous les articles
Affichage des articles dont le libellé est C Programming. Afficher tous les articles

Basic of C


C Language – The C language is one of the powerful programming languages used to write computer programs for variety of applications. It was developed by Dennis Ritchie at Bell Lab during 1970’s. C has flexible features to write programs for numerical, commercial and graphical applications. May operating system programs for the latest computers and compilers are written using C language.
                        This language was developed from B language which was modified from a language called Basic Combined Programming Language (BCPL).

Salient features of C:
C is a general purpose, structured programming language. Among the two types of programming languages discussed earlier, C lies in between these two categories. That’s why it is often called a middle level language. It means that it combines the elements of high level languages with the functionality of assembly language. It provides relatively good programming efficiency (as compared to machine oriented language) and relatively good machine efficiency as compared to high level languages). As a middle level language, C allows the manipulation of bits, bytes and addresses – the basic elements with which the computer executes the inbuilt and memory management functions. C code is very portable, that it allows the same C program to be run on machines with different hardware configurations. The flexibility of C allows it to be used for systems programming as well as for application programming.

C is commonly called a structured language because of structural similarities to ALGOL and Pascal. The distinguishing feature of a structured language is compartmentalization of code and data. Structured language is one that divides the entire program into modules using top-down approach where each module executes one job or task. It is easy for debugging, testing, and maintenance if a language is a structured one. C supports several control structures such as while, do-while and for and various data structures such as strucs, files, arrays etc. as would be seen in the later units. The basic unit of a C program is a function - C’s standalone subroutine. The structural component of C makes the programming and maintenance easier.


Characters used in C –
·         Alphabets
Upper case letters A to Z
Lower case letter a to z

·         Numbers
0 to 9

·         Special Characters

+
Plus
“
Double Quote
-
Minus
&
Ampersand
*
Asterisk
#
Hash
/
Slash
$
Dollar
\
Back slash
^
Caret
%
Percent
< 
Lesser than
|
Vertical bar
> 
Greater than
~
Tilde
=
Equal to
?
Question mark
(
Open Parenthesis
!
Exclamation Mark
)
Close Parenthesis
,
Comma
[
Open bracket
.
Full stop
]
Close Bracket
;
Semicolon
{
Open Set Bracket
:
Colon
}
Close Set bracket
‘
Apostrophe
_
Underscore

Identifier –An identifier is a name having a few letters, numbers and special character _ (Underscore). It is used to identify a variable, function, symbolic constant and so on. An identifier can be written with a maximum 31 characters. It is a good practice to have identifiers with few letters; less than 8 letters is commonly followed with the first letter being an alphabet.
Ex:-
            c3
            sum
            PI
            sigma
            matadd

Rules for Forming Identifiers -
Identifiers are defined according to the following rules:
1.      It consists of letters and digits.
2.      First character must be an alphabet or underscore.
3.      Both upper and lower cases are allowed. Same text of different case is not equivalent, for example: TEXT is not same as text.
4.      Except the special character underscore ( _ ), no other special symbols can be used.

Keywords or Reserved words – C language uses the following keywords which are not available to users to use them as variables/function names. Generally all keywords are in lower case although uppercase of same names can be used as identifiers.
auto
break
case
enum
volatile
while
char
extern
switch
typedef
const
struct
short
union
continue
return
signed
unsigned
register
goto
sizeof
void
for
if
static
float
double
int
default
do
else
long

Tokens – There are six types of tokens are used in C language.

C Tokens
Examples
Keywords
Auto, float, int etc
Constants
-25, 3.24 etc
Identifiers
Sum, PI etc
String literals
“Total Amount is” “Sum =“ etc
Operators
+, -, * etc
Separators
,   :    ;

Watch Video Tutorial Click Below 






Like it ? Share it.

~ mercredi 8 juillet 2015 0 commentaires

Compiler and How to install


A Compiler is used to translate a C program into object program using which an executable program (.EXE) will be generated by linking the input (keyboard) and output(Monitor) devices. The .EXE file will be run to get the result. Different C compilers are used in DOS and UNIX environments. We know that an editor is used to type and save a program in disk. In DOS environment C compiler with the TURBO editor is commonly available. In UNIX operating system a built-in editor Vi is commonly used.

                        All the UNIX systems have a C compiler called cc. It is a command line compiler and is used to generate the executable file.

We will use Code Block for this Tutorial series. This is an alternate option of Turbo C.

How to install Code Block

1. Open your Web Browser and search for Code Block in Google then open official website of Code Block


2. After opening official click on download tab then click on download the binary release


3. Scroll down and click on sourceforge download link (2nd link)


4. Wait for a while your download will be start automatically


5.  As I am using Internet Download Manager so this is a dialogue box of IDM for downloading the file. (if you do not use any download manager then your browser will use the default downloader)


6. Find out your downloaded file and right click on the code block setup file then open it


7. Click Next


8. Click I Agree


9. Click Next


10. Click Install


11. Installation on process


12. If you want to run code block now click on yes or if you do not wish to run now then click no


13. If you choose Yes then Code Block will be open


14. Code Block


15. Click Next


16. Click Finish
(Click image for large view)


Watch Video Tutorial Click Below



Like it ? Share it.

~ mardi 7 juillet 2015 1 commentaires

Introduction to Programming



Computer Programming– A program has a set of instructions written in correct order to get the desired result. The method of writing the instructions to solve the given problem is called programming.

Programming languages can be divided into two categories:

(i)                Low Level Languages or Machine Oriented Languages: The language whose design is governed by the circuitry and the structure of the machine is known as the Machine language. This language is difficult to learn and use. It is specific to a given computer and is different for different computers i.e. these languages are machine-dependent. These languages have been designed to give a better machine efficiency, i.e. faster program execution. Such languages are also known as Low Level Languages. Another type of Low-Level Language is the Assembly Language. We will code the assembly language program in the form of mnemonics. Every machine provides a different set of mnemonics to be used for that machine only depending upon the processor that the machine is using

(ii)             High Level Languages or Problem Oriented Languages: These languages are particularly oriented towards describing the procedures for solving the problem in a concise, precise and unambiguous manner. Every high level language follows a precise set of rules. They are developed to allow application programs to be run on a variety of computers. These languages are machine-independent. Languages falling in this category are FORTRAN, BASIC, PASCAL etc. They are easy to learn and programs may be written in these languages with much less effort. However, the computer cannot understand them and they need to be translated into machine language with the help of other programs known as Compilers or Translators.

Programming techniques: - There are two type of programming techniques commonly used:-
1.      Procedural Programming
2.      Object Oriented Programming (OOP)

Procedural Programming– In Procedural Programming, for a given problem, variables are identified and instructions are written using the variables in the correct sequence to get the required result.
                        The procedural Programming method is commonly used to solve scientific and engineering problem involving variables.

Object Oriented Programming (OOP)– In Object Oriented Programming, Objects which have data related to a person or item are used. The program can be written using many functional blocks. The functional block contains instructions similar to procedural programming.
                        Object Oriented Programming method is commonly used to develop software packages. C++ is one of the commonly used object oriented programming languages.

Algorithm – In order to write computer programs without any logical errors, it is recommended programmers prepare a rough writing showing the steps involved in the program. This is called an algorithm.
                        An algorithm presents step by step instructions required to solve any problem. These steps can be shown diagrammatically using a flowchart.


Flowchart – Flowchart is a symbolic or diagrammatic representation of an algorithm. It uses several geometrical figures to represent the operations, and arrows to show the direction of flow. Following are the commonly used symbols in flowcharts:-

(Click on image for large view)


Question – Answer

Q. 1 Write the algorithm and draw the flowchart to find the sum and product of given two numbers.

Solution:

            In this problem, two numbers, Let A and B, are given (input) and the result, sum (A+B) of two numbers and product (A*B) of two numbers, are to be calculated.

Algorithm:
1.      Read a, b
2.      Sum ← a+b
3.      Product ←a*b
4.      Print sum, product
5.      Stop

Flowchart:

Note – We can use equal to (=) sign instead of arrow (←). E.g. sum = a+b

Video Tutorial Click Below:



Like it ? Share it.

~ dimanche 5 juillet 2015 0 commentaires

C Programming


C programming is a popular computer programming language which is widely used for system and application software. Despite being fairly old programming language, C programming is widely used because of its efficiency and control. This tutorial is intended for beginners who does not have any prior knowledge or have very little knowledge of computer programming.

Theory
Video Tutorials
English
Hindi


Fundamentals of C









4. Conversions and Associativity



Introduction to Code Blocks



Input or Output Functions and Statements




Decision and Loop Control Statement in C




Array and Subscript



Strings



Functions



Structure and Union



Pointers



Files



C Preprocessor and Command Line Arguments




Graphics Using C



Standard Library Functions







Like it ? Share it.

~ mardi 7 avril 2015 0 commentaires