রবিবার, ১৯ সেপ্টেম্বর, ২০১০

16. Know when to use the continue statement


The continue statement is somewhat the opposite of the break statement. It forces the next iteration of the loop to take place, skipping any code in between itself and the test condition of the loop. For example, this program never display any output: 

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
  for(x=0;x<100;++x)
  {
  continue;
  printf("%d",x);    /* this is never executed */
  }
}

In this program when the continue statement is reached, it causes the loop to repeat, skipping the printf() statement. In while and do-while loops, a continue statement will cause control to go directly to the test condition and then continue the looping process. In the case of for, the increment part of the loop is performed,the conditional test is executed, and the loop continues.
   Frankly, continue is seldom used, not because it is poor practice to use it, but simply because good applications for it are not common.

(post by arnob)

15. Use break to exit a loop

The break statement allows you to exit a loop from any point within its body, bypassing its normal termination expression. If you use a break statement under a loop and when the program read the break statement then the loop is immediately stopped, and program control resumes at the next statement following the loop. For example, this loop prints only the numbers 1 to 10.


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
  for (i=1;i<100;i++)
  {
  printf("%d",i);
  if(i==10);
  break;                    /* exit the loop */
  }
}


The break statement can be used with all three of C'a loops.
   You can have as many break statements within a loops as you desire. However, since too many exit points from a loop tend to destructure your code, it is generally best to use the break for special purposes, not as your normal loop exit.


Here a another example for using break.


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,x=0;
for(i=0;i<5;++i)
  {
  x+=(i+j-1);
  printf("%d",x);
  break;
  }
printf("\nx=%d",x);
}


(post by arnob)

14. Remember the C keywords

In C language the ANSI Chas 32 keywords that may not be used as variable or function names. These words, combined with the formal C syntax, form the C programming language. They are listed in this table.

Many C compilers have added several additional keywords that are used to take better advantage of the environment in which the compiler is used, and that give support for inter-language programming, interrupts, and memory organization. Some commonly used extended keywords are show in the table.


   The lowercase lettering of the keywords in significant. C requires that all keywords be in lowercase form. For example RETURN will not be recognized as the keyword return. Also, no keyword may be used as a variable or function name.
(post by arnob)

13. Write yout own functions


  Now I am going to write about how to create a function. If you want to create your own function you can do this. Functions are the building of C. So  for, the programs you have see included only one function: main(). Most real-world programs however, will contain many functions. The general form of a C program that has multiple functions is shown here: 

/*include header files here*/
/*function prototypes here*/
int void main()
{
/*-----*/
}
ret-type f1 (param-list)
{
/*-----*/
}
ret-type f2(param-list)
{
/*------*/
}
.
.
.
.
ret-type fN(param-list)
{
/*------*/
}

You can call your functions by different names. Here, ret-type specifies the type of data return by the function. If a function does not reutrn a value then it's returned type mast be void and if a function does not use parameters, then its param-list should contain the keyword void.
   Now I am going to write another example.

#include<stdio.h>
#include<conio.h>
int funct1(int a, int b);
main()
{
int a,b,c;
scanf("%d %d",&a,&b);
c=funct1(a,b);
printf("%d",c);
}
funct1(int a, int b)
{
int c;
c=a+b;
return(c);
}
  
In this program I use a function called funct1. Remember that if we declared one variable under one function that variable can not known in other function. I mean we can not use that variable in another  function.  In that program after the library function I write function prototypes (int funct1 (int a, int b)). Here int is return type of this function and in the bracket it is called parameter. C=funct1(a,b); In this line i called the function. You must try it. OK good luck.
(Post by arnob)

শনিবার, ১৮ সেপ্টেম্বর, ২০১০

12. The basics of if-else statement


The if-else statement is used to carry out a logical test and then take one of two possible actions, depending on the outcome of the test. Whether the outcome is true or false.
   The else potion of the if-else statement is optional. Thus in its simplest general form, the statement can be written as

                          if (expression) statement

When the if statement is true, then the else statement is not working. When the if statement is false then the else statement is working. We can easily use many if statement under one if statement. It is easy to use.  When you enter a expression under an if statement, the expression must be placed in parentheses, as shown. In this form, the statement will be executed only if the expression has a nonzero value  (i.e., if expression is true.). If the expression has a value of zero (the expression is false), then the statement will be ignored. 
  
For example: 


if(a==10)
printf("Yes")
else
printf("No")


Here if the 1st statement is true i mean if (a==10), then it will be print Yes. If  the if statement is false i mean if (a!=10) then it will be print No.


Here is a  complete C program for using if else.


#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int y;
printf("Enter the age : ");
scanf("%d",&y);
if(y>=145)
printf("Sorry he/she is death.");
else
if(y>=100)
printf("con......");
else
if(y>=80)
printf("Very old man");
else
if(y>=60)
printf("Old man");
else
if(y>40)
printf("Middle age man");
else
if(y>20)
printf("Young");
else
if(y>=15)
printf("Teens");
else
if(y>=8)
printf("Boy");
else
if(y>=5)
printf("Child");
else
if(y>=0)
printf("Baby");
else
if(y<0)
printf("Up coming");
getch();
}


(post by arnob)


শুক্রবার, ১৭ সেপ্টেম্বর, ২০১০

11. LIBRARY FUNCTIONS

A library function is a function that carry out various commonly used operations, but it is not part of the program itself.Some functions return a data item to their access point; others indicate whether a condition is true or false by returning a 1 or a 0, respectively; still others carry out specific operations on data items but do not return anything. Features which tend to be computer-dependent are generally written as library functions. Libraries save programmers the bother of writing code to do the same tasks time and time again; in short, libraries encourage code reuse.
   For example, there are library functions that carry out standard input/output operations, functions that perform operations on characters, functions that perform operations on strings and functions that carry out various mathematical calculations. Other kinds of library functions are also available.
   There are two main types of libraries: static libraries that are read by the compiler at compile-time and bound into the final version of the executable code; and dynamic libraries that are referred to by name to the compiler but the code is not actually incorporated into the executable until the program is run. One advantage of dynamic libraries is that they can be updated without having to update the program that calls them.
   A library function is accessed simply by writing the function name, followed by a list of arguments that represent information being passed to the function. The arguments must be enclosed in parentheses and separated by commas. The arguments can be constants, variable names, or more complex expressions. The parentheses must be present, even if there are on arguments.
   A function that returns a data item can appear anywhere within an expression, in place of a constant or an identifier. A function that carries out operations on data items but does not return anything can be accessed simply by writing the function name, since this type of function reference constitutes an expression statement.

বৃহস্পতিবার, ১৬ সেপ্টেম্বর, ২০১০

10. ARITHMETIC OPERATORS

Today I am going to write about Arithmetic operators. There are five arithmetic operators in C. They are
 
 

The operands acted upon by arithmetic operators must represent numeric values. Thus, the operands can be integer quantities, floating-point quantities or characters quantities. Remember one thing that character constants represent integer values, as determined by the computer's character set. The remainder operator (%) requires that both operands be integers and the second operand be nonzero.
     Division of one integer quantity by another is referred to as integer division. This operation always results in a truncated quotient. On the other hand, if a division operation is carried out with two floating-point quotient.

   Example:  Suppose that m and n are integer variables whose values are 15 and 4, respectively. Several arithmetic expressions involving these variables are shown below, together with their resulting values.



Notice the truncated quotient resulting from the division operation, since both operands represent integer quantities. Also, notice the remainder resulting from the use of the modulus operator in the last expression.

09. ESCAPE SEQUENCES

Certain non printing characters, as well as the backslash (\) and the apostrophe ('), can be expressed in terms of escape sequences. An escape sequence always begins with a backward slash and is followed by one or more special characters. For example, a line feed  (LF), which is referred to as a newline in C, can be represented as \n. Such as escape sequences always represent single characters, even though they are written in terms of two or more characters.
  The commonly used escape sequences are listed below.

08. COSNTANTS

There are four basic types of constants in C. They are integer constants, floating-point constants, character constants and string constants (there are also enumeration constants). Moreover, there are several different kinds of integer and floating-point constants, as discussed below.
  Integer and floating-point constants represent numbers, They are often referred to collectively as numeric-type constants. The following rules apply to all numeric-type constants.

1. Commas and blank space cannot be included within the constant.

2. The constant can be preceded by a minus (-) sign if desired.

3. The value of a constant cannot exceed specified minimum and maximum bounds. For each type of constant, these bounds will vary from one C compiler to another.


Integer Constants : 

  An integer constant is an integer-valued number. Thus it consists of a sequence of digits. Integer constants can be written in three different number systems: decimal (base 10), octal (base 8) and hexadecimal (base 16).Beginning programmers rarely, however, use anything other than decimal integer constants.
  A decimal integer constant can consist of any combination of digits taken from the set 0 through 9. If the constant contains two or more digits, the first digit must be something other than 0.

For example : 0      1       743   5280   32767   9999
They all are valid decimal integer constants.

Note that : you can not use any coma(,), any fullstops (.), Bland space( ), and can not use first number zero (0998).

  An octal integer constant can consist of any combination of digits taken from the set 0 through 7.
However the first digit must be 0, in order to identify the constant as an octal number .

For example:  0    01   0743    0774
They all are valid octal decimal integer constants.

In a octal constants you does not begin with 0, can not use ( . ) .

   A hexadecimal integer constant must begin with either  0x or 0X. It can then be followed by any combination of digits taken from the sets 0 through 9 and a through f  (either upper-or lowercase). note that the letters a through f (or A through F) represent the (decimal )quantities 10 through 15, respectively. 

 For example: 0x   0xbb7    0x7ddd  0xabcd
They all are valid hexadecimal integer constants.

 

বুধবার, ১৫ সেপ্টেম্বর, ২০১০

07. WRITE A C PROGRAM STEP-3

Now i am going to write some simple complete C program. First of all I want to writ a program to adding  two number. Lets go:


/* Add two number */

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a,b,c;
printf("Enter a two number: ");
scanf("%d %d",&a,&b);
c=a+b;
printf("Ans= %d",c);
getch();
}

Here 1st of all user input two number (for example the two number is 5 and 9). Then i take this by using scanf function. Now (c=a+b) i mean c=the value of a + the value of b. so the ans is c=5+9, so c=14, then i print c by using the function printf.
So the output is Ans=14

Now the second one is calculate the area of acircle. So lats start...

/* program to calculate the area of a circle */

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
float radius, area;
printf("Radius = ?");
scanf("%f",&radius);
area=3.1416 * radius * radius;
printf("Area= %f "area);
getch();
}

06. How to use scanf

Many new C programmer having problem to use scanf. Today i want to write something about use of scanf. Scanf is a function We use it for input. If i need to input something to a user then i simply use scanf.  Look at this cord.

Cord:

/* Use of scanf */

#include<stdio.h>
main()
{
int a;
printf("Enter a number: ");
scanf("%d",&a);
printf("%d",a);
getch();
}


In this cord I use printf and scanf. In printf function there is no( & ), but in scanf there mast be a (&) remember it. See when we use scanf  we first declared what the variables type was
"%d" for int ,"%f" for float ,%e for double ,"%c" for char , "%s" for strings.

  Hear i use scanf for input something. Then i use printf to print that thing which i get input.

Writern by arnob

05. VARIABLE DECLARATIONS

Variable declarations is the most important thing in  C program. Fist of all we want to know what is variable? Variable is a symbol or name that stands for a value.X and Y are variables. Variable is represent numerical value, characters, characters string etc. Variable play an important rule in computer programing. For using a variable in program you mast declared that variable. There are many kinds of variable such as integer type variable, float type variable, character type variable etc.

  Now we learn how to declared a variable in C program. A variable mast be declared after the main function. If you want to declared a integer type variable in your program, after main  function you write this:

int a,b,c;

If the variable type is float you can write

float a,b,c;

Now i writer a program for declared a variable


/* Declared a variable */

#include<stdio.h>

main()
{
int a,b,c,d;
float x,y,z;
getch();
}

This program can not give any out put. This is a  program for declared variable.

(post by Arnob)

04. WRITE A C PROGRAM STEP-2

Now we want to print some thing by a C program:
/* print you name */ /* Title */

#include<stdio.h>   /* Library file access */
#include<conio.h>
void main()          /*Function heading */
{
clrscr( );
printf("Enter your name !");
getch( );
}



In this programm i use [clrscr();] for to clear the output screen. suppose you run a program then alter it and run it again you may find that the previous output is still stacked there itself, at this time clrscr(); would clean the previous screen. If you use clrscr in your function you mast write a library function [#include<conio.h>]. This library function also use if you use getch  in your program. [ getch(); ] is used to hold the screen in simple language, if u don't write this the screen. Another thing i used in this program that is printf . If you want to print some thing in your program you mast yous this function name printf [printf();]. If you use this in your program you also need to write a library function called strio.h [#include<stdio.h>].

Pointers

A pointer is a variable that represents the location of a data item, such as a variable or an array element. Pointers are used frequently in C, as they have a number of useful applications. For example, pointers can be use to pass information back and forth between a function and its refrence point In particulr, pointers provide a way to return multiple data items from a function via function arguments. Pointers also permit refernces to other functions to be specified as aguments to a given function. This has the effect of passig functions as arguments to the given function.









03. WRITE A C PROGRAM STEP-1

For write a C program: 
1.  1st of all u mast write Library file access.(#include<library file name >)

2.  Then write Function heading.(main())

3.  Then start a second bracket and end a second bracket. Now you mast be write every thing in the middle of second bracket.

4.  Now write your program. For example:


/* start writing a C program */

#include<stdio.h>    /*Library file access */        
#include<conio.h>
main()      /*Function heading */
{

/* now here u write your program code */
}

/*post by Arnob */

02. STRUCTURE OF A C PROGRAM

Every C program consists of one or more functions. One of the functions must be called main. The program will always begin by executing the main function, which may access other functions. Every C program mast have one main function. Any other function definitions must be defined separately, either ahead of or after main.
Each function must contain: 
1. A function heading, which consist of the  function name, followed by an optional list of arguments, enclosed in parentheses.
2. A list of argument declarations, if arguments are included in the heading.
3. A compound statement, which comprises the remainder of the function.

The arguments are symbols that represent information being passed between the function and other parts of the program.
  Each compound statement is enclosed within a pair of braces. The braces may contain one or more elementary statements and other compound statements. Thus compound statements may be nested, one within another. Each expression statement must end with a semicolon(;).
  Comments may appear anywhere within a program, as long as they are placed within the delimiters /* and */(/*this is a comment */). Such comments are helpful in identifying the program's principal features or in explaining the underlying logic of various program features.
  These program components will be discussed in much greater detail later in this book. For now, the reader should be concerned only with an overview of the basic features that characterize most C programs.
(post by Arnob)

01. INTRODUCTION TO C

C is a general-purpose, structured programming language. Its instructions consist of terms that resemble algebraic expressions, augmented by certain English keyword such as if, else,for,do and while. In this respect C resembles other high-level structured programming languages such as Pascal and FORTRAN. C also contains certain additional features, however, that allow it to be used at a lower level, thus bridging the gap between machine language and the more conventional high-label languages. This flexibility allows C to be use for systems programming as well as for applications programming.

  C is characterized by the ability to write very concise source programs, due in part to the large number of operators included within the language. It has a relatively small instruction set, though actual implementations include extensive library functions which enhance the basic instructions. Furthermore, the language encourages users to write additional library functions of their own. Thuse the features and capabilities of the language can easily be extended by the user.

  C compilers are commonly available for computers of all size, and C interpreters are becoming increasingly common. The compilers are usually compact, and they generate object programs that are small interpreters are less efficient, though they are easier to use when developing a new program. Many programmers begin with an interpreter, and then switch to a compiler once the program has been debugged.

  Another important characteristic of  C is that its programs are highly portable, even more so than with other high-level languages. The reason for this is that C relegates most computer-dependent features to its library functions. Thus, every version of C is accompanied by its own set of library functions, which are written for the particular characteristics of the host computer . These library functions are relatively standardized, however, and each individual library function is generally accessed in the same manner from one version of C to another. Therefore,most C programs can be processed on many different computers with little or on alteration.

মঙ্গলবার, ১৪ সেপ্টেম্বর, ২০১০

About us

Administrator: The name of administrator is Md  Bahar uddin ARNOB. He lives in Bangladesh at Dhaka. He is a student of Stamford University Bangladesh in the department of CSE


Author: He is j.siam . He lives in Bangladesh at Dhaka. He is a student of AIUB in the department of CSE.



Author: He is Abdula al mamun. He lives in Bangladesh at Dhaka. He is a student of Stamford University Bangladesh. His department is CSE.





Something about this blog:  Hello friends, how are you? we are three friends Arnob, Siam and Mamun. We all are student of CSE. We all konw that the programming is one of the most importent and heard subject in CSE. We want to creat a sits about programmin. Here we are trying to make easy the progtamming subject. If you have any question please call me Arnob 01924066050.