#include<stdio.h>#include<stdlib.h>//输入三个整数并判断其排列顺序及最大值#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1#define OVERFLOW -2//预定义类型typedefint Status;typedefint ElemType;typedef ElemType *Triplet;//函数原型
Status InitTriplet(Triplet *pT,ElemType v1,ElemType v2,ElemType v3);
Status DestroyTriplet(Triplet *pT);
Status Get(Triplet T,int i,ElemType *pElem);
Status Put(Triplet T,int i,ElemType e);
Status IsAscending(Triplet T);
Status IsDescending(Triplet T);
Status Max(Triplet T,ElemType *pElem);
Status Min(Triplet T,ElemType *pElem);intmain(){
Triplet tr;
ElemType e,e1,e2,e3;int a1,a2,a3;int result;printf("Please enter 3 integers:");scanf("%d%d%d",&a1,&a2,&a3);
e1=a1;e2=a2;e3=a3;InitTriplet(&tr,e1,e2,e3);
result=IsAscending(tr);if(result)printf("Ascending!\n");elseprintf("Not Ascending!\n");
result=IsDescending(tr);if(result)printf("Descending!\n");elseprintf("Not Descending!\n");Min(tr,&e);printf("The smallest number is : %d\n",e);Max(tr,&e);printf("The biggest number is : %d\n",e);DestroyTriplet(&tr);return0;}
Status InitTriplet(Triplet *pT,ElemType v1,ElemType v2,ElemType v3){*pT=(ElemType *)malloc(3*sizeof(ElemType));if(!(*pT))exit(OVERFLOW);(*pT)[0]=v1;(*pT)[1]=v2;(*pT)[2]=v3;return OK;}
Status DestroyTriplet(Triplet *pT){free(*pT);*pT=NULL;return OK;}
Status Get(Triplet T,int i,ElemType *pElem){if(i<1||i>3)return ERROR;*pElem=T[i-1];return OK;}
Status Put(Triplet T,int i,ElemType e){if(i<1||i>3)return ERROR;
T[i-1]=e;return OK;}
Status IsAscending(Triplet T){return(T[0]<=T[1]&&T[1]<=T[2]);}
Status IsDescending(Triplet T){return(T[0]>=T[1]&&T[1]>=T[2]);}
Status Max(Triplet T,ElemType *pElem){*pElem=(T[0]>=T[1])?((T[0]>=T[2])?T[0]:T[2]):((T[1]>=T[2])?T[1]:T[2]);return OK;}
Status Min(Triplet T,ElemType *pElem){*pElem=(T[0]<=T[1])?((T[0]<=T[2])?T[0]:T[2]):((T[1]<=T[2])?T[1]:T[2]);return OK;}
#include<stdio.h>#include<stdlib.h>#include<time.h>//加法的时间测试intmain(){int i,j,n;int x,s;
clock_t start,end,total;printf("Please enter the calculation scale:n= ");scanf("%d",&n);
start=clock();for(i=1;i<=n;i++)for(j=1;j<=n;j++){++x;s+=x;}
end=clock();
total=end-start;printf("The start time is %d,and the end time is %d.\n",(int)start,(int)end);printf("When n=%d ,the time is %d ms.\n",n,(int)total);return0;}
#include<stdio.h>#include<stdlib.h>#include<time.h>//加法的时间测试intmain(void){int i,j,k;int n,*pMa,*pMb,*pMc;
time_t start,end,total;//输入规模;printf("Please enter the calculation scale:n= ");scanf("%d",&n);//矩阵建立
pMa=(int*)malloc(n*n*sizeof(int));if(!pMa)return1;
pMb=(int*)malloc(n*n*sizeof(int));if(!pMb)return1;
pMc=(int*)malloc(n*n*sizeof(int));if(!pMc)return1;//矩阵初始化
k=0;for(i=0;i<n;i++)for(j=0;j<n;j++){
pMa[i*n+j]=++k;
pMb[i*n+j]=k*k;}//时间变量设置
start=time(NULL);//矩阵相乘for(i=0;i<n;i++)for(j=0;j<n;j++){
pMc[i*n+j]=0;for(k=0;k<n;k++)
pMc[i*n+j]=pMa[i*n+k]*pMb[k*n+j];}
end=time(NULL);
total=end-start;printf("The start time is %d,and the end time is %d.\n",(int)start,(int)end);printf("When n=%d ,the time is %d s.\n",n,(int)total);free(pMa);free(pMb);free(pMc);return0;}