Saturday, May 31, 2014

Programming Hints :

Programming Hints :

Read more »

Standard Input/Output Examples in C,C++,Pascal

Standard Input/Output :

 UNIX programmers are familiar with notions of filters and pipes–programs that take
one stream of input and produce one stream of output. The output of such programs
is suitable to feed to other programs as input. The paradigm is one of stringing lots of
little programs together rather than producing big, complicated software systems that
try to do everything.
This software tools philosophy has taken somewhat of a beating in recent years due
to the popularity of graphical user interfaces. Many programmers instinctively put a
point-and-click interface on every program. But such interfaces can make it very difficult
to transfer data from one program to another. It is easy to manipulate text output in
another program, but what can you do with an image other than look at it?


C Code:
#include<stdio.h>
int main() {
long p,q,r;
while (scanf("%ld %ld",&p,&q)
!=EOF) {
if (q>p) r=q-p;
else r=p-q;
printf("%ld\n",r);
}
}

C++ Code:
#include<iostream.h>
void main()
{
long long a,b,c;
while (cin>>a>>b) {
if (b>a)
c=b-a;
else
c=a-b;
cout << c << endl;

Pascal Code:
{$N+}
program acm;
var
a, b, c : integer;
begin
while not eof do
begin
readln(a, b);
if b > a then
begin
c := b;
b := a;
a := c
end;
writeln(a - b);
end
end.

By Im@n

Thursday, May 29, 2014

C KeyWords


C Keywords  :
The C language reserves certain words that have special meanings to the language. Those reserved words are sometimes called C keywords. You should not use the C keywords as variable, constant, or function names in your program. The following are the 32 reserved C keyword.
Keyword
Description
auto
Storage class specifier
break
Statement
case
Statement
char
Type specifier
const
Storage class modifier
continue
Statement
default
Label
do
Statement
double
Type specifier
else
Statement
enum
Type specifier
extern
Storage class specifier
float
Type specifier
for
Statement
goto
Statement
if
Statement
int
Type specifier
long
Type specifier
register
Storage class specifier
return
Statement
short
Type specifier
signed
Type specifier
sizeof
Operator
static
Storage class specifier
struct
Type specifier
switch
Statement
typedef
Statement
union
Type specifier
unsigned
Type specifier
void
Type specifier
volatile
Storage class modifier
while
Statement

Note that : All C keywords are written in lowercase letters. As I’ve mentioned, C is a case-sensitive language. Therefore, int, as shown in the list here, is considered as a C keyword, but INT is not.


The char Data Type

The char Data Type
An object of the char data type represents a single character of the character set used by your computer. For example, A is a character, and so is a. But 7 is a number.
But a computer can only store numeric code. Therefore, characters such as A, a, B, b, and so on all have a unique numeric code that is used by computers to represent the characters. Usually, a character takes 8 bits (that is, 1 byte) to store its numeric code.
For many computers, the ASCII codes are the de facto standard codes to represent a character set. (ASCII, just for your information, stands for American Standard Code for Information Interchange.) The original ASCII character set has only 128 characters because it uses the lower 7 bits that can represent 27 (that is, 128) characters.

On IBM-compatible PCs, however, the character set is extended to contain a total of 256 (that is, 28) characters. Appendix C, “ASCII Character Set,” gives a list of the 256 characters.

Character Variables
A variable that can represent different characters is called a character variable.
You can set the data type of a variable to char by using the following declaration format:

char  variablename;
where variablename is the place where you put the name of a variable.
If you have more than one variable to declare, you can either use the following format:
char  variablename1;
char  variablename2;
char  variablename3;
or this one:
char  variablename1, variablename2, variablename3;

Character Constants
A character enclosed in single quotes (`) is called a character constant. For instance, `A’, `a’, `B’, and `b’ are all character constants that have their unique numeric values in the ASCII character set.
You can remember to use the single quote (`), instead of the double quote (“), in character constants because a character constant represents a single character. You’ll see later in the book that the double quote is used to indicate a string of characters.
From the ASCII character set listed in Appendix C, you will find that the unique numeric (decimal) values of `A’, `a’, `B’, and `b’ are 65, 97, 66, and 98, respectively. Therefore, given x as a character variable, for instance, the following two assignment statements are equivalent:

x = `A';
x = 65;

So are the following two statements:

x = `a';
x = 97;

The Escape Character (\)
Actually, you first saw the escape character (\) in Hour 2, “Writing Your First C Program,” when you learned to use the newline character (\n) to break a message into two pieces. In the C language, the backslash (\) is called the escape character; it tells the computer that a special character follows.

For instance, when the computer sees \ in the newline character \n, it knows that the next character, n, causes a sequence of a carriage return and a line feed.

Besides the newline character, several other special characters exist in the C language, such as the following:

Character
Description
\b
The backspace character; moves the cursor to the left one character.
\f
The form-feed character; goes to the top of a new page.
\r
The return character; returns to the beginning of the current line.
\t
The tab character; advances to the next tab stop.

 Printing Out Characters
You already know that the printf() function, defined in the C header file stdio.h, can be used to print out messages on the screen. In this section, you’re going to learn to use the character format specifier, %c, which indicates to the printf() function that the argument to be printed is a character. Let’s first have a look at the program in Listing 4.1, which prints out characters on the screen.

TYPE

Later in this hour, you’ll see a program (in Listing 4.2) that converts numeric values back to the corresponding characters.
http://www.programalgorithms.blogspot.com/

Wednesday, May 28, 2014

# C Program Header Files:

1. <stdio.h>: input and output function in
program.
2. <conio.h>: to clear screen and pause
information function.
3. <ctype.h>: function for testing
characters
4. <string.h>: function for manipulating
string
5. <math.h>: mathmatical function
6. <stdlib.h>: utility function for number,
conversion, storage allocation
7. <assert.h>: function that can beused to
add diagnostics to a program
8. <stdarg.h>: function that can be used to
step through a list of function arguments
9. <setjmp.h>: function that can be used
to avoid the normal call and return
sequence
10. <signal.h>: function for handling
exceptional condition that may arise in a
program
11. <time.h>: function for manipulating
date and time
12. <limits.h>: constant definitions for the
size of C data types
13. <float.h>: definitions relating to
floating-point arithmetic

Tuesday, May 27, 2014

Java hello world program

/*Hello World :
Java programming source code */

class HelloWorld
{
   public static void main(String args[])
   {
      System.out.println("Hello World");
   }
}

Output : Hello World
System :
Hello World is passed as an argument to println method, you can print whatever you want. There is also a print method which doesn't takes the cursor to beginning of next line as println does. System is a class, out is object of PrintStream class and println is the method.