Posted by Swapnil on 12:30 pm with No comments

C...?
C is a programming language, it is high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.
Why C seems so popular ?
C is so popular because it is simple, reliable and easy to use. This language are easy to learn. It is structured language and it produce efficient program.
What mean by structured language ?
Structure programming, sometimes known as modular programming, is a subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify.
Major parts of popular operating systems like Windows, Unix, Linux are still written in C.
Posted by Swapnil on 12:00 pm with No comments
Learning C is easier. To learn C programs, We first know what alphabets, numbers, symbols and what is variables and keywords ? And also we know about, how to write programs.
Steps in learning C language :
Alphabets, Digits, Special symbols :
A character denotes any alphabet, digit or special symbol used to represent information.
Constants :
A constant is an entity that doesn't change, whereas, a variable is an
entity that may change. Constant is declare by using 'const' keyword. C
constants can be divided in two types :
1. Primary constants
2. Secondary constant
primary constants :
- Integer constant
- Real constant
- Character constant
Secondary constant :
- Array
- Pointer
- Structure
- Union
- Enum
Let us see the some rules of constructing primary constants :
Rules of constructing Integer constants
- An integer constant must be have at least one digit.
- It must not have a decimal point.
- It can be either positive or negative.
- If no sign precedes an integer constant, it is assumed to be positive.
- No commas or blank are allowed within an integer constant.
- Range of integer constant is depends upon compiler. For compilers like visual studio, gcc, it is -2147483648 to +2147483648 and for compilers like Turbo C or Turbo C++ is -32768 to +32767
Example of integer constant:
const int a=123;
where, 'const' is a keyword to declare variable 'a' as a constant.
Rules of real constant
- An real constant must be have at least one digit.
- It must have a decimal point.
- It can be either positive or negative.
- Default sign is positive.
- No commas or blank are allowed within an integer constant.
Example of real constant
const int a=325.502;
Rules of character constant
- A character constant is a single alphabet, a single digit or a single special symbol enclosed within single inverted commas.
- Both the inverted commas should point to the left.
Example of character constant
const char a='S';
Variables :
Variables in c is nothing but container of data, it named location of data . Each variable have specific type, which determines the size of variables in memory. A particular type of variable can hold only the same type of constant. For example, an integer variable can hold only integer constant, a float variable can hold only real constant and character variables can hold only character constant.
A variables must begins with letter or underscore ( _ ). Name of variable consist an letters, digits and underscore, and it terminate with semi colon ( ; ). See following example to understand ow to declare an variables.
syntax:
type variable_list;
int a; // int is a integer data type and 'a' is variable name
float ab_c; // ab_c is a variable type it can hold only real constant (float)
There are some following important points for declare an variable :
- The first character in variable name must be an alphabet or underscore.
- In variable declaring commas or blanks are not allowed.
- Also some special symbols are not allowed other than underscore.
Keywords :
Keywords are the reserved words used in programming. Keywords are the words whose meaning has already been explained to the c compiler.
Keywords are constant that never changed by user. The keywords also called 'Reserved words'. There are 32 keywords available in c.
Identifiers :
Identifier are created to give unique name to C entities to identify it during the execution of program.
Posted by Swapnil on 11:00 am with No comments
First program in C
Program question :
Q. Write a c program to calculate addition of two numbers.
Ans :
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter first numbers : ");
scanf("%d",&a);
printf("Enter secound number : ");
scanf("%d",&b);
/*add two numbers */
printf("Addition of two numbers : ");
c=a+b;
printf("a+b=");
scanf("%d",&c);
getch();
}
Output :
Enter first number : 40
Enter secound number : 40
Addition of two numbers :
a+b=80
In above program calculate the addition of two numbers. For addition required at least two numbers. In program a and b are two variables that declare to store two number by user, and another variable c are used to store an addition of two numbers.
- printf() - Used to display message on screen. It is necessary to use #include<stdio.h>. stdio.h is standard input output header file.
- scanf() - Is used to read character, string, numeric data from keyboard. The format specifier %d is used in scanf() statement. So that, the value entered is received as an integer.
- getch() - Is used to get a character from console. And holds the output screen.
Posted by Swapnil on 9:23 pm with No comments
The decision control instruction can be implemented in C using:
The if statement :
Using keyword if, implement the decision control instruction.
Syntax :
if(condition is true)
{
//execute statement;
}
In that if the condition is true, then executed the statement, in contrast
if it is false then it is not executed.
for example:
void main()
{
int a,b;
printf("Enter two numbers for compare: \n");
scanf("%d%d",&a,&b);
if(a>b) //check the greater value(if(a greater than b))
{
printf("\n a is greater");
}
if(a<b) //check the greater value(if (a less than b))
{
printf("\n b is greater");
}
if(a==b) //check the value(if (a equal to b))
{
printf("\n both are equal");
}
getch();
}
Output of above example:
Enter two numbers for compare:
10 5 // a=10 and b=5
a is greater
if a=5 and b=10
b is greater
- The if statement
- The if-else statement
- The conditional operator
The if statement :
Using keyword if, implement the decision control instruction.
Syntax :
if(condition is true)
{
//execute statement;
}
In that if the condition is true, then executed the statement, in contrast
if it is false then it is not executed.
for example:
void main()
{
int a,b;
printf("Enter two numbers for compare: \n");
scanf("%d%d",&a,&b);
if(a>b) //check the greater value(if(a greater than b))
{
printf("\n a is greater");
}
if(a<b) //check the greater value(if (a less than b))
{
printf("\n b is greater");
}
if(a==b) //check the value(if (a equal to b))
{
printf("\n both are equal");
}
getch();
}
Output of above example:
Enter two numbers for compare:
10 5 // a=10 and b=5
a is greater
if a=5 and b=10
b is greater
Subscribe to:
Posts (Atom)

