Cprogramming.......
C...
C...
C Programming
What is a programming language?--Human beings
need language to communicate between them. Similarly to communicate with
computers we need a programming language. All the events in life can be
communicated to computers with the help of programming language. C
is the basic of all programming language. Before the introduction of C
we had only Machine level languages. C is just like any other
communication Language.
If you learn C programming thoroughly you can easily learn other programming languages. To learn C
we just need to know the syntax of C program only. i.e order in which
we have to write the contents.This website is intended to introduce C programming
to beginning programmers. Over several years of studying, I have noted a
large number of students appear to have difficulty in grasping the
fundamentals of C Language. So I am trying to explain them with the help
of simple examples.
This website will help you get a quick start with C programming. This website is a guide for the beginners and also for those who have little knowledge on C Programming fundamentals.
There are different types of
programming languages such as Structure oriented, Object oriented etc. C
is the most commonly used Structure oriented programming language.
Compiler for some languages are developed using C only. With the help of
this tutorial I am trying to explain all the basics of C.In order to
successfully complete this tutorial, you won't need any prior knowledge
of the C programming language. First of all I will start with the most
basic concepts and take you up to the highest level of C programming
including the usually intimidating concepts of structures, union,file,
pointers and dynamic memory allocation,etc.
Once you have mastered C, you will find Object Oriented Language such as c++,java, etc are easy to learn.
So let's
start
our Journey.........
CONTROL STATEMENTS......
if (expression)
statement;
If the expression is evaluated and found to be true, the single statement following the "if" is executed. If false, the following statement is skipped. Here a compound statement composed of several statements bounded by braces can replace the single statement.
Here's an example program using simple if statement:
if else statement:
This feature permits the programmer to write a single comparison, and then execute one of the two statements depending upon whether the test expression is true or false. The general form of the if-else statement is
if(expression)
statement1
else
statement2
Here also expression in parentheses must evaluate to (a boolean) true or false. Typically you're testing something to see if it's true, and then running a code block(one or more statements) if it is true, and another block of code if it isn't. The statement1 or statement2 can be either simple or compound statement.
The following program demonstrates a legal if else statement:
You can set up an if-else statement to test for multiple conditions. The following example uses two conditions so that if the first test fails, we want to perform a second test before deciding what to do:
if (x%2==0)
{
printf(“x is an even number”);
}
else
{
if (x>10)
{
printf(“x is an odd number and greater than 10”);
}
else
{
printf(“x is an odd number and less than 10”);
}
}
This brings up the other if-else construct, the if, else if, else. This construct is useful where two or more alternatives are available for selection.
The syntax is
if(condition)
statement 1;
else if (condition)
statement 2;
.....................
.....................
else if(condition)
statement n-1;
else
statemens n ;
The various conditions are evaluated one by one starting from top to bottom, on reaching a condition evaluating to true the statement group associated with it are executed and skip other statements. If none of expression is evaluate to true, then the statement or group of statement associated with the final else is executed.
The following program demonstrates a legal if-elseif-else statement:
CONTROL STATEMENTS......
if statements
If statement is a conditional branching statement. In conditional branching statement a condition is evaluated, if it is evaluate true a group of statement is executed. The simple format of an if statement is as follows:if (expression)
statement;
If the expression is evaluated and found to be true, the single statement following the "if" is executed. If false, the following statement is skipped. Here a compound statement composed of several statements bounded by braces can replace the single statement.
Here's an example program using simple if statement:
This feature permits the programmer to write a single comparison, and then execute one of the two statements depending upon whether the test expression is true or false. The general form of the if-else statement is
if(expression)
statement1
else
statement2
Here also expression in parentheses must evaluate to (a boolean) true or false. Typically you're testing something to see if it's true, and then running a code block(one or more statements) if it is true, and another block of code if it isn't. The statement1 or statement2 can be either simple or compound statement.
The following program demonstrates a legal if else statement:
You can set up an if-else statement to test for multiple conditions. The following example uses two conditions so that if the first test fails, we want to perform a second test before deciding what to do:
if (x%2==0)
{
printf(“x is an even number”);
}
else
{
if (x>10)
{
printf(“x is an odd number and greater than 10”);
}
else
{
printf(“x is an odd number and less than 10”);
}
}
This brings up the other if-else construct, the if, else if, else. This construct is useful where two or more alternatives are available for selection.
The syntax is
if(condition)
statement 1;
else if (condition)
statement 2;
.....................
.....................
else if(condition)
statement n-1;
else
statemens n ;
The various conditions are evaluated one by one starting from top to bottom, on reaching a condition evaluating to true the statement group associated with it are executed and skip other statements. If none of expression is evaluate to true, then the statement or group of statement associated with the final else is executed.
The following program demonstrates a legal if-elseif-else statement:

No comments:
Post a Comment