ILLUSTRATE CALL BY REFERENCE:
/*To illustrate call by refrence */
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,swap(int *x,int *y);
clrscr();
printf ("\n\n Enter the first number : ");
scanf("%d",&x);
printf ("\n\n Enter the second number : ");
scanf("%d",&y);
printf("\n\n\n The value of x & y before swapping are %d & %d",x,y);
swap(&x,&y);
printf("\n\n The value of x & y after swapping are %d & %d",x,y);
getch();
}
void swap(int *x,int *y)
{
int t;
t = *x ;
*x = *y ;
*y = t ;
}
SWAPPING TWO POINTERS:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n=5,swap(int *ptr2,int *ptr4);
clrscr();
printf("\n\n Enter %d elements : \n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
swap(&a[2],&a[4]);
printf("\n\n The resultant matrix is : \n");
for(i=0;i<n;i++)
printf("a[%d] = %d\n",i,a[i]);
getch();
}
void swap(int *ptr2,int *ptr4)
{
int t;
t = *ptr2;
*ptr2 = *ptr4;
*ptr4 = t;
}
/*To illustrate call by refrence */
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,swap(int *x,int *y);
clrscr();
printf ("\n\n Enter the first number : ");
scanf("%d",&x);
printf ("\n\n Enter the second number : ");
scanf("%d",&y);
printf("\n\n\n The value of x & y before swapping are %d & %d",x,y);
swap(&x,&y);
printf("\n\n The value of x & y after swapping are %d & %d",x,y);
getch();
}
void swap(int *x,int *y)
{
int t;
t = *x ;
*x = *y ;
*y = t ;
}
SWAPPING TWO POINTERS:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n=5,swap(int *ptr2,int *ptr4);
clrscr();
printf("\n\n Enter %d elements : \n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
swap(&a[2],&a[4]);
printf("\n\n The resultant matrix is : \n");
for(i=0;i<n;i++)
printf("a[%d] = %d\n",i,a[i]);
getch();
}
void swap(int *ptr2,int *ptr4)
{
int t;
t = *ptr2;
*ptr2 = *ptr4;
*ptr4 = t;
}
ALPHABETIC SORT:
#include<stdio.h>
void main()
{
char t[100],string[100][100];
int i,j,numbers;
clrscr();
printf("\n\n How many numbers to be stored in array : ");
scanf("%d",&numbers);
if( (numbers < 0) || (numbers > 100) )
{
printf("\n\n Enter numbers to be stored in between 1 & 100");
printf("\n\n\n\n PRESS ANY KEY TO CONTINUE..............");
getch();
exit(0);
}
printf("\n Enter %d strings : \n ",numbers);
for(i=1 ; i <= numbers ; i++)
{
scanf("%s",string[i]);
}
for(i=1 ; i <= numbers-1 ; i++)
{
for(j=1 ; j <= numbers-i ; j++)
{
if ( strcmp( string[j] , string[j+1] ) > 0 )
{
strcpy(t , string[j]);
strcpy(string[j] , string[j+1]);
strcpy(string[j+1] , t);
}
}
}
printf("\n The sorted string in alphabetical order are : \n\n");
for(i=1 ; i <= numbers ; i++)
{
printf("%s \n", string[i]);
}
printf("\n\n\n PRESS ANY KEY TO CONTINUE........");
getch();
}
Comments
Post a Comment