c language is structured programming language
TRANSCRIPT
-
8/8/2019 C Language is Structured Programming Language
1/19
Structured programmer language C
C language is structured programming language. Its a case sensitive language before
it was called as B, Basic Compiled Programming language. In this language we are using
compiler to execute. The complier name is TC (turbo C).
Parts of the program In C language
1. declarations2. input statements3. Arithmetic and logical works4. Output statementsFunctions
Header file Library File
Standard input output , header file (
stdio.h
( conioh ( console input , output) Get CH
It helps to execute
Graphic .h
void main()
Void main ()
{
Variable Declaration
Input
Calculation
Output
}
Functions
{
}
{} set brackets
[] square bracket
Main c
Note: single has comment //
Main C
(file Name )
Compiler
Main.obj
Main.bak
Main.exe
Main.C ( souce
-
8/8/2019 C Language is Structured Programming Language
2/19
-
8/8/2019 C Language is Structured Programming Language
3/19
Structured programmer language C
Clrscr ();
Printf (enter the integer value \n);
Scanf (%d, &a);
Printf (the given integer value is %d,a);
Getch ();
}
Write a C program to read a float value and display?
#include
#include
Void main()
{
Float a;
Clrscrn();
Printf(float value \n);
Scanf(%f,&a);
Printf(the given float is %f,a);
Getch();
}
Error names: statement missingIt to programmer, there was a mistaken from the previous line that is , we miss
the semi colon from the previous line .
Undefined symbols: the compiler does not understand your variable names in the
program. All the variables must be declared before it has used. Sometimes we
use Printf instead of printf
Unable to open OBJ file, linker, library, output directory path was not set
properly
//program for float value and fixed ()
#include
#includeVoid main ()
{
Float a1,a2,a3;
Clrsrn
Prinf(enter the decimal vale\n);
Scanf(%f%f,&a1,&a2);
A3+a1+a2;
Peintf(the amount of %.2f,a3)
Getch()
}
Read the employee salary, traveling allowance and medical allowance
//progarme for employee salry ()#include
#include
Void main ()
{
Float e,t,m;
Clrsrn
Prinf(enter the decimal vale\n);
Scanf(%f%f%f,&e,&t,&m);
-
8/8/2019 C Language is Structured Programming Language
4/19
Structured programmer language C
A1= e+t+m;
Peintf(the amount of %.2fa1,)
Getch()
String :
//read a string and display ()
#include
#include
Void main ()
{
Char x[20];
Clrscr();
Printf(enter the string\n);
Scanf(%s,&x);
Printf(\n the given string is %s,x);
Getch;
}
Wrte a progarme fro emplee id , name , address, salary and
do the following calculationTA( traveling allowance ) salary *7 /100
Ma ( medical allowance ) sa;ry *9/100
Hra salary +10/100
Fa( food allawnace ) salry * 11/100
Loan =salry *1/100
Gross =salry +ta+ma+hra+fa
Net=gross-loan
//progarme for employee salry ()
#include#include
Void main ()
{
Int a; //emplee id
Char x[20],y[20]
Float b,ta,ma,hra,fa,oan,gross,net;
Clrscr();
Printf( \n enter the emplee id);
Scanf(\n %d,&a)
Printf( \n enter the name);
Scanf(\n %s,&x)
Printf( \n enter the address);
Scanf(\n %s,&y)Printf( \n enter the salary);
Scanf(\n %f,&b)
Ta=b*7/100
Ma=b*9/100
Hra=b*10/100
Fa=b*11/100
Loan=b*1/100
Gross=b+ta+ma+hra+fa
-
8/8/2019 C Language is Structured Programming Language
5/19
Structured programmer language C
Net=gross-loan
Printf( \n the amount of ta %f,ta);
Printf( \n the amount of ma %f,ma);
Printf( \n the amount of hra %f,hra);
Printf( \n the amount of fa %f,fa);
Printf( \n the amount of loan %f,loan);
Printf( \n the amount of gross %f,gross);
Printf( \n the amount of net %f,net);
Getch();
}
Write a progarme fro simple interest and display
it?SI =PRN
/* this is my thired programe
date 04/04/2010*/
//#include /headerfile//#include
void main()
{
float si,p,r,n;
clrscr();
printf("\n enter the principle amount");
scanf("\n %f",&p);
printf("\n enter the rate of interest");
scanf("\n%f",&r);
printf("\n enter the number of years");
scanf("\n%f",&n);
si=p*r*n/100;
printf("\n simple amount is %.2f",si);
getch();
}
Write A C PROGARME TO READ A DOLLEER VALUE AND CONVERTION INTO THE RUFIYAA
VALUE
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Incremnet and decremenets
These methods are used when in looping
Incremnet = post incerment and pre incremnet
Decermenet = post decrement and pre decremenet
Pre incremnet : ++IThe value of the varibele I is inceremeneted by one , then it will used by
another varibles .
Exmaple x = 100
-
8/8/2019 C Language is Structured Programming Language
6/19
Structured programmer language C
A =++x
In this case the value of the varible x is incremnetd from 100 to 101 then
its been asssign to a
Post increment : I++The value of the varible I is assgin to another varible first then it will be
incremneted by oneExample
X=100
A=X++
out put is A =100
X =101
Because x is assgin frist , aftre assgning it been incremneted
/* this is 5th programe
date 20/04/2010*/
//#include /headerfile
//#includevoid main()
{Int x, y;
Clrscr;
X=100,
Y=++x
Printf(value of x is %d\n,x),
Prinf( the value of y is %d\n,y),
getch();
}
-----------------------------------------------------------------------------/* this is 6th programe
date 20/04/2010*/
//#include /headerfile
//#include
void main()
{Int x, y;
Clrscr;
X=100,
Y=x--
Printf(value of x is %d\n,x),
Prinf( the value of y is %d\n,y),
getch();
}
----------------------------------------------------------------------------
/* this is 7th programe
date 20/04/2010*/
//#include /headerfile
//#include
void main()
{
-
8/8/2019 C Language is Structured Programming Language
7/19
Structured programmer language C
Int x;
Float b;
Char c;
Clrscr;
Printf(enter the value of interger %d\n,x);
scanf(%d,&a);
printf(vaue of x is float\n,x);
scanf(%f,&b,b);
printf(value of x is charcater\n,x);
scanf( %c,&c);
printf (values are fllows)
printf(%d\t%f\t%c)
getch();
}
Diffrence between character and string
charcterconstant String constantChar optionOption-y;Char symbolesSymbles=#
----------------------------------------------------------------------------
/* this is 8th programe
date 25/04/2010*/
#include /headerfile
#include
void main()
{Int year , reminder;
Clrscr();
Printf(enter the year\n);
Scanf (%d,&year):
Reminder=year%4;
IF(reminder==0)
Printf(year %d is leap year,year);
Else
Printf(year %d is not a leap year,year);
-
8/8/2019 C Language is Structured Programming Language
8/19
Structured programmer language C
Getch();
}
----------------------------------------------------------------------------
/* this is 9th programedate 25/04/2010*/
#include /headerfile
#include
void main()
{Int m1,m2,m3,m4,total
Float arg;
Char name[20] *grade{10},
Clrscrn;
Printf( \n enter the name:\t);
Scanf( %s,&name);
Printf()
Switch case
Its a multi branching control statement
General format
Switch(condition)
{
Case value:
-----------------------------------------------------------------------------------\--
-------------------------------------------------------------------------------------
Break;
Case value2:
Break;
Case value3:
-
8/8/2019 C Language is Structured Programming Language
9/19
Structured programmer language C
Break;
Default:
Break;
In switch case there many available cases. In case consider as branch. The switch
condition has to be evaluated at first.
The switch condition value compare with case values. Which case value is match with
switch condition value that specific case will be executed
If there is no match found the control will go to default branch.
Note: every case have break statement. When the control comes to break statement, the
switch case will be terminated
Ex: char value;
Value =a,
Switch(value)
{
Casea
Printf(the letter a aplhepet a);
Break;
Casee
Printf(the letter is alpaheebt e);
Break;
Default:
Printf(no value match);
-
8/8/2019 C Language is Structured Programming Language
10/19
Structured programmer language C
Break;
#include
#inculde
void main()
{
char option;
clrscr();
printf("enter a letter \n");
scanf(" %c",&option);
printf("the given letter is %c \n",option);
switch(option)
{
case'a':
case'A':
case'e':
case'E':
case'i':
case'I':
case'o':
case'O':
case'u':
case'U':
printf("the letter is a vowel");
break;
default;
printf("this is not a vowel");
}
getch();
}
-
8/8/2019 C Language is Structured Programming Language
11/19
Structured programmer language C
#include
#inculde
void main()
{
int a,b,c,option
clrscr();
printf("\n\t\t menu\n\n");
printf("\t\t 1.....add\n");
printf("\t\t 2.....sub\n");
printf("\t\t 3.....mulit\n");
printf("\t\t 4.....division\n");
printf("\t\t 5.....close\n");
printf("\n select your choice\t");
scanf("%d,&option");
printf("enter two number\n");
scanf("%d%d",&a,&b);
switch(option)
{
case1:
c=a+b;
break;
case2:
c=a-b;
break;
case3:
c=a*b;
break;
case4:
if (b==0||b,0)
-
8/8/2019 C Language is Structured Programming Language
12/19
Structured programmer language C
printf("deiviosn not possible");
if(b.0)
c=a/b;
default:
printf("select proper option\n");
break;
}
print("result is %d",c)
getch();
}
Itrative statement
1. Do loop2.While loop3. For loop
Part of Itertive statement
a. Intailizeb. Incerment/decrementsc. Condition
Do loop
General format
Initail Value
Do
{
Incremnet or dercremnet
}
While (lgigal condition)
-
8/8/2019 C Language is Structured Programming Language
13/19
Structured programmer language C
EXCESIE 1
N=1;
Do
{
Printf{welcome};
N=n+1;
}
While (n
-
8/8/2019 C Language is Structured Programming Language
14/19
Structured programmer language C
{
printf("my name is %s\n"*name);
i=i+1;
}
while(i
-
8/8/2019 C Language is Structured Programming Language
15/19
Structured programmer language C
Write a c-progarme to display your name in n using for loop
#include
#include
void main()
{
int n,i,total,a[100];
clrscr();
printf("how many time you wnat to entrer");
scanf("%d",&n);
printf("enter the number one by one\n");
for(i=0;i
-
8/8/2019 C Language is Structured Programming Language
16/19
Structured programmer language C
2.Array=> many data stored at one variable3.Structure =>different type as data (disimialr type of data)
can store in one variable name
How gto declare
General format
Struct structure name
{
Int id
Float salary
Char // these are structure number
};
Struct structure name variable name;
File concept
How to declare
1.Declare the file pointer variablesFILE *FP
Data type file pointer
2.The text file should be opned using file pointer and filemode( file mode means to write and read purpose)
There are three file mode
Write : it
Read: it just read
Append
File =fopen( ab1.txt, w+)
-
8/8/2019 C Language is Structured Programming Language
17/19
Structured programmer language C
#include
#include
void main()
{
struct student
{
int id;
float m1,mt,m3,tot;
char name[20];
struct student s;
file *fp;
int recsize;char option;
clrscr;
fp=fopen(stud.txt,w+);
recsize=sizeof(s);
do
{
Clrscr
Printf(enter the id \t);scanf(%d,&s.id);
Fwrite(&s,recsize,1,fp);
Printf(do u want to add another recosrd);
Sacnf(%c,&option
}
-
8/8/2019 C Language is Structured Programming Language
18/19
Structured programmer language C
While ( option==y);
Getch()
}
String fuction
Its is a collection of Alpha and neumericals and symbols
How to declare string variable
Char varibelname [size];
Example char a [100];
a= the variable
100= the size of variable
The format specifer for string is %s
#include
Strlen(string);
-
8/8/2019 C Language is Structured Programming Language
19/19
Structured programmer language C