Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 45

PROGRAM NO.

/* Program for Finding the Area of Circle */

#include<stdio.h> #include<conio.h> void main() { int r; float n,p=3.14; clrscr(); printf("\n\n\n\t\t***** Program for Finding the Area of Circle *****"); printf("\n\n\n\n\n\t\t\tEnter the Radius of Circle === "); scanf("%d", &r); n=p*r*r; printf("\n\n\n\t\t\t Area of Circle === %f ",n); getch(); }

OUTPUT :***** Program for Finding the Area of Circle ***** Enter the Radius of Circle === Area of Circle === 78.500000 5

PROGRAM NO. -

/* Program Of Find Greater Number Between Three Number */


#include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf("\n\n\n\t\tEnter The Three Number A, B & C === scanf("%d%d%d",&a,&b,&c); if( (a>b) && (a>c) ) { printf("\n\n\n\t\t\t A is Greater ==== %d ", a); } else if ( b>c ) { printf("\n\n\n\t\t\t B is Greater ==== %d ", b); } else printf("\n\n\n\t\t\t C is Greater ==== %d ", c); getch(); }

");

OUTPUT :-

Enter the Three Number A, B & C === B is Greater ==== 50

20 50 40

PROGRAM NO. -

/* Program to Create, Traverse, Insert and Deletion in an Array */


#include<stdio.h> #include<conio.h> main() { int a[25],choice,i,n,item,pos,pos1=0; do { clrscr(); printf("\n ******* ARRAY *******\n"); printf("\n 1.CREATE AN ARRAY"); printf("\n 2.TRAVERSE AN ARRAY"); printf("\n 3.INSERT AT A PARTICULAR POSITION"); printf("\n 4.DELETION OF AN ELEMENTL"); printf("\n 5.EXIT"); printf("\n ENTER YOUR CHOICE : "); scanf("%d",&choice); switch(choice) { /*Enter 1 to create array*/ case 1 : printf("\nENTER THE SIZE OF THE ARRAY : "); scanf("%d",&n); printf("\nENTER THE ARRAY : \n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); break; /*Enter 2 to print array*/ case 2 : printf("\nELEMENTS OF THE ARRAY ARE : \n"); for(i=1;i<=n;i++) printf("%d\n",a[i]); getch(); break; /*Enter 3 to insert at particular position*/ case 3 : printf("\nENTER THE POSITION WHERE YOU WANT TO INSERT : "); scanf("%d",&pos); printf("\nENTER THE NUMBER YOU WANT TO INSERT : ");

scanf("%d",&item); for(i=n;i>=pos;i--) a[i+1]=a[i]; a[pos]=item; n=n+1; if(pos>n) printf(YOU ENTER A WRONG POSITION); break; /*Enter 4 to delete an element of array*/ case 4 : printf("\nENTER THE NUMBER YOU WANT TO DELETE : "); scanf("%d",&item); for(i=1;i<=n;i++) { if(a[i]==item) { pos1=i; break; } } I if(pos1==0) { printf("\nTHE NUMBER YOU WANT TO DELETE IS NOT FOUND IN THE ARRAY"); } else { for(i=pos1+1;i<=n;i++) a[i-1]=a[i]; n=n-1; printf("\nNUMBER DELETE IS : %d",item); } getch(); break; /*Enter 5 to exit from program*/ case 5: exit(); default : printf("WRONG CHOICE"); } }while(choice!=5); return(0); }

OUTPUT:******* ARRAY ******* 1.CREATE AN ARRAY 2.TRAVERSE AN ARRAY 3.INSERT AT A PARTICULAR POSITION 4.DELETION OF AN ELEMENTL 5.EXIT ENTER YOUR CHOICE : 1 ENTER THE SIZE OF THE ARRAY : 4 ENTER THE ARRAY : 11 21 31 41 ******* ARRAY ******* 1.CREATE AN ARRAY 2.TRAVERSE AN ARRAY 3.INSERT AT A PARTICULAR POSITION 4.DELETION OF AN ELEMENTL 5.EXIT ENTER YOUR CHOICE : 2 ELEMENTS OF THE ARRAY ARE : 11 21 31 41 ******* ARRAY *******

1.CREATE AN ARRAY 2.TRAVERSE AN ARRAY 3.INSERT AT A PARTICULAR POSITION 4.DELETION OF AN ELEMENTL 5.EXIT ENTER YOUR CHOICE : 3 ENTER THE POSITION WHERE YOU WANT TO INSERT : 2 ENTER THE NUMBER YOU WANT TO INSERT : 5 ******* ARRAY ******* 1.CREATE AN ARRAY 2.TRAVERSE AN ARRAY 3.INSERT AT A PARTICULAR POSITION 4.DELETION OF AN ELEMENTL 5.EXIT ENTER YOUR CHOICE : 2 ELEMENTS OF THE ARRAY ARE : 11 5 21 31 41 ******* ARRAY ******* 1.CREATE AN ARRAY 2.TRAVERSE AN ARRAY 3.INSERT AT A PARTICULAR POSITION 4.DELETION OF AN ELEMENTL 5.EXIT ENTER YOUR CHOICE : 3

ENTER THE POSITION WHERE YOU WANT TO INSERT : 7 ENTER THE NUMBER YOU WANT TO INSERT : 27 YOU ENTER A WRONG POSITION ******* ARRAY ******* 1.CREATE AN ARRAY 2.TRAVERSE AN ARRAY 3.INSERT AT A PARTICULAR POSITION 4.DELETION OF AN ELEMENTL 5.EXIT ENTER YOUR CHOICE : 4 ENTER THE NUMBER YOU WANT TO DELETE : 5 NUMBER DELETE IS : 5

******* ARRAY ******* 1.CREATE AN ARRAY 2.TRAVERSE AN ARRAY 3.INSERT AT A PARTICULAR POSITION 4.DELETION OF AN ELEMENTL 5.EXIT ENTER YOUR CHOICE : 2 ELEMENTS OF THE ARRAY ARE : 11 21 31 41

******* ARRAY ******* 1.CREATE AN ARRAY 2.TRAVERSE AN ARRAY 3.INSERT AT A PARTICULAR POSITION 4.DELETION OF AN ELEMENTL 5.EXIT ENTER YOUR CHOICE : 5

PROGRAM NO. -

7 Subtraction,

/*Program of Matrix Operation's (Addition, Multiplication and Transpose) using a Switch Case */
#include<stdio.h> #include<conio.h> void add(); void sub(); void multi(); void tran(); void order(); void main() { int a[100][100],b[100][100],c[100][100]; int i,j,m,n,p,q,ch; clrscr();

printf("\n\n\n\n\n\n\n\t\t\t***** MATRIX OPERATION ******"); printf("\n\n\n\t\t\t 1. ADDITION"); printf("\n\n\t\t\t 2. SUBSTRACTION"); printf("\n\n\t\t\t 3. MULTIPLICATION"); printf("\n\n\t\t\t 4. TRANSPOSE\n\n\n"); printf("\n\n\t\t\tEnter Your Choice === scanf("%d",&ch); switch (ch) { ");

case 1 : { add(); break; } case 2 : { sub(); break; } case 3 : { multi(); break; }

case 4 : { order(); tran(); break; } default : { printf("\n\n\n\t\t\tChoice Not Exist Plese Try Again");

break; } } getch(); } void add() { int n,m,p,q,i,j,a[100][100],b[100][100],c[100][100]; clrscr(); printf("\n\n\n\n\t\t\t\t\t==== ADDITION ====\n\n\t"); printf("\n\n\t\t *** BOTH MATRIX ***" ); ROW AND COLOUMN MUST BE EQUAL OF ");

printf("\n\n\n\t\tEnter the Order of Matrix A (Row * Column) === scanf("%d%d",&m,&n); printf("\n\n\n\t\tEnter the Order of Matrix B (Row * Column) === scanf("%d%d",&p,&q); if((m==p) && (n==q)) { printf("\n\n\n\t\tEnter the Element of Matrix A === for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { scanf("%d",&a[i][j]); } ");

");

} printf("\n\n\n\t\tEnter the Element of Matrix B === for(i=1;i<=p;i++) { for(j=1;j<=q;j++) { scanf("%d",&b[i][j]); } } for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { c[i][j]=0; c[i][j]=c[i][j]+(a[i][j]+b[i][j]); } } printf("\n\n\n\t\t === After Addition Matrix C (%d * %d) ===",m,q); for(i=1;i<=m;i++) { printf("\n\n\n\n\t\t"); for(j=1;j<=n;j++) { printf("\t%d\t",c[i][j]); } ");

} }

else printf("\n\n\n\n\n\t\tOrder of Matrix A & B Don't Satisfied Conditions"); } void tran() { int a[100][100]; int i,j,m,n; printf("\n\n\n\n\t\t\t==== TRANSPOSE ====\n\n\t"); printf("\n\n\n\t\tEnter the Element of Matrix A === for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { scanf("%d",&a[i][j]); } } printf("\n\n\n\t\t\t ==== Original Matrix ==== \n\n"); for(i=1;i<=m;i++) { printf("\n\n\t\t\t\t"); for(j=1;j<=n;j++) { ");

printf("%d\t",a[i][j]); } } printf("\n\n\n\t==== Element after Transpose of Matrix A ( %d * %d ) === ", n,m); for(i=1;i<=n;i++) { printf("\n\n\t\t\t\t"); for(j=1;j<=m;j++) { printf("%d\t",a[j][i]); } } getch(); } void sub() { int n,m,p,q,i,j,a[100][100],b[100][100],c[100][100]; clrscr(); printf("\n\n\n\n\t\t\t\t==== SUBSTRACTION ====\n\n\t"); printf("\n\n\t\t *** BOTH MATRIX ***" ); ROW AND COLOUMN MUST BE EQUAL OF ");

printf("\n\n\n\t\tEnter the Order of Matrix A (Row * Column) === scanf("%d%d",&m,&n); printf("\n\n\n\t\tEnter the Order of Matrix B (Row * Column) ===

");

scanf("%d%d",&p,&q); if((m==p) && (n==q)) { printf("\n\n\n\t\tEnter the Element of Matrix A === for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { scanf("%d",&a[i][j]); } } printf("\n\n\n\t\tEnter the Element of Matrix B === for(i=1;i<=p;i++) { for(j=1;j<=q;j++) { scanf("%d",&b[i][j]); } } "); ");

for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { c[i][j]=0;

c[i][j]=c[i][j]+(a[i][j]-b[i][j]); } } printf("\n\n\n\t\t=== ===",m,q); for(i=1;i<=m;i++) { printf("\n\n\n\n\t\t"); for(j=1;j<=n;j++) { printf("\t%d\t",c[i][j]); } } } After Substraction Matrix C (%d * %d)

else printf("\n\n\n\n\n\t\tOrder of Matrix A & B Don't Satisfied Conditions"); }

void multi( ) { int n,m,p,q,i,j,a[100][100],b[100][100],c[100][100]; clrscr(); printf("\n\n\n\n\t\t\t==== MULTIPLICATION ====\n\n\t");

printf("\n\n\t\t *** 1st of COLOUMN and 2nd of RAW MUST BE EQUAL OF BOTH MATRIX ***" ); printf("\n\n\n\t\tEnter the Order of Matrix A (Row * Column) === scanf("%d%d",&m,&n); printf("\n\n\n\t\tEnter the Order of Matrix B (Row * Column) === scanf("%d%d",&p,&q); if(n==p) { printf("\n\n\n\t\tEnter the Element of Matrix A === for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { scanf("%d",&a[i][j]); } } printf("\n\n\n\t\tEnter the Element of Matrix B === for(i=1;i<=p;i++) { for(j=1;j<=q;j++) { scanf("%d",&b[i][j]); } } "); "); "); ");

for(i=1;i<=m;i++) { for(j=1;j<=q;j++) { c[i][j]=0; c[i][j]=c[i][j]+(a[i][j]*b[i][j]); } } printf("\n\n\n\t\tAfter Multiplication Matrix C (%d * %d) ===",m,q); for(i=1;i<=m;i++) { printf("\n\n\n\n\t\t"); for(j=1;j<=q;j++) { printf("\t%d\t",c[i][j]); } } } else printf("\n\n\n\n\n\t\tOrder of Matrix A & B Don't Satisfied Conditions"); } void order() { int m,n; clrscr();

printf("\n\n\n\t\tEnter the Order of Matrix A (Row * Column) === scanf("%d%d",&m,&n); }

");

OUTPUT :***** MATRIX OPERATION ****** 1. 2. 3. 4. ADDITION SUBSTRACTION MULTIPLICATION TRANSPOSE 1

Enter Your Choice === ==== ADDITION ==== *** MATRIX ***

ROW AND COLOUMN MUST BE EQUAL OF BOTH 23 23

Enter the Order of Matrix A (Row * Column) === Enter the Order of Matrix B (Row * Column) === Enter the Element of Matrix A === Enter the Element of Matrix B === 123456 222222

=== After Addtion Matrix C (2 * 3) === 3 6 4 7 5 8

***** MATRIX OPERATION ****** 1. 2. 3. 4. ADDITION SUBSTRACTION MULTIPLICATION TRANSPOSE

Enter Your Choice ===

==== SUBSTRACTION ==== *** MATRIX *** Enter the Order of Matrix A (Row * Column) === Enter the Order of Matrix B (Row * Column) === Enter the Element of Matrix A === Enter the Element of Matrix B === 10 10 20 20 5555 22 22 ROW AND COLOUMN MUST BE EQUAL OF BOTH

=== After Substraction Matrix C (2 * 2) === 5 15 5 15

***** MATRIX OPERATION ****** 1. 2. 3. 4. ADDITION

SUBSTRACTION MULTIPLICATION TRANSPOSE 3

Enter Your Choice ===

==== MULTIPLICATION ==== *** 1st of COLOUMN and 2nd of RAW MUST BE EQUAL OF BOTH MATRIX *** Enter the Order of Matrix A (Row * Column) === Enter the Order of Matrix B (Row * Column) === Enter the Element of Matrix A === Enter the Element of Matrix B === 123456 10 10 10 10 10 10 23 32

After Multiplication Matrix C (2 * 2) === 10 40 20 50

***** MATRIX OPERATION ****** 1. ADDITION 2. 3. 4. SUBSTRACTION MULTIPLICATION TRANSPOSE 4

Enter Your Choice ===

==== TRANSPOSE ==== Enter the Order of Matrix A (Row * Column) === Enter the Element of Matrix A === 33

123456789

==== Original Matrix ==== 1 2 4 7 3 5 8 6 9

==== Element after Transpos of Matrix A ( 3 * 3 ) === 1 2 3 4 5 6 7 8 9

PROGRAM NO. - 8 /*Program for Implementation of stack operation (PUSH & POP) */
#include<stdio.h> #include<conio.h> void push(); void pop(); void main() { int ch; int stk[100],i,top,ele,item; clrscr(); printf("\n\n\n\t\t\t *** Main Menu ***\n\n"); printf("\n\n\n\t\t\t 1. PUSH OPERATION"); printf("\n\n\n\t\t\t 2. POP OPERATION"); printf("\n\n\n\t\t\t Enter Your Choice :- "); scanf("%d",&ch); switch(ch) { case 1 : { push(); break; } case 2 : { pop(); break; } default: { printf("\n\n\n\t\t\t Wrong Choice Pls Try Again"); } } getch(); } void push() {

int stk[100],i,top,ele,item; clrscr(); printf("\n\n\t\tEnter The number of element Push On Stack :- "); scanf("%d",&top); printf("\n\n\t\tEnter the Element of Stack :- "); for(i=1;i<=top;i++) { scanf("%d",&stk[i]); } printf("\n\n\t\t*** Stack Before Push Operation *** \n\n\n\t\tTOP \n\n\t"); for(i=top;i>=1;i--) { printf("\t%d",stk[i]); } printf("\n\n\n\t\tEnter the Element to be insert in TOP of Stack :- "); scanf("%d",&item); if (top==100) { printf("\n\n\t\t 'STACK IS OVERFLOW' "); } else { top++; stk[top]=item; } printf("\n\n\t\t*** Stack after Push Operation *** \n\n\n\t\t TOP \n\n\t"); for(i=top;i>=1;i--) { printf("\t%d",stk[i]); } getch(); } void pop() { int stk[100],i,top,ele,item; clrscr();

printf("\n\n\t\tEnter The number of element Push On Stack :- "); scanf("%d",&top); printf("\n\n\t\tEnter the Element of Stack :- "); for(i=1;i<=top;i++) { scanf("%d",&stk[i]); } printf("\n\n\t\t*** Stack Before Pop Operation *** \n\n\n\t\t TOP \n\n\t"); for(i=top;i>=1;i--) { printf("\t%d",stk[i]); } if (top==0) { printf("\n\n\t\t 'STACK IS UNDERFLOW' "); } else { item=stk[top]; top--; } printf("\n\n\t\t*** Stack after Pop Operation *** \n\n\n\t\t TOP \n\n\t"); for(i=top;i>=1;i--) { printf("\t%d",stk[i]); } getch(); }

OUTPUT :*** Main Menu ***

1. PUSH OPERATION 2. POP OPERATION Enter Your Choice :1

Enter The number of element Push On Stack :Enter the Element of Stack :12345

*** Stack Before Push Operation *** TOP 5 4 3 2 1

Enter the Element to be insert in TOP of Stack :- 6 *** Stack after Push Operation *** TOP 6 5 4 3 2 1

*** Main Menu *** 1. PUSH OPERATION 2. POP OPERATION Enter Your Choice :2

Enter The number of element Push On Stack :Enter the Element of Stack :12345

*** Stack Before Pop Operation *** TOP

*** Stack after Pop Operation *** TOP 4 3 2 1

PROGRAM NO. - 9 /* Program for Implementation of Queue operation in Array ( INSERTION & DELETION ) */
#include<stdio.h> #include<conio.h> #include<process.h> void ins(); void del(); void main() { int ch; clrscr(); printf("\n\n\n\t\t\t *** Main Menu ***\n\n"); printf("\n\n\n\t\t\t 1. Insertion in Queue "); printf("\n\n\n\t\t\t 2. Deletion in Queue"); printf("\n\n\n\t\t\t 3. EXIT"); printf("\n\n\n\t\t\t Enter Your Choice :scanf("%d",&ch); switch(ch) { case 1 : { ins(); ");

break; } case 2 : { del(); break; } case 3 : { exit(0); break; } default: { printf("\n\n\n\t\t\t Wrong Choice Pls Try Again"); } } getch(); } void ins() { int que[50],i,n,cl,front,rear,item,null=0; clrscr();

printf("\n\n\n\t\tEnter the size of Queue :scanf("%d",&n); cl=n; if(n == cl && n != 0) { front=1; rear=n;

");

printf("\n\n\n\t\tEnter the element of Queue :for(i=1;i<=n;i++) { scanf("%d",&que[i]); } } else if (n==0) { front=null; rear=null;

");

printf("\n\n\n\t\tQueue is a Empty then insert on 1st Position "); } if( front==1 && rear== 50 ) { printf("\n\n\n\t\tOVERFLOW"); }

if ( front=null ) { front=1; rear=1; } else if ( rear == n ) { rear=rear+1; } else if ( rear == n && front != 1 ) { rear=1; } printf("\n\n\n\t\tEnter the element to be insert in a Queue :scanf("%d",&item); que[rear]=item; printf("\n\n\n\t\tAfter Insertion in a Queue \n\n\n\t "); printf("FRONT [ "); for(i=1;i<=rear;i++) { printf("\t%d",que[i]); ");

printf(" ] REAR"); getch();

void del() { int que[50],i,n,j,cl,front,rear,item,null=0; clrscr(); printf("\n\n\n\t\tEnter the size of Queue :scanf("%d",&n); cl=n; if(n == cl && n != 0) { front=1; rear=n; printf("\n\n\n\t\tEnter the element of Queue :for(i=1;i<=n;i++) { scanf("%d",&que[i]); } } else if (n==0) "); ");

{ front=null; rear=null; printf("\n\n\n\t\t\tUNDERFLOW"); printf("\n\n\n\t\tQueue is a Empty List then Element not Deleted "); } item=que[front]; if ( rear == front ) { front=null; rear=null; } else if ( front == n ) { front=1; } else { front=front+1; } j=front; if( front != 0 ) {

printf("\n\n\n\t\tAfter Deletetion in a Queue \n\n\n\t "); printf("FRONT [ "); for(i=j;i<=rear;i++) { printf("\t%d",que[i]); } printf(" ] } } REAR");

OUTPUT :*** Main Menu *** 1. Insertion in Queue 2. Deletion in Queue 3. EXIT Enter Your Choice :1

Enter the size of Queue :-

5 12345 10

Enter the element of Queue :-

Enter the element to be insert in a Queue :-

After Insertion in a Queue FRONT [ 1 2 3 4 5 10 ] REAR

Enter the size of Queue :-

Queue is a Empty then insert on 1st Position Enter the element to be insert in a Queue :After Insertion in a Queue FRONT [ 10 ] REAR 10

*** Main Menu *** 1. Insertion in Queue 2. Deletion in Queue 3. EXIT Enter Your Choice :2

Enter the size of Queue :-

5 12345

Enter the element of Queue :-

After Deletetion in a Queue FRONT [ 2 3 4 5 ] REAR

Enter the size of Queue :UNDERFLOW

Queue is a Empty List then Element not Deleted

PROGRAM NO. - 10 /* Program for Implementation of Pointer ( Call by Value & Call by Reference )*/
#include<stdio.h> #include<conio.h> #include<process.h> void cbv(); void cbr(); void swapref(int *,int *); int swap(int,int); void main() { int ch; clrscr(); printf("\n\n\n\t\t\t *** Main Menu ***\n\n"); printf("\n\n\n\t\t\t 1. CALL BY VALUE "); printf("\n\n\n\t\t\t 2. CALL BY REFERENCE"); printf("\n\n\n\t\t\t 3. EXIT"); printf("\n\n\n\t\t\t Enter Your Choice :scanf("%d",&ch); switch(ch) { ");

case 1 : { cbv(); break; } case 2 : { cbr(); break; } case 3 : { exit(0); break; } default: { printf("\n\n\n\t\t\t Wrong Choice Pls Try Again"); } } getch(); } void cbr()

{ int a,b,c; clrscr(); printf("\n\n\n\t\tEnter the values of A & B :scanf("%d%d",&a,&b); printf("\n\n\n\t\tOriginal Values of A & B \n\n"); ");

printf("\n\n\n\t\tA = %d\t\tB = %d\n\n", a,b ); swapref(&a,&b); printf("\n\n\n\t\tAfter Swaping Values of A & B : printf("\n\n\n\t\tA = %d\t\tB = %d", a,b ); getch(); } void swapref(int * x ,int * y) { int temp; temp=*x; *x=*y; *y=temp; \n\n");

} void cbv() { int a=10,b=20,c;

clrscr(); printf("\n\n\n\t\tOriginal Values of A & B \n\n");

printf("\n\n\n\t\tA = %d\t\tB = %d\n\n", a,b ); c=swap(a,b); getch(); } int swap(int p,int q) { int x=10,y=20,temp; temp=x; x=y; y=temp; printf("\n\n\n\t\tAfter Swaping Values of A & B : printf("\n\n\n\t\tA = %d\t\tB = %d", x,y ); return(0); } \n\n");

OUTPUT :*** Main Menu ***

1. CALL BY VALUE 2. CALL BY REFERENCE 3. EXIT Enter Your Choice :Original Values of A & B A = 10 B = 20 1

After Swaping Values of A & B : A = 20 B = 10

*** Main Menu *** 1. CALL BY VALUE 2. CALL BY REFERENCE 3. EXIT Enter Your Choice :2

Enter the values of A & B :-

100 200

Original Values of A & B A = 100 B = 20

After Swaping Values of A & B : A = 200 B = 100

PROGRAM NO. 11 /* Program to Perform Various String Operation using user defined function */
#include<stdio.h> #include<conio.h> #include<string.h> int udstrlen (char *s); void udstrcpy (char *t, char *s); void udstrcat (char *t, char *s); int udstrcmp (char *s1, char *s2); void main() { char s1[10]; char s2[10]; char s3[10]; char s4[20]; int len1,len2; clrscr(); printf("Enter the first string:\t"); /* ENTER THE FIRST STRING*/ scanf(" %s",s1); printf("Enter the 2nd string:\t"); /* ENTER THE SECOND STRING*/ scanf(" %s",s2); len1 = udstrlen(s1); /* CACLULATE THE LENGHT */ len2 = udstrlen(s2); printf("\n\n string s1: %s", s1); printf("\n\n string s2: %s", s2); printf("\n\n lenth of string s1: %d",len1); printf("\n\n lenth of string s2: %d",len2); udstrcpy(s3,s1); /* STRING COPY */ printf("\n\n string s3 after copying s1 to it: %s",s3);

udstrcpy(s4,s1); udstrcat(s4,s2); /* CONCATENATE THE STRING */ printf("\n\n string s4 after cancatination : %s",s4); if(udstrcmp(s1,s2)==0) /* COMPARE THE STRING */ { printf("\n\n strings are same"); } else { printf("\n\n strings are not same"); } getch(); } int udstrlen (char *s) { int len=0; while (*s != '\0') { len++; s++; } return (len); } void udstrcpy (char *t, char *s) { while (*s != '\0') { *t=*s; s++; t++; } *t='\0'; }

void udstrcat (char *s1, char *s2) { while (*s1 != '\0') { s1++; } while (*s2 != '\0') { *s1=*s2; s1++; s2++; } *s1= '\0'; } int udstrcmp (char *s1, char *s2) { while (*s1 != '\0' || *s2 != '\0') { if ((*s1-*s2) == 0) { s1++; s2++; } else { return(*s1-*s2); } } return(0);

OUTPUT:Enter the first string: SHAMAN Enter the 2nd string: AGGARWAL

string s1: SHAMAN string s2: AGGARWAL lenth of string s1: 6 lenth of string s2: 8 string s3 after copying s1 to it: SHAMAN string s4 after cancatination : SHAMANAGGARWAL strings are not same

You might also like