Sunday, November 17, 2013

C First Program

C Programming Introduction : Tips

  1.  Every C Program Should have exactly one main function
  2. C Program Execution Always Starts from main.
  3. Execution of C Program begins at Opening brace of function and ends at closing brace of the function
  4. Generally all statements in c are written in Lowercase Letters.
  5. Uppercase Letters are used for Symbolic names,output strings and messages
  6. Every C statement must ends with semicolon
  7. All variables must be declared with respective data types before using .
  8. C is free form-Language
  9. Comments can be inserted anywhere in C Program , but nested comments are not supported by C .
  10. Braces are Generally Used for the Grouping of statements

Sample C Program :

//C hello world example
#include <stdio.h>
 
int main()
{
  printf("Hello world\n");
  return 0;
}
Output: 
Hello world

C Language Applications

Application Of C Programming

C Programming is best known programming language. C Programming is near to machine as well as human so it is called as Middle level Programming Language. C Programming can be used to do verity of tasks such as networking related,OS related.

Application of C Programming are listed below -

  1. C language is used for creating computer applications 
  2. Used in writing Embedded softwares
  3. Firmware for various electronics, industrial and communications products which use micro-controllers.
  4. It is also used in developing verification software, test code, simulators etc. for various applications and hardware products.
  5. For Creating Compiles of different Languages which can take input from other language and convert it into lower level machine dependent language.
  6. C is used to implement different Operating System Operations.
  7. UNIX kernel is completely developed in C Language.

List of Applications of C Programming

List of Application
Operating SystemsNetwork DriversPrint Spoolers
Language CompilersAssemblersText Editors
Modern ProgramsData BasesLanguage Interpreters
SimulatorsUtilitiesEmbedded System

Saturday, November 16, 2013

C Language Features

Features of C Programming Language :

C Programming is widely used in Computer Technology, We can say that C Programming is inspiration for development of other languages. We can use C Programming for different purposes. Below are some of the Features of C Programming language -
Features of C
Low Level Language SupportProgram Portability
Powerful and Feature RichBit Manipulation
High Level FeaturesModular Programming
Efficient Use of Pointers

1 . Low Level Features :

  1. C Programming provides low level features that are generally provided by the Lower level languages. C is Closely Related to Lower level Language such as “Assembly Language“.
  2. It is easier to write asssembly language codes in C programming.

2 . Portability :

  1. C Programs are portable i.e they can be run on any Compiler with Little or no Modification
  2. Compiler and Preprocessor make it Possible for C Program to run it on Different PC

3 . Powerful

  1. Provides Wide verity of ‘Data Types
  2. Provides Wide verity of ‘Functions’
  3. Provides useful Control & Loop Control Statements

4 . Bit Manipulation

  1. C Programs can be manipulated using bits. We can perform different operations at bit level. We can manage memry representation at bit level. [Eg. We can use structure to manage Memory at Bit Level.]
  2. It provides wide verity of bit manipulation Operators. We have bitwise operators to manage Data at bit level.

5 . High Level Features :

  1. It is more User friendly as compare to Previous languages. Previous languages such as BCPL,Pascal and other programming languages never provide such great features to manage data.
  2. Previous languages have there pros and cons but C Programming collected all useful features of previous languages thus C become more effective language.

6 . Modular Programming

  1. Modular programming is a software design technique that increases the extent to which software is composed of separate parts, called modules
  2. C Program Consist of Different Modules that are integrated together to form complete program

7 . Efficient Use of Pointers

  1. Pointers has direct access to memory.
  2. C Supports efficient use of pointer .

8 . More Efficient


                                 Dennis Ritche : Father of C Programing Language

Father of C Programming : Dennis Ritchie


Born OnSeptember 9 1941
Born inBronxville – New York
Full NameDennis MacAlistair Ritchie
NicknameDMR
NationalityAmerican
Graduate FromHarvard University
Graduate InPhysics and Applied Mathematics


Dead OnOctober 12 2011

Dennis Ritchie : Known for

NoWhat ?
1Creator of C Programming
2Creator of UNIX operating System
3Co-author of “The C Programming Language”

Awards :

YearAward
1982Ritchie and Ken Thompson jointly received the Turing Award for their development of generic operating systems theory
1999Thompson and Ritchie jointly received the 1998 National Medal of Technology from President Bill Clinton for co-inventing the UNIX operating system and the C programming language

History Chart : C Programming

Milestones In C Programming History :

  • A new language B a second attempt.1970.
  • A totally new language C a successor to B 1971
  • By 1973 UNIX OS almost totally written in C.

History of C Programming : Chart

History of c programming Chart

C Programming Inventor :

C Programming Language Inventor

History of C Programming Language


  1. C is a programming language which born at “AT & T’s Bell Laboratories” of USA in 1972.
  2. It was written by Dennis Ritchie.
  3. This language was created for a specific purpose : to design the UNIX operating system (which is used on many computers).
From the beginning, C was intended to be useful to allow busy programmers to get things done because C is such a powerful, dominant and supple language, its use quickly spread beyond Bell Labs. in the late 70’s

Why Name “C” was given to Language ?

  1. Many of its principles and ideas were taken from the earlier language B.
  2. Ken Thompson was the developer of B Language.
  3. BCPL and CPL are the earlier ancestors of B Language
  4. CPL is common Programming Language.In 1967, BCPL Language ( Basic CPL ) was created as a scaled down version of CPL
  5. As many of the features were derived from “B” Language thats why it was named as “C”.
  6. After 7-8 years C++ came into existence .

Summary of C Programming Language History

Summary of C Programming History
1B Language Developed ByKen Thompson
2Operating System Developed in CUNIX
3Developed atAT & T Bell Laboratory
4Creator of Traditional CDennis Ritchie
5Year1972

C Programming Language Timeline :

Programming LanguageDevelopment YearDeveloped by
ALGOL1960International Group
BCPL1967Martin Richards
B1970Ken Thompson
Traditional C1972Dennis Ritchie
K&R C1978Brain Kernighan and Dennis Ritchie
ANSI C1989ANSI Committee
ANSI/ISO C1990ISO Committee

Friday, November 15, 2013

C Program to Calculate Area of Scalene Triangle

#include<stdio.h>
#include<math.h>
int main()
{
int s1,s2,angle;
float area;
clrscr();
printf("\nEnter Side1 : ");
scanf("%d",&s1);

printf("\nEnter Side2 : ");
scanf("%d",&s2);

printf("\nEnter included angle : ");
scanf("%d",&angle);

area = (s1 * s2 * sin((M_PI/180)*angle))/2;

printf("\nArea of Scalene Triangle : %f",area);
return(0);
}
Enter Side1 : 3
Enter Side2 : 4
Enter included angle : 30
Area of Scalene Triangle : 3.000000

C Program for Beginners : Area of Scalene Triangle

C Program to find Area of Scalane Triangle

Properties of Scalene Triangle :

  1. Scalene Triangle does not have sides having equal length.
  2. No angles of Scalene Triangle are equal.
  3. To calculate area we need at least two sides and the angle included by them.

Formula to Find Area of Scalene Triangle :

Explanation and Program Logic :

Part 1 : M_PI

sin((M_PI/180)*angle)
  • It is Constant defined in math.h Header File
  • It contain value = 3.14 in short instead of writing 3.14 write directly M_PI.

Part 2 : ( M_PI / 180 ) * angle

  • We are accepting angle in degree.
  • C function sin takes argument in radian , so to convert angle into radian we are purposefully writing above statement.

Part 3 : sin function

  • It computes sine of an angle

The % Format Specifiers in C

The % specifiers that you can use in ANSI C are:

Usual variable type Display
%c: char single character
%d (%i): int signed integer
%ld: long signed integer
%hd short signed integer
%e (%E): float or double exponential format
%f: float signed decimal
%lf: double signed decimal
%g: (%G) float or double use %f or %e as required
%o: int unsigned octal value
%p: pointer address stored in pointer
%s: array of char sequence of characters(string)
%u: int unsigned 
%lu: long unsigned
%x: (%X) int unsigned hex value

C Program to find area and circumference of circle

#include<stdio.h>

int main()
{
int rad;
float PI=3.14,area,ci;
clrscr();

printf("\nEnter radius of circle: ");
scanf("%d",&rad);

area = PI * rad * rad;
printf("\nArea of circle : %f ",area);

ci = 2 * PI * rad;
printf("\nnCircumference : %f ",ci);

return(0);
}

Output :

Enter radius of a circle : 1
Area of circle : 3.140000
Circumference  : 6.280000
If you have any problem regarding any program, mail me at tanveersingh800@gmail.com

Introduction to C language for beginners

C is a general-purpose high level language that was originally developed by Dennis Ritchie for the Unix operating system. It was first implemented on the Digital Eqquipment Corporation PDP-11 computer in 1972.
The Unix operating system and virtually all Unix applications are written in the C language. C has now become a widely used professional language for various reasons.
  • Easy to learn
  • Structured language
  • It produces efficient programs.
  • It can handle low-level activities.
  • It can be compiled on a variety of computers.

Facts about C

  • C was invented to write an operating system called UNIX.
  • C is a successor of B language which was introduced around 1970
  • The language was formalized in 1988 by the American National Standard Institue (ANSI).
  • By 1973 UNIX OS almost totally written in C.
  • Today C is the most widely used System Programming Language.
  • Most of the state of the art software have been implemented using C

Why to use C ?

C was initially used for system development work, in particular the programs that make-up the operating system. C was adoped as a system development language because it produces code that runs nearly as fast as code written in assembly language. Some examples of the use of C might be:
  • Operating Systems
  • Language Compilers
  • Assemblers
  • Text Editors
  • Print Spoolers
  • Network Drivers
  • Modern Programs
  • Data Bases
  • Language Interpreters
  • Utilities

C Program File

All the C programs are writen into text files with extension ".c" for example hello.c. You can use "vi" editor to write your C program into a file.
This tutorial assumes that you know how to edit a text file and how to write programming insturctions inside a program file.

C Compilers

When you write any program in C language then to run that program you need to compile that program using a C Compiler which converts your program into a language understandable by a computer. This is called machine language (ie. binary format). So before proceeding, make sure you have C Compiler available at your computer. It comes alongwith all flavors of Unix and Linux.
If you are working over Unix or Linux then you can type gcc -v or cc -v and check the result. You can ask your system administrator or you can take help from anyone to identify an available C Compiler at your computer.