Sunday, 30 November 2014
Writing a Program
Writing Program:-
In order to write program in any programming language, it is necessary to know what about its command and syntax. Programmer must also know that what are the basic usage of commands and other programming structure. Programs written in C language is really not much difficult to understand that one written in any other language, once you become used to the basic syntax.
Function Definition: All C programs are divided into units called ‘functions’.
Every C program consists of one or more functions. Consider the following program:
#include <stdio.h>
void main(void)
{
printf ( "Hello, World");
}
The above program has only one function “main”. This function is one to which control is passed from the operating system when the program is run, i.e. it is the first function executed. The word “void” preceding “main” specifies that the function “main” will not return a value. The second “void” in paranthesis specifies that the function takes no arguments.
Input Statement:-
A statement used to input a single character or a sequence of characters from the keyboard.
1. getch – a function used to input a single character from the keyboard without echoing the character on the monitor.
Syntax: getch( );
Example: ch = getch( );
2. getche – a function used to input a single character from the keyboard, the character pressed echoed on the monitor.
Syntax: getche( );
Example: ch = getche( );
3. getchar – a function used to input a single character from the keyboard, the character pressed echoed on the monitor, terminated by pressing ENTER key.
Syntax: getchar( );
Example: ch = getchar( );
4. gets – a function used to input sequence of character from the keyboard, spaces are accepted, terminated by pressing enter key.
Syntax: gets( );
Example: gets(ch);
5. scanf – a function used to input single character or sequence of characters from the keyboard, it needs the control string codes in able to recognized. Spaces are not accepted upon inputting. Terminated by pressing spacebar.
Syntax: scanf(“control string codes”, identifier);
Example: scanf(“%d”, &num);
Output Statement:-
A statement used to display the argument list or string on the monitor.
1. printf – a function used to display the argument list on the monitor. It sometimes needs the control string codes to help display the remaining argument on the screen.
Syntax: printf(“control string codes”, argument list);
Example: printf(“Hello, %s, you are %d years old”, name, age);
2. putchar – a function used to display the argument list or string on the monitor. It is like overwriting a character.
Syntax: putchar( );
Example: putchar(tolower (ch));
3. puts – a function used to display the argument list or string on the monitor. It does not need the help of the control string codes.
Syntax: puts( );
Example: puts(“hello”);
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment