SlideShare une entreprise Scribd logo
1  sur  11
LAB EXERCISE
R SARASWATHI
Ex:11 Bubble Sort
#include <stdio.h>
int main()
{
int array[100], n, c, d, swap;
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d integersn", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
for (c = 0 ; c < n - 1; c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1]) /* For decreasing order use '<' instead of '>' */
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
printf("Sorted list in ascending order:n");
for (c = 0; c < n; c++)
printf("%dn", array[c]);
return 0; }
OUTPUT
Enter number of elements
5
Enter 5 integers
6
3
2
1
5
Sorted list in ascending order:
1
2
3
5
6
Ex:12 Insertion Sort
include<stdio.h>
int main(){
int i, j, count, temp, number[25];
printf("How many numbers u are going to enter?: ");
scanf("%d",&count);
printf("Enter %d elements: ", count);
// This loop would store the input numbers in array
for(i=0;i<count;i++)
scanf("%d",&number[i]);
// Implementation of insertion sort algorithm
for(i=1;i<count;i++){
temp=number[i];
j=i-1;
while((temp<number[j])&&(j>=0)){
number[j+1]=number[j];
j=j-1;
}
number[j+1]=temp;
}
printf("Order of Sorted elements: ");
for(i=0;i<count;i++)
printf(" %d",number[i]);
return 0;
}
OUTPUT
How many numbers u are going to enter?: 5
Enter 5 elements: 2
1
3
9
8
Order of Sorted elements: 1 2 3 8 9
Ex:13 Students Mark statement
using structures
#include<stdio.h>
#include<string.h>
struct student
{
int sid;
char sname[10];
int tamil,eng,maths,science,social,tot;
float avg;
}s[10];
void main()
{
int i,n;
printf("nt Student Mark Register ");
printf("nt --------------------------------- ");
printf("n Enter the no.of Students : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("n Enter the Student Id :");
scanf("%d",&s[i].sid);
printf("n Enter the Name :");
scanf("%s",&s[i].sname);
printf("n Enter the MarksntTamiltEnglishttMathstSciencetSocialn");
scanf("n %d t %d t %d t %d t %d",&s[i].tamil,&s[i].eng,&s[i].maths,&s[i].science,&s[i].social);
s[i].tot=s[i].tamil+s[i].eng+s[i].maths+s[i].science+s[i].social;
s[i].avg=s[i].tot/5;
printf("ntSIDtSNametTAMILtENGLISHtMATHStSCINCEtSOCIAL SCIENCEtTOTALtAVERAGE ");
for(i=1;i<=n;i++)
{
printf("n t%d t %s t %d t %d t %d t %d t %d t %d t %f ",s[i].sid,s[i].sname,s[i].tamil,s[i].eng,s[i].maths,s[i].science,s[i].social,s[i].tot,s[i].avg);
}
getch();
}
}
OUTPUT
Student Mark Register
---------------------------------
Enter the no.of Students : 1
Enter the Student Id :1
Enter the Name :ABINAYA.S
Enter the Marks
Tamil English Maths Science Social
80 90 85 74 87
SID SName TAMIL ENGLISH MATHS SCINCE SOCIAL SCIENCE TOTAL AVERAGE
1 ABINAYA.S 80 90 85 74 87 416 83.000000
Ex: 14. Arithmetic operations on
pointers
#include <stdio.h>
int main()
{
int a=5,*x;
char b='z',*y;
x=&a;
printf("tttARITHMETIC OPERATIONn");
printf("INTEGER POINTER VARIABLE(*X): %dn",*x);
printf("ADDRESS OF A FROM VARIABLE(X) A: %dn",x);
x++;
printf("tttARITHMETIC OPERATION - POINTERn ADDRESS OF A AFTER INCREMENT X++:
%dn",x);
x--;
printf("ADDRESS OF A AFTER DECREMENT X-- %dn",x);
y=&b;
printf("CHARACTER POINTER VARIABLE(*Y): %dn",*y);
printf("ADRESS OF A VARIABLE(Y): %dn",y);
y++;
printf("tttARITHMETIC OPERATION - POINTERn ADDRESS OF A AFTER INCREMENT Y++:
%dn",y);
y--;
printf("ADDRESS OF A AFTER DECREMENT Y-- %dn",y);
return 0;
}
OUTPUT
ARITHMETIC OPERATION
INTEGER POINTER VARIABLE(*X): 5
ADDRESS OF A FROM VARIABLE(X) A: 1781813660
ARITHMETIC OPERATION - POINTER
ADDRESS OF A AFTER INCREMENT X++: 1781813664
ADDRESS OF A AFTER DECREMENT X-- 1781813660
CHARACTER POINTER VARIABLE(*Y): 122
ADRESS OF A VARIABLE(Y): 1781813659
ARITHMETIC OPERATION - POINTER
ADDRESS OF A AFTER INCREMENT Y++: 1781813660
ADDRESS OF A AFTER DECREMENT Y-- 1781813659
Ex:15 15. Creating/ Reading/
Writing a text/binary file
#include<stdio.h>
void main()
{
FILE *fp;
int scno,c,p,r,amount,i,n;
char name[20],filename[20];
printf("n INPUT FILE NAME n");
scanf("%s",filename);
fp=fopen(filename,"w");
printf("Input EB bill pay detailsnn");
printf("n Enter the number of members:");
scanf("%d",&n);
printf("n SCNO tNAME tCURt PREt n");
for(i=1;i<=n;i++)
{
fscanf(stdin,"n%d%s%d%d",&scno,name,&c,&p);
fprintf(fp,"n %d %s %d %d",scno,name,c,p);
}
fclose(fp);
fprintf(stdout,"nn");
fp=fopen(filename,"r");
printf("n SCNO tNAME tCUR tPRE tREA tAMOUNTn");
for(i=1;i<=n;i++)
{
fscanf(fp,"n %d %s %d %d n",&scno,&name,&c,&p);
r=c-p;
amount=r*3;
fprintf(stdout,"n %d t%s t%d t%dt %d t%d n",scno,name,c,p,r,amount);
}
fclose(fp);
getch();
OUTPUT
INPUT FILE NAME :
ebbill
Input EB bill pay details
Enter the number of members:2
SCNO NAME CUR PRE
1 ABINAYA 250 350
2 BALA 600 685
SCNO NAME CUR PRE REA AMOUNT
1 ABINAYA 250 350 -100 -300
2 BALA 600 685 -85 -255

Contenu connexe

Tendances

C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
vinay arora
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
vinay arora
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
vinay arora
 
C basics
C basicsC basics
C basics
MSc CST
 

Tendances (20)

C programming
C programmingC programming
C programming
 
Array
ArrayArray
Array
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 
C programms
C programmsC programms
C programms
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
 
1D Array
1D Array1D Array
1D Array
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
 
C basics
C basicsC basics
C basics
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
 
Lecture 1 string functions
Lecture 1  string functionsLecture 1  string functions
Lecture 1 string functions
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 

Similaire à LAB PROGRAMS SARASWATHI RAMALINGAM

Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er Ritu Aggarwal
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
SANTOSH RATH
 

Similaire à LAB PROGRAMS SARASWATHI RAMALINGAM (20)

All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
C programming BY Mazedur
C programming BY MazedurC programming BY Mazedur
C programming BY Mazedur
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Coding
CodingCoding
Coding
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Struct examples
Struct examplesStruct examples
Struct examples
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
5th Sem SS lab progs
5th Sem SS lab progs5th Sem SS lab progs
5th Sem SS lab progs
 
C questions
C questionsC questions
C questions
 
Cquestions
Cquestions Cquestions
Cquestions
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
C Language Lecture 17
C Language Lecture 17C Language Lecture 17
C Language Lecture 17
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 

Plus de SaraswathiRamalingam

Plus de SaraswathiRamalingam (20)

MACINTOSH
MACINTOSHMACINTOSH
MACINTOSH
 
XSL - XML STYLE SHEET
XSL - XML STYLE SHEETXSL - XML STYLE SHEET
XSL - XML STYLE SHEET
 
XML - SAX
XML - SAXXML - SAX
XML - SAX
 
DOM-XML
DOM-XMLDOM-XML
DOM-XML
 
X FILES
X FILESX FILES
X FILES
 
XML SCHEMAS
XML SCHEMASXML SCHEMAS
XML SCHEMAS
 
XML
XMLXML
XML
 
XML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITIONXML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITION
 
Georg scheutz - Charles babbage - Saraswathi Ramalingam
Georg scheutz - Charles babbage - Saraswathi RamalingamGeorg scheutz - Charles babbage - Saraswathi Ramalingam
Georg scheutz - Charles babbage - Saraswathi Ramalingam
 
Dennis ritchie - SARASWATHI RAMALINGAM
Dennis ritchie - SARASWATHI RAMALINGAMDennis ritchie - SARASWATHI RAMALINGAM
Dennis ritchie - SARASWATHI RAMALINGAM
 
Arithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingam
Arithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingamArithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingam
Arithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
C PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAMC PROGRAMS - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAM
 

Dernier

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 

LAB PROGRAMS SARASWATHI RAMALINGAM

  • 2. Ex:11 Bubble Sort #include <stdio.h> int main() { int array[100], n, c, d, swap; printf("Enter number of elementsn"); scanf("%d", &n); printf("Enter %d integersn", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); for (c = 0 ; c < n - 1; c++) { for (d = 0 ; d < n - c - 1; d++) { if (array[d] > array[d+1]) /* For decreasing order use '<' instead of '>' */ { swap = array[d]; array[d] = array[d+1]; array[d+1] = swap; } } } printf("Sorted list in ascending order:n"); for (c = 0; c < n; c++) printf("%dn", array[c]); return 0; }
  • 3. OUTPUT Enter number of elements 5 Enter 5 integers 6 3 2 1 5 Sorted list in ascending order: 1 2 3 5 6
  • 4. Ex:12 Insertion Sort include<stdio.h> int main(){ int i, j, count, temp, number[25]; printf("How many numbers u are going to enter?: "); scanf("%d",&count); printf("Enter %d elements: ", count); // This loop would store the input numbers in array for(i=0;i<count;i++) scanf("%d",&number[i]); // Implementation of insertion sort algorithm for(i=1;i<count;i++){ temp=number[i]; j=i-1; while((temp<number[j])&&(j>=0)){ number[j+1]=number[j]; j=j-1; } number[j+1]=temp; } printf("Order of Sorted elements: "); for(i=0;i<count;i++) printf(" %d",number[i]); return 0; }
  • 5. OUTPUT How many numbers u are going to enter?: 5 Enter 5 elements: 2 1 3 9 8 Order of Sorted elements: 1 2 3 8 9
  • 6. Ex:13 Students Mark statement using structures #include<stdio.h> #include<string.h> struct student { int sid; char sname[10]; int tamil,eng,maths,science,social,tot; float avg; }s[10]; void main() { int i,n; printf("nt Student Mark Register "); printf("nt --------------------------------- "); printf("n Enter the no.of Students : "); scanf("%d",&n); for(i=1;i<=n;i++) { printf("n Enter the Student Id :"); scanf("%d",&s[i].sid); printf("n Enter the Name :"); scanf("%s",&s[i].sname); printf("n Enter the MarksntTamiltEnglishttMathstSciencetSocialn"); scanf("n %d t %d t %d t %d t %d",&s[i].tamil,&s[i].eng,&s[i].maths,&s[i].science,&s[i].social); s[i].tot=s[i].tamil+s[i].eng+s[i].maths+s[i].science+s[i].social; s[i].avg=s[i].tot/5; printf("ntSIDtSNametTAMILtENGLISHtMATHStSCINCEtSOCIAL SCIENCEtTOTALtAVERAGE "); for(i=1;i<=n;i++) { printf("n t%d t %s t %d t %d t %d t %d t %d t %d t %f ",s[i].sid,s[i].sname,s[i].tamil,s[i].eng,s[i].maths,s[i].science,s[i].social,s[i].tot,s[i].avg); } getch(); } }
  • 7. OUTPUT Student Mark Register --------------------------------- Enter the no.of Students : 1 Enter the Student Id :1 Enter the Name :ABINAYA.S Enter the Marks Tamil English Maths Science Social 80 90 85 74 87 SID SName TAMIL ENGLISH MATHS SCINCE SOCIAL SCIENCE TOTAL AVERAGE 1 ABINAYA.S 80 90 85 74 87 416 83.000000
  • 8. Ex: 14. Arithmetic operations on pointers #include <stdio.h> int main() { int a=5,*x; char b='z',*y; x=&a; printf("tttARITHMETIC OPERATIONn"); printf("INTEGER POINTER VARIABLE(*X): %dn",*x); printf("ADDRESS OF A FROM VARIABLE(X) A: %dn",x); x++; printf("tttARITHMETIC OPERATION - POINTERn ADDRESS OF A AFTER INCREMENT X++: %dn",x); x--; printf("ADDRESS OF A AFTER DECREMENT X-- %dn",x); y=&b; printf("CHARACTER POINTER VARIABLE(*Y): %dn",*y); printf("ADRESS OF A VARIABLE(Y): %dn",y); y++; printf("tttARITHMETIC OPERATION - POINTERn ADDRESS OF A AFTER INCREMENT Y++: %dn",y); y--; printf("ADDRESS OF A AFTER DECREMENT Y-- %dn",y); return 0; }
  • 9. OUTPUT ARITHMETIC OPERATION INTEGER POINTER VARIABLE(*X): 5 ADDRESS OF A FROM VARIABLE(X) A: 1781813660 ARITHMETIC OPERATION - POINTER ADDRESS OF A AFTER INCREMENT X++: 1781813664 ADDRESS OF A AFTER DECREMENT X-- 1781813660 CHARACTER POINTER VARIABLE(*Y): 122 ADRESS OF A VARIABLE(Y): 1781813659 ARITHMETIC OPERATION - POINTER ADDRESS OF A AFTER INCREMENT Y++: 1781813660 ADDRESS OF A AFTER DECREMENT Y-- 1781813659
  • 10. Ex:15 15. Creating/ Reading/ Writing a text/binary file #include<stdio.h> void main() { FILE *fp; int scno,c,p,r,amount,i,n; char name[20],filename[20]; printf("n INPUT FILE NAME n"); scanf("%s",filename); fp=fopen(filename,"w"); printf("Input EB bill pay detailsnn"); printf("n Enter the number of members:"); scanf("%d",&n); printf("n SCNO tNAME tCURt PREt n"); for(i=1;i<=n;i++) { fscanf(stdin,"n%d%s%d%d",&scno,name,&c,&p); fprintf(fp,"n %d %s %d %d",scno,name,c,p); } fclose(fp); fprintf(stdout,"nn"); fp=fopen(filename,"r"); printf("n SCNO tNAME tCUR tPRE tREA tAMOUNTn"); for(i=1;i<=n;i++) { fscanf(fp,"n %d %s %d %d n",&scno,&name,&c,&p); r=c-p; amount=r*3; fprintf(stdout,"n %d t%s t%d t%dt %d t%d n",scno,name,c,p,r,amount); } fclose(fp); getch();
  • 11. OUTPUT INPUT FILE NAME : ebbill Input EB bill pay details Enter the number of members:2 SCNO NAME CUR PRE 1 ABINAYA 250 350 2 BALA 600 685 SCNO NAME CUR PRE REA AMOUNT 1 ABINAYA 250 350 -100 -300 2 BALA 600 685 -85 -255