Labels

Showing posts with label C Tutorial. Show all posts
Showing posts with label C Tutorial. Show all posts

Thursday, July 05, 2012

The else if statement

Previously we have learnt about nested if else statement, the else if statement works some what like the nested if else statement. But it avoids the complication of the nested if else statement. In case of nested conditional operator, the programmer may indulge in the complication of the program. But a good programmer should always look forward to write a program a very easy and short way as possible. Thus else if statement is one such way to make a program simpler and easier for a developer to develop a program.
Let us understand, the utility of else if statement with an example.

Wednesday, January 25, 2012

Logical Operators

In C language, there are 3 types of logical operators which are used.

  1. && – Used for AND operation.
  2. || – Used for OR operation.
  3. ! – Used for NOT operation.
When we want to apply two conditions to occur simultaneously in any condition based structure, we need to use AND operator. In  C language, AND operator is represented by && sign.

Friday, January 06, 2012

Nested if-else statement

The word nested itself signifies one within another. Nested if-else statement also signifies the same, an entire if-else structure can be written the body of the if statement or the else statement or within both individually.

Syntax of nested if-else statement is as follows:

Wednesday, January 04, 2012

if-else Statement

Till now we have learnt, the statement(s) is/are executed when the condition with in if statement is true, but we can also execute statement(s) when the condition is false. To execute the statement(s), when the condition becomes false, we need to use else statement along with if statement.

Syntax for if-else statement:

Sunday, January 01, 2012

Multiple statements within if

In some cases, we need to execute multiple instructions or statements on satisfying any condition. In such a condition, we need to place the statements within a pair of braces within if statement.

Syntax:
If (Condition)
{
Statement 1;
Statement 2;

Monday, April 27, 2009

The if statement

The if statement is very common in most of the computer languages. Alike C also reserve this keyword to implement the decision control instruction.
The syntax of this instruction is as follows:
if( The condition = True )
  execute the statements;


Sunday, April 26, 2009

Decision Control Structure

In the previous blogs we have learnt about the different basic requirement to write a C program, now as we move forward we will learn about the different techniques of to write a C program. In this blog we will learn about the decision control structure of C program. Here we will learn about what is decision control structures and decision control algorithms.

Wednesday, April 08, 2009

Control Instruction in C

Control instruction in a programming language determines the flow of control in a program. In C language there are four types of control instruction, which are as follows:
  1. Sequence Control Instruction.
  2. Selection or Decision Control Instruction.
  3. Repetition or Loop Control Instruction.
  4. Case Control Instruction.

Tuesday, April 07, 2009

A simple program to understand printf() and scanf() function

Now we will see how printf() and scanf() function works together to perform a particular work.
We will write a program to calculate the Simple Interest. where the principle, rate of interest and the time in years will be taken from the user.

#include<stdio.h>
#include<conio.h>
void main()

Monday, April 06, 2009

Utility of scanf() function and how it is used.

Utility of scanf() is to input data from the user. The format string used in the printf() statement is same for scanf() statment, only difference is that we have to space & sign before the variable name, and we can’t print any word or statement to make the input user friendly with the scanf() function, to make the input statement user friendly, we have to pint the statement using printf() function and then we have to use scanf() function to input the data.
Syntax of scanf() function is as follows:
scanf(“<format string>”, &<variable name>);


Sunday, April 05, 2009

Utility of printf() function & how it is used.

In the previous blogs we have learnt about the basic part of programming and we will move further with the different programming syntaxes and logical part of the programming. So, now let’s start with the printf() and scanf() functions.
printf() function is used to print any value or character or variable value on the screen.
Syntax of printf() function is as follows:
printf(“<format string>”, <list of variables>);


<format string> could be,
%f for printing real or float values
%d for printing integer values
%c for printing character values

Tuesday, March 31, 2009

The First C program

Now let us try to write a simple C program, to understand what we have read in our previous blogs.
We will star our program development skill, by writing a simple C program to calculate the average of three numbers. {also see: Rules for writing a C program}


Line No. Program statements
1 /* Calculation of the average of three given number */
2 #include<stdio.h>
3 #include<conio.h>
4 void main()

Monday, January 26, 2009

Rules for writing a C program

In the previous blogs we have learnt about the types of variables, constants and the hierarchy of operations, and now we are ready to write our first C program.
A program consists of series of consecutive steps according to the flowchart of the program or to get the desired result. And in C program each instruction is written as a separate statement and this statements must appear in the same order in which we wish them to execute, unless of course the logic of the program demands a deliberate jump or transfer of the program counter or the control to a statement, which is out of sequence.

There are some specific rules to follow, while writing C programs:

Sunday, January 25, 2009

Hierarchy of operations

In an arithmetic operation, while execution of two or more operators , we some time have some problem as to how does it get executed. Lets take an example to understand the thing more properly, we consider an arithmetic expression:
5*m – 7*n

Now sometimes we face problem regarding the execution of the expression, does it corresponds to (5m)-(7n) or 5(m-7n) ? Thus to solve this kind of problems we have to understand the Hierarchy of operations. The priority or the precedence in which the operations in an arithmetic expression are performed is called the hierarchy of operation.

Thursday, December 25, 2008

Integer and float conversion

For efficient C programming, one has to understand the rules for conversion of floating point and integer values in C. {also see: Types of Arithmetic statement}
Some of the points are discussed below which are very important while writing an efficient C program.
  1. An arithmetic operation between two integers always produce an integer result.
  2. An arithmetic operation between two real always produce a real result.
  3. An arithmetic operation between an integer and real always produce a real result.

Wednesday, December 24, 2008

How the execution of the arithmetic statement takes place

While writing an arithmetic statement, it is very important for us to understand how the arithmetic statement works.
Firstly, the operation on the right hand side of the assignment operator takes place using the constants and the numerical value stored in the variable names, and then this value is assigned to the variable on the left hand side.
Though arithmetic statements look very simple, yet the beginners often commit mistakes while writing it, so we have to be very careful while writing an arithmetic statement. Let us discuss on the points which we have to keep in mind while writing an arithmetic statement to avoid errors:

a) C program allows only one variable on the left hand of the assignment operator. That is,

a=b+c;          /* Right Arithmetic statement */
b+c=a;          /* Wrong Arithmetic statement */

Tuesday, December 23, 2008

Types of Arithmetic statement

In C language, arithmetic statements are mainly of three types, which are as follows:

1. Integer type:  In this arithmetic statement all the operands are either integer type variables or integer type constants.
Ex:  int a,b,c,d;
       j=j+5;
       a=b+5*c-d;

2. Real or float type:  In this arithmetic statement all the operands are either real type variables or real type constants.
Ex:  float a,b,c,d;

Monday, December 22, 2008

Arithmetic instruction

In an arithmetic instruction, a variable name is always remains in the left hand side of = and variable name(s) & constant(s) connected by arithmetic operators like +, –, * & /, lie on the left hand side of =.
Ex:
int d=7;
float pi,n=22.0;
pi=n/d;
Here,
Like /, +, –, * are also the arithmetic operators.

Sunday, December 21, 2008

Type declaration instruction

This instruction type is used to declare the type of variable which is being used in the program. In a C program, the variable which is to used must have to declared before using it in any statement. Type declaration is usually done at the beginning of the program.
Ex:
int num;          /* where int is the declaration type and num is a variable name */
float num1;     /* where float is the declaration type and num1 is a variable name */
char name;     /* where char is the declaration type and name is a variable name */

Saturday, December 20, 2008

The purpose of different types of instructions

In the previous topic we have learnt about what are the different types of instructions, now in this blog we will see what are the purposes of those different types of instructions:

1.
Type declaration instruction
-
It is used to declare the type of variable used in C program.
2.
Input/output instruction
-
It is used to input data from the user and obtain the output result to the desired location.
3.
Arithmetic instruction
-
It is used to perform arithmetic operation between constants and variables.
4.
Control instruction
-
It is used to perform sequence of execution of various statements used in a C program.