An ARRAY is a accumulating of similar elements. These agnate elements could be all ints, or all floats, or all chars, etc. Usually, the arrangement of characters is alleged a 'string', admitting an arrangement of ints or floats is alleged basically an array. Keep in apperception that all elements of any accustomed arrangement accept to be of the aforementioned type. i.e. they cannot accept an arrangement of ten numbers, of which 5 are ints & 5 are floats.For example, we want to align the allotment...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
main( )
{
int m, f ;
printf ( "\nEnter number " ) ;
scanf ( "%d", &m ) ;
f = factorial ( m ) ;
printf ( "Factorial = %d", f ) ;
}
factorial ( int a )
{
int fact = 1, j ;
for ( j = a ; j >= 1 ; j-- )
fact = fact * j ;
return ( fact ) ;
}
OUTPUT:
Enter number 4
Factorial = 24...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
In C, it is achievable for the functions to alarm themselves. A Function is alleged 'recursive' if a account aural the physique of a action calls the aforementioned function. Sometimes alleged 'circular definition', recursion is appropriately the action of defining something in agreement of itself.
FACTORIAL OF A NUMBER USING RECURSION:
main( )
{
int m, fact ;
printf ( "\nEnter any number " ) ;
scanf ( "%d", &m ) ;
fact = recr ( m ) ;
printf ( "Factorial = %d", fact ) ;
}
recr ( int...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
main( )
{
int x = 20, y = 12 ;
swap ( x, y ) ;
printf ( "\nx = %d y = %d", x, y ) ;
}
swap ( int a, int b )
{
int z ;
z = a ;
a = b ;
b = z ;
printf ( "\na = %d b = %d", a, b ) ;
}
OUTPUT:
a = 12 b = 20
x = 20 y = 12
...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
main( )
{
int r ;
float a, peri ;
printf ( "\nEnter radius of a circle " ) ;
scanf ( "%d", &r ) ;
aperi ( r, &a, &peri ) ;
printf ( "area = %f", a ) ;
printf ( "\nperimeter = %f", peri ) ;
}
aperi ( int r, float *a, float *p )
{
*a = 3.14 * r * r ;
*p = 2 * 3.14 * r ;
}
OUTPUT:
Enter radius of a circle 10
Area = 314.000000
Perimeter = 62.800000...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
main( )
{
int a = 3 ;
int *b ;
b = &a ;
printf ( "\nAddress of a = %u", &a ) ;
printf ( "\nAddress of a = %u", b ) ;
printf ( "\nAddress of b = %u", &b ) ;
printf ( "\nValue of b = %u", b ) ;
printf ( "\nValue of a = %d", a ) ;
printf ( "\nValue of a = %d", *( &a ) ) ;
printf ( "\nValue of a = %d", *b ) ;
}
OUTPUT:
Address of a = 65512
Address of a = 65512
Address of b = 65522
Value of b = 65512
Value of a = 3
Value of a = 3
Value of a = 3
...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
Pointer is a user authentic advice blazon which creates appropriate types of variables which can authority the abode of archaic advice blazon like char, int, float, bifold or user authentic advice blazon like function, arrow etc. or acquired advice blazon like array, structure, union, enum.
POINTER DECLARATION:
Declaring pointers can be actual ambagious & difficult sometimes (working with structures & arrow to pointers). To acknowledge arrow capricious they have to accomplish use...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
Call by reference basically means 'calling function instead of passing values but instead passing the location n umber or address of the variable'.Call by refrence basically use the pointers for address referenc...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
Functions in C language can be called by two methods:
Call by value
Call by reference
Call by value:
Call by value basically means passing values between functions when they are called i.e. user provides values to the functions when they are called in the MAIN() function.THese values can either be any constants or variables.
An example illustrating this is given belo...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
A function is a independent block of statements that accomplish a articular assignment of some kind. Every C affairs can be anticipation of as a accumulating of these functions. As they acclaimed earlier, application a function is something like hiring a being to do a specific job for you. In the above programs we have used main at the starting, this main() itself is a function.A simple program illustrating the use of function is given below:...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
In a difficult programming bearings it seems so simple to accomplish use of a goto to yield the ascendancy area you need. However, always, there is a added affected way of autograph the aforementioned affairs application if, for, while and switch. These constructs are far added analytic and aboveboard to understand.
The huge affair with gotos is that if they do use them they can hardly be abiding how they got to a abiding point in our code. They abstruse the breeze of control. The GOTO keyword...
Sunday
//
Labels:
C LANGUAGE
//
0
comments
//
main( )
{
int n = 27 ;
switch ( n )
{
case 1239 :
printf ( "i am in case 1239 \n" ) ;
break ;
case 56 :
printf ( "I am in case 56 \n" ) ;
break ;
case 29 :
printf ( "I am in case 29 \n" ) ;
break ;
default :
printf ( "I am in default \n" ) ;
}
}
OUTPUT:
I am in defau...
Saturday
//
Labels:
C LANGUAGE
//
0
comments
//
The ascendancy account that lets us accomplish a best from the amount of choices is alleged a switch, or added accurately a switch-case-default, back these keywords go calm to accomplish up the ascendancy statement.
Syntax for switch statement:
switch ( integer expression )
{
case constant 1 :
do this ;
case constant 2 :
do this ;
case constant 3 :
do this ;
default :
do this ;
...
Saturday
//
Labels:
C LANGUAGE
//
0
comments
//
The CONTROL keyword allows us to ignore the statements occurring after the control statement and transfer the control to the beginning of the loop i.e. it refreshes the loop.It is mainly associated with the if statement.It however differs from the break statement i.e. it somehow opposes the break statement.
...
Saturday
//
Labels:
C LANGUAGE
//
0
comments
//
The BREAK statement is basically used to get out of the loop. When the break statement is encountered the control is automatically transferred to the statement executing just after the curly braces of the loop i.e. it allows us to get out of the existing loop at any instant of time.
/*Demonstration of break statement*/
main( )
{
int n, count ;
printf ( "Enter a number " ) ;
scanf ( "%d", &n ) ;
count = 2 ;
while ( count <= n - 1 )
{
if ( n % count == 0 )
{
printf...
Saturday
//
Labels:
C LANGUAGE
//
0
comments
//
There is a accessory aberration amid the alive of while and do-while loops. This aberration is the abode area the action is tested. The while tests the action afore active any of the statements aural the while loop. As adjoin this, the do-while tests the action afterwards accepting accomplished the statements aural the loop.
General syntax for DO-WHILE loop :
do
{
this ;
and this ;
and this ;
and this ;
} while ( this condition is true ) ;
...
Thursday
//
Labels:
C LANGUAGE
//
0
comments
//
The loops that they accept acclimated so far accomplished the statements aural them a bound amount of times. However, in absolute activity programming comes beyond a bearings if it is not accepted advanced how affluence of times the statements in the bend are to be executed.
/* Execution of a loop for many number of times */
main( )
{
char other ;
int n ;
do
{
printf ( "Enter number " ) ;
scanf ( "%d", &n ) ;
printf ( "square of %d is %d", n, n * n ) ;
printf ( "\nWant to enter other...
Thursday
//
Labels:
C LANGUAGE
//
0
comments
//
/* Demonstration of nested loops */
main( )
{
int a, b, s;
for ( a = 1 ; a <= 3 ; a++ ) /* outer loop */
{
for ( b = 1 ; b <= 2 ; b++ ) /* inner loop */
{
s= a + b ; printf ( "a = %d b = %d sum= %d\n", a,...
Thursday
//
Labels:
C LANGUAGE
//
0
comments
//
/* Calculation of simple interest for 4 sets of pi, t and rate */
main ( )
{
int pi, t, i ;
float rate, si ;
for ( i = 1 ; i <= 4 ; i = i + 1 )
{
printf ( "Enter values of pi, t, and rate " ) ;
scanf ( "%d %d %f", &pi, &t, &rate ) ;
si = pi * t * rate / 100 ;
printf ( "Simple Interest = Rs.%f\t", si ) ;
}
}
...
Thursday
//
Labels:
C LANGUAGE
//
0
comments
//

The for bend specify things about a bend in a individual line:
(a) Setting a bend adverse to an basic value.
(b) Testing the bend adverse whether its amount has accomplished the no. of repititions desired.
(c) Increasing the account of bend adverse anniversary time the affairs articulation aural the bend has been executed.
Syntax for FOR loop:...
Thursday
//
Labels:
C LANGUAGE
//
0
comments
//
The general syntax for WHILE loop is given as:
initialise loop counter ;while ( test loop counter using a condition ){do this ;and this;increment loop counter;...
Thursday
//
Labels:
C LANGUAGE
//
0
comments
//
The versatility of the computer lies in its adeptness to accomplish a set of instructions repeatedly. This involves repeating some allocation of the affairs either a defined amount of times or until a specific action is getting satisfied.
Various loops availble in C are as follows:
a for statement
a while statement
a do-while statemen...
Tuesday
//
Labels:
C LANGUAGE
//
0
comments
//
The codicillary or conditional operators ? and : are sometimes alleged ternary operators back they yield arguments. In fact, they anatomy a affectionate of foreshortened if-then-else. Their accepted anatomy is :
expression 1 ? expression 2 : expression 3
If announcement one is accurate (that is, if its amount is non-zero), again the account alternate will be announcement two, contrarily the account alternate will be announcement 3. Example showing conditional operator:
main( )
{
int a = -4,...
Tuesday
//
Labels:
C LANGUAGE
//
0
comments
//
Various logical and arithmetic operators useful in c are give below as:
Operators Type
! Logical NOT
* / % Arithmetic and modulus
+ - ...
Tuesday
//
Labels:
C LANGUAGE
//
0
comments
//
It is nothing different from if else. It is jst rearranging the else with the if followed by it. the else if program is given below which proves the above statement:
/* else if demo */main( ){int a,b,c,d,e, pr ;pr = (a+b+c+d+e) / pr ;if ( pr >= 60 )printf ( "First division" ) ;else if ( pr >= 50 )printf ( "Second division" ) ;else if ( pr >= 40 )printf ( "Third division" ) ;elseprintf ( "fail" ) ...
Tuesday
//
Labels:
C LANGUAGE
//
0
comments
//
#include <stdio.h>
#include <math.h>
main() {
float a, b, c, x1, x2, q, d, x1r, x2r, x1i, x2i;
printf("Input coefficients of square equation a,b,c:");
scanf("%f %f %f", &a, &b, &c);
d=b*b -4.0*a*c;
if (d > 0) {
/* results are real numbers */
q = pow (d, 1./2);
x1 = (-b + q)/(2*a);
x2 = (-b - q)/(2*a);
printf ("X1=%f X2=%f\n", x1, x2);
} ...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
Nested if else means if else into if else i.e. multiple if else statements included in one if else statement.Below is the program demonstrating if else :
/* A demo of nested if-else */
main( )
{
int m ;
printf ( "Enter either 0 or 1" ) ;
scanf ( "%d", &m ) ;
if ( m == 0 )
printf ( "this is zero" ) ;
else
{
if ( m == 1 )
printf ( "this is one" ) ;
else
printf ( "wrong choice" ) ;
}...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
The if account by itself will assassinate a individual statement, or a accumulation of statements, if the announcement afterward if evaluates to true. It does annihilation if the announcement evaluates to false.
SIMPLE IF ELSE PROGRAM :
/* Calculation of gross salary */
main( )
{
float base, gross, da, hra ;
printf ( "Enter basic salary " ) ;
scanf ( "%f", &base ) ;
if (base < 2000 )
{
hra =base * 20 / 100 ;
da = base * 80 / 100 ;
}
else
{
hra = 100 ;
da = base * 90 / 100 ;
}
gross =...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
main( )
{
int n ;
printf ( "Enter a number less than 20 " ) ;
scanf ( "%d", &n ) ;
if ( num <= 20 )
printf ( "THIS IS AN ACCURATE PROGRAM" ) ;...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
The keyword if tells the compiler that what follows is a alarm ascendancy instruction. The action afterward the keyword if is consistently amid aural a brace of parentheses. If the condition, whatever it is, is true, again the account is executed. If the action is not accurate again the account is not executed.
Various conditional operators used for if statement are as follows:
Greater than(>)
Less than(<)
Equal to(= =)
Greater than equla to(>=)
Less than equal to(<=)
Not equal ...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
Many a times,we would like a set of instructions to be accomplished in situation, and an absolutely altered set of instructions to be accomplished in addition situation. This array of bearings is dealt in C programs application a alarm ascendancy instruction.various decision control stements in C are as follows:
The if statement
The if-else statement
The conditional operator...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
There are fundamentally three types of instructions in C:
Type Acknowledgment Instruction
Arithmetic Instruction
Control Instruction
The purpose of anniversary of these instructions is accustomed below:
1) Type acknowledgment instruction
To acknowledge the blazon of variables acclimated in a C program.
2)Arithmetic instruction
To accomplish addition operations amid con-stants & variables.
3)Control instruction
To ascendancy the arrangement of beheading of assorted state-ments in a C pro...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
To accomplish the affairs accepted the affairs itself care to ask the user to accumulation the ethics of p, n & r through the keyboard in the coursework of execution. This can be accomplished application a action alleged scanf( ). This action is a counter-part of the printf( ) function. printf( ) outputs the ethics to the awning admitting scanf( ) receives them from the keyboard. This is illustrated in the affairs apparent below:
/* Calculation of simple interest */
main()
{
int a, b;
float...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
Our first C program would simply calculate simple interest for a set of values representing principle, number of years and rate of interest.
/* Calculation of simple interest */
main( )
{
int a, b;
float c, si ;
a = 1000 ;
b = 3 ;
c = 8.5 ;
/* formula for simple interest */
si = (a * b * c) / 100 ;
printf ( "%f" , si ) ;...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
Variable names are names accustomed to locations in memory. These locations can accommodate integer, absolute or appearance constants. In any language, the categories of variables that it can abutment depend on the categories of constants that it can handle. This is because a specific blazon of capricious can authority alone the aforementioned blazon of constant. For example, an accumulation capricious can authority alone an accumulation constant, a absolute capricious can authority alone a absolute...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
There are basically three data types in c language:
1) Constants-
A constant is an entity that doesn’t change whereas a variable is an entity that may change.
Types of C Constants:
C constants can be divided into two major categories:
(a) Primary Constants
These are again divided into three types as:
Real constants
Integer constants
Character constants
(b) Secondary Constants
These are again further divided into :
Arrays
Pointers
Structures
Union e...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
alphabets A, B, ….., Y, Z a, b, ……, y, z
digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
special symbols ‘ ! @ # % ^ & * ( ) _ - + = | \ { } [ ] : ; " ' < > , . ? / ...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
C is a programming accent developed at AT & T's Bell Laboratories of USA in 1972. It was advised and accounting by a man called Dennis Ritchie. In the backward seventies C began to alter the added accustomed languages of that time like PL/I, ALGOL, etc. No pushed C. It wasn't fabricated the official Bell Labs language. Thus, after any advertisement C's acceptability advance and its basin of users grew. Ritchie seems to accept been afraid that so lots of programmers adopted C to earlier languages...
Monday
//
Labels:
C LANGUAGE
//
0
comments
//
Powered by Blogger.
Blog Archive
-
▼
2011
(50)
-
▼
July
(38)
- INTRODUCTION TO C
- DATA SETS IN C
- DATA TYPES
- VARIABLES
- SIMPLE C PROGRAM
- PROGRAM USING SCANF() AND PRINTF()
- C INSTRUCTIONS
- INTRODUCTION TO DECISION CONTROL STRUCTURES
- IF STATEMENT
- IF STATEMENT PROGRAM
- IF ELSE STATEMENT
- NESTED IF ELSE
- DETERMINING ROOTS OF AN EQUATION
- ELSE IF STATEMENT
- LOGICAL AND ARITHMETIC OPERATORS
- CONDITIONAL OPERATORS
- LOOPS
- THE WHILE LOOP
- The for bend specify things about a bend in a ind...
- EXAMPLE OF FOR LOOP
- NESTING OF LOOPS
- THE ODD LOOP
- THE DO-WHILE LOOP
- BREAK STATEMENT IN C
- THE CONTINUE STATEMENT IN C
- SWITCH STATEMENT IN C
- SIMPLE PROGRAM SHOWING SWITCH STATEMENT
- THE GOTO STATEMENT IN C LANGUAGE
- FUNCTIONS IN C LANGUAGE
- CALLING FUNCTIONS IN C LANGUAGE
- CALL BY REFERENCE IN C LANGUAGE
- POINTERS IN C LANGUAGE
- SIMPLE PROGRAM SHOWING POINTER IN C LANGUAGE
- PROGRAM FOR FUNCTION CALL BY REFERENCE IN C
- SWAPPING OF TWO NUMBERS IN C
- RECURSION IN C LANGUAGE
- FACTORIAL OF A NUMBER WITHOUT RECURSION IN C
- ARRAYS IN C LANGUAGE
-
▼
July
(38)
