You are on page 1of 5

‘C’ Language

What is Language?
Language is a medium of communication. There are several types of languages like:
1. Low Level Language: - Low level language is used to design system software and
utilities etc.
2. High Level Language: -High level language is used to design the application software
like Business Problems and Scientific problem.
What is C?
C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972. It
was designed and written by a man named Denis Ritchie. The C Compilers combines the
capabilities of an assembly language with the feature of a high-level language and therefore it
is well suited for writing both system software and business package.
There are only 32 keywords and its strength lies its built-in functions.
Constants
Constant in C refer to fixed value that do not change during the execution of a program. This
quantity can be stored at a location in the memory of the computer.
Types of C Constants
C constants can be divided into two major categories:
1. Primary Constants
a) Integer Constants
b) Real Constants
c) Character Constants
2. Secondary Constants
a) Array
b) Pointer
c) Structure
d) Union etc.
Rules for Constructing Integer Constants
a) An integer constant must have at least one digit.
b) It must not have a decimal point.
c) It could be either positive or negative.
d) No commas or blanks are allowed within an integer constant.
e) The allowable range for integer constants is -32768 to +32767.
Rules for Constructing Real Constants
a) An integer constant must have at least one digit.
b) It must have a decimal point.
c) It could be either positive or negative.
d) No commas or blanks are allowed within an integer constant.
Rules for Constructing Character Constants
a) 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.
b) The maximum length of a character can be 1 character.
Variables
In C a quantity which may vary during program execution is called a variable. Variable
names are given to locations in the memory of computer where different constants are stored.
These locations can store integer, real or character constants.
Rules for Constructing Variable Names
a) A variable name is any combination of 1 to 8 alphabets, digits or underscores. Some
compilers allow variable names whose length could be up to 40 characters, still, it
would be safer to stick to the rule of 8 characters.
b) The first character in the variable name must be an alphabet.
c) No commas or blanks are allowed within a variable name.
d) No special symbol other that an underscore can be used in a variable name.
C Keywords
Every C word is classified as either a keyword or an identifier. All keywords have fixed
meanings and these meaning cannot be changed. Keywords serve basic building blocks for
program statements.
There are 32 Keywords available in C.

auto double if static break else int struct
case enum long switch char extern near typedef
const float register union continue return default for
short void do goto signed while far unsigned
/*for simple addition, subtraction, #include<stdio.h>
multiplication and division*/ #include<conio.h>
#include<stdio.h> void main()
#include<conio.h> {
void main() int a,b;
{ clrscr();
int a,b,c; printf("enter any two numbers");
clrscr(); scanf("%d%d",&a,&b);
printf("enter the value of a and b"); if(a>b)
scanf("%d%d",&a,&b); printf("a is large number:%d",a);
c=a+b; else
printf("total=%d",c); printf("b is large number:%d",b);
c=a-b; getch();
printf("Subtraction=%d",c); }
c=a*b; /*program to find out largest number in
printf("Multiplication=%d",c); given three numbers*/
c=a/b; #include<stdio.h>
printf("Division=%d",c); #include<conio.h>
getch(); void main()
} {
int a,b,c;
/*for simple and compound interest*/ clrscr();
#include<stdio.h> printf("enter any three numbers");
#include<conio.h> scanf("%d%d%d",&a,&b,&c);
#include<math.h> if(a>b&&a>c)
void main() printf("a is large number:%d",a);
{ else
int p,r,t,si,ci; if(b>a&&b>c)
clrscr(); printf("b is large number:%d",b);
printf("enter the value of principle,rate of else
interest,number of years"); printf("c is large number:%d",c);
scanf("%d%d%d",&p,&r,&t); getch();
si=(p*r*t)/100; }
printf("simple interest=%d",si);
ci=p*pow((100+r)/100.0,t)-p; /*program to do print the four digit number
printf("compound interest=%d",ci); in the reverse form*/
getch(); #include<stdio.h>
} #include<conio.h>
void main()
/*program to find out area of a triangle*/ {
#include<stdio.h> int a,b,c,d,r1,r2,r3,r4;
#include<conio.h> clrscr();
void main() printf("enter the value of a four digit
{ number");
int b,h,area; scanf("%d",&a);
clrscr(); r1=a%10;
printf("enter the value of breadth and height"); b=a/10;
scanf("%d%d",&b,&h); r2=b%10;
area=(b*h)/2; c=b/10;
printf("area of triangle is:%d",area); r3=c%10;
getch(); r4=c/10;
} d=r1*1000+r2*100+r3*10+r4*1;
printf("reverse form=%d",d);
/*program to find out largest number in getch();
given two numbers*/ }
/*program to find out the division*/ /*find the enter number is prine or not*/
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
void main() void main()
{ {
int a,b,c,d,e,av; int num,i;
clrscr(); clrscr();
printf("enter marks of five subjects"); printf("\n enter a numner");
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e); scanf("%d",&num);
av=(a+b+c+d+e)/5; i=2;
if(av>=60) while(i<num)
printf("first division"); {
else if(num%i==0)
if(av>=50&&av<60) {
printf("second division"); printf("not a prime number");
else break;
if(av>=35&&av<50) }
printf("third division"); i++;
else }
printf("fail"); if(i==num)
getch(); printf("prime number");
} getch();
}
/*programe to do print the counting*/
#include<stdio.h> /*program for printing ‘*’ */
#include<conio.h> #include<stdio.h>
void main() #include<conio.h>
{ void main()
int counting=1; {
clrscr(); int rows,i,j;
while(counting<=100) clrscr();
{ printf("\n enter the number of rows:");
printf("%d\t",counting); scanf("%d",&rows);
counting=counting+1; for(i=1;i<=rows;i++)
} {
} for(j=1;j<=i;j++)
/*programe to find out the value of even printf("*");
numbers among 1 to 100*/ printf("\n");
#include<stdio.h> }
#include<conio.h> }
void main()
{ /*magic number program*/
int count=1,even=0; #include<stdio.h>
clrscr(); #include<conio.h>
while(count<=100) void main()
{ {
if(count%2==0) int magic=22;
{ int guess;
printf("%d\t",count); clrscr();
even=even+1; printf("enter your guess for the number");
} scanf("%d",&guess);
count=count+1; if(guess==magic)
} printf("\n Congratulation!Right guess");
} else
printf("\n Wrong guess");
getch(); scanf("%d",&n);
} while(count<n)
{
/*find wheather number is even or odd by printf("\n %d number=",count+1);
using switch case*/ scanf("%f",&x);
#include<stdio.h> sum+=x;
#include<conio.h> ++count;
void main() }
{ average=sum/n;
int n,ch; printf("\n average is %f",average);
printf("Enter the number:\n"); getch();
scanf("%d",&n); }
if(n%2==0)
ch=1; void main()
else {
ch=2; int x;
switch(ch) printf("enter a number");
{ scanf("%d",&x);
case 1: while(x<=100)
printf("number is even\n"); {
break; if(x<0)
case 2: {
printf("number is odd\n"); printf("enter nagative value for x");
} break;
} }
/*pocess for non negative number*/
/*Find the sum of the number*/ scanf("%d",&x);
#include<stdio.h> }
#include<conio.h> }
void main()
{ #include<stdio.h>
int num,count,sum,rem; void main()
clrscr(); {
sum=0; int i;
printf("Enter the number"); for(i=1;i<=5;i++)
scanf("%d",&num); stat();
for(count=num;count>0;count/=10) }
{ stat()
rem=count%10; {
sum+=rem; static int x=0;
} x=x+1;
printf("sum of digit=%d",sum); printf("x=%d\t",x);
getch(); }
}

/*progame to find average of a set of
numbers*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,count=0;
float x,average,sum=0;
clrscr();
printf("how many numbers");