SlideShare a Scribd company logo
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

More Related Content

DOCX
Data structure output 1
DOCX
ADA FILE
PPTX
4. chapter iii
PPTX
Session06 functions
PDF
Data Structure in C Programming Language
DOCX
C lab manaual
PPTX
3. chapter ii
Data structure output 1
ADA FILE
4. chapter iii
Session06 functions
Data Structure in C Programming Language
C lab manaual
3. chapter ii

What's hot (20)

PPTX
C programming
PPT
PDF
Data Structure using C
DOC
Basic c programs updated on 31.8.2020
DOCX
SaraPIC
DOCX
DataStructures notes
DOCX
Let us C (by yashvant Kanetkar) chapter 3 Solution
PDF
C Prog. - Strings (Updated)
PDF
C programms
PDF
Datastructures asignment
PDF
C Prog. - Structures
PDF
1D Array
PDF
LET US C (5th EDITION) CHAPTER 2 ANSWERS
PDF
Numerical analysis
PDF
C Prog - Strings
DOC
C basics
PDF
Simple C programs
PPTX
Lecture 1 string functions
DOCX
Solutionsfor co2 C Programs for data structures
C programming
Data Structure using C
Basic c programs updated on 31.8.2020
SaraPIC
DataStructures notes
Let us C (by yashvant Kanetkar) chapter 3 Solution
C Prog. - Strings (Updated)
C programms
Datastructures asignment
C Prog. - Structures
1D Array
LET US C (5th EDITION) CHAPTER 2 ANSWERS
Numerical analysis
C Prog - Strings
C basics
Simple C programs
Lecture 1 string functions
Solutionsfor co2 C Programs for data structures
Ad

Similar to LAB PROGRAMS SARASWATHI RAMALINGAM (20)

PPT
All important c programby makhan kumbhkar
PDF
VTU Data Structures Lab Manual
PPTX
C programming BY Mazedur
DOCX
PDF
PDF
Assignment on Numerical Method C Code
DOCX
Chapter 8 c solution
PPT
Struct examples
DOC
Daapracticals 111105084852-phpapp02
PPTX
L25-L26-Parameter passing techniques.pptx
PPTX
Introduction to Basic C programming 02
DOCX
Data structure new lab manual
DOC
5th Sem SS lab progs
PPT
C questions
PPT
Cquestions
PDF
C Programming lab
PDF
C Language Lecture 17
PPTX
C Programming Language Part 8
PDF
5 c control statements looping
DOCX
All important c programby makhan kumbhkar
VTU Data Structures Lab Manual
C programming BY Mazedur
Assignment on Numerical Method C Code
Chapter 8 c solution
Struct examples
Daapracticals 111105084852-phpapp02
L25-L26-Parameter passing techniques.pptx
Introduction to Basic C programming 02
Data structure new lab manual
5th Sem SS lab progs
C questions
Cquestions
C Programming lab
C Language Lecture 17
C Programming Language Part 8
5 c control statements looping
Ad

More from SaraswathiRamalingam (20)

PPTX
PPTX
XSL - XML STYLE SHEET
PPTX
PPTX
PPTX
XML DTD DOCUMENT TYPE DEFINITION
PPTX
Georg scheutz - Charles babbage - Saraswathi Ramalingam
PPTX
Dennis ritchie - SARASWATHI RAMALINGAM
PPTX
Arithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingam
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
C PROGRAMS - SARASWATHI RAMALINGAM
XSL - XML STYLE SHEET
XML DTD DOCUMENT TYPE DEFINITION
Georg scheutz - Charles babbage - Saraswathi Ramalingam
Dennis ritchie - SARASWATHI RAMALINGAM
Arithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingam
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAM

Recently uploaded (20)

PDF
Trump Administration's workforce development strategy
PDF
Empowerment Technology for Senior High School Guide
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PPTX
20th Century Theater, Methods, History.pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
My India Quiz Book_20210205121199924.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Indian roads congress 037 - 2012 Flexible pavement
PPTX
Computer Architecture Input Output Memory.pptx
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
IGGE1 Understanding the Self1234567891011
Trump Administration's workforce development strategy
Empowerment Technology for Senior High School Guide
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
20th Century Theater, Methods, History.pptx
What if we spent less time fighting change, and more time building what’s rig...
Virtual and Augmented Reality in Current Scenario
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Share_Module_2_Power_conflict_and_negotiation.pptx
AI-driven educational solutions for real-life interventions in the Philippine...
Weekly quiz Compilation Jan -July 25.pdf
My India Quiz Book_20210205121199924.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Indian roads congress 037 - 2012 Flexible pavement
Computer Architecture Input Output Memory.pptx
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
IGGE1 Understanding the Self1234567891011

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