venice
06-26-04, 11:26 AM
//display the ascending and descending value
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define size 10
void asc(int*);
void dec(int*);
void swap(int*,int*);
void main(void)
{
int input[size],a;
int *ascend,*descend,x,y,m;
char dbuffer [9];
char tbuffer [9];
ascend=(int*)calloc(10,sizeof(int));
descend=(int*)calloc(10,sizeof(int));
_strdate( dbuffer );
printf( "The current date is %s \n", dbuffer );
_strtime( tbuffer );
printf( "The current time is %s \n", tbuffer );
printf("\n");
printf("Press 1 to enter or 0 to exit --->");
scanf("%d",&y);
do{
if(y==1)
{
printf("\t\t\tLoading");
for(x=0;x<6;x++)
{
_sleep(300);
printf(".");
}
system("cls");
}
else if(y==0){
system("cls");
printf("\n\t\t\tThanks for using this system!!\n\n\t\t\tHAVE A NICE DAY!!\n\n\n");
return;
}
else
{
system("cls");
printf("\n\t\t\tWrong entry!!\n\n\t\t\tPlease enter again!!\n\n\n");
return;
}
_strdate( dbuffer );
printf( "The current date is %s \n", dbuffer );
_strtime( tbuffer );
printf( "The current time is %s \n", tbuffer );
printf("\n");
printf("\n\t\t=====================================\n");
printf("\n\t\t\t WELCOME TO OUR\n\n\t\t\tCALCULATING SYSTEM!!\n");
printf("\n\t\t=====================================\n\n");
for(a=0;a<size;a++)
{
printf("\t\t Please key in value no.%d>",a+1);
scanf("%d",&input[a]);
*(ascend+a)=input[a];
*(descend+a)=input[a];
}
printf("\n\n");
printf("\t\tProcessing");
for(x=0;x<6;x++)
{
_sleep(200);
printf(".");
}
system("cls");
_strdate( dbuffer );
printf( "The current date is %s \n", dbuffer );
_strtime( tbuffer );
printf( "The current time is %s \n", tbuffer );
asc(ascend);
dec(descend);
printf("\n\n\t ================================================\n");
printf("\n\t\t\tRESULT AS SHOWN AS BELOW\n");
printf("\n\t ================================================\n");
printf("\t\tAscending\tOriginal\tDescending\n");
for(a=0;a<size;a++)
{
printf("\t\t%d\t\t%d\t\t%d\n",*(ascend+a),input[a],*(descend+((size-1)-a)));
}
printf("\n\n\n\t");
free(ascend);
free(descend);
printf("Press 2 to go to new calculation or any keys to exit>");
scanf("%d",&m);
}while(m==2);
system("cls");
printf("\n\t\t\tThanks for using this system!!\n\n\t\t\tHAVE A NICE DAY!!\n\n\n");
}
void asc(int *ascend)
{
int i,j,smallest;
for(i=0;i<size-1;i++)
{
smallest=i;
for(j=i+1;j<size;j++)
if(ascend[j]<ascend[smallest])
smallest=j;
swap(ascend+i,ascend+smallest);
}
}
void dec(int *descend)
{
int i,j,smallest;
for(i=0;i<size-1;i++)
{
smallest=i;
for(j=i+1;j<size;j++)
if(descend[j]<descend[smallest])
smallest=j;
swap(descend+i,descend+smallest);
}
}
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define size 10
void asc(int*);
void dec(int*);
void swap(int*,int*);
void main(void)
{
int input[size],a;
int *ascend,*descend,x,y,m;
char dbuffer [9];
char tbuffer [9];
ascend=(int*)calloc(10,sizeof(int));
descend=(int*)calloc(10,sizeof(int));
_strdate( dbuffer );
printf( "The current date is %s \n", dbuffer );
_strtime( tbuffer );
printf( "The current time is %s \n", tbuffer );
printf("\n");
printf("Press 1 to enter or 0 to exit --->");
scanf("%d",&y);
do{
if(y==1)
{
printf("\t\t\tLoading");
for(x=0;x<6;x++)
{
_sleep(300);
printf(".");
}
system("cls");
}
else if(y==0){
system("cls");
printf("\n\t\t\tThanks for using this system!!\n\n\t\t\tHAVE A NICE DAY!!\n\n\n");
return;
}
else
{
system("cls");
printf("\n\t\t\tWrong entry!!\n\n\t\t\tPlease enter again!!\n\n\n");
return;
}
_strdate( dbuffer );
printf( "The current date is %s \n", dbuffer );
_strtime( tbuffer );
printf( "The current time is %s \n", tbuffer );
printf("\n");
printf("\n\t\t=====================================\n");
printf("\n\t\t\t WELCOME TO OUR\n\n\t\t\tCALCULATING SYSTEM!!\n");
printf("\n\t\t=====================================\n\n");
for(a=0;a<size;a++)
{
printf("\t\t Please key in value no.%d>",a+1);
scanf("%d",&input[a]);
*(ascend+a)=input[a];
*(descend+a)=input[a];
}
printf("\n\n");
printf("\t\tProcessing");
for(x=0;x<6;x++)
{
_sleep(200);
printf(".");
}
system("cls");
_strdate( dbuffer );
printf( "The current date is %s \n", dbuffer );
_strtime( tbuffer );
printf( "The current time is %s \n", tbuffer );
asc(ascend);
dec(descend);
printf("\n\n\t ================================================\n");
printf("\n\t\t\tRESULT AS SHOWN AS BELOW\n");
printf("\n\t ================================================\n");
printf("\t\tAscending\tOriginal\tDescending\n");
for(a=0;a<size;a++)
{
printf("\t\t%d\t\t%d\t\t%d\n",*(ascend+a),input[a],*(descend+((size-1)-a)));
}
printf("\n\n\n\t");
free(ascend);
free(descend);
printf("Press 2 to go to new calculation or any keys to exit>");
scanf("%d",&m);
}while(m==2);
system("cls");
printf("\n\t\t\tThanks for using this system!!\n\n\t\t\tHAVE A NICE DAY!!\n\n\n");
}
void asc(int *ascend)
{
int i,j,smallest;
for(i=0;i<size-1;i++)
{
smallest=i;
for(j=i+1;j<size;j++)
if(ascend[j]<ascend[smallest])
smallest=j;
swap(ascend+i,ascend+smallest);
}
}
void dec(int *descend)
{
int i,j,smallest;
for(i=0;i<size-1;i++)
{
smallest=i;
for(j=i+1;j<size;j++)
if(descend[j]<descend[smallest])
smallest=j;
swap(descend+i,descend+smallest);
}
}
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}