| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 702 人关注过本帖
标题:请各位高手帮忙看看,为什么队列的打印和求最大值不能正确执行?
取消只看楼主 加入收藏
ice_callous
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2010-10-14
结帖率:60%
收藏
已结贴  问题点数:20 回复次数:3 
请各位高手帮忙看看,为什么队列的打印和求最大值不能正确执行?
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdarg.h>

#define N 2


typedef float elemtype;
typedef struct
{
    elemtype *base;
    int dim;
    int *bounds;
    int *constants;
}Array;


void InitArray(Array &A)
{
    A.dim=3;
    int elemtotal;
    A.bounds=(int *)malloc(A.dim*sizeof(int));
    A.bounds[0]=N;
    A.bounds[1]=N;
    A.bounds[2]=N;
    elemtotal=N*N*N;
    A.base=(elemtype*)malloc(elemtotal*sizeof(elemtype));
    A.constants=(int*)malloc(A.dim*sizeof(int));
    A.constants[2]=sizeof(elemtype);
    A.constants[1]=A.constants[2]*N;
    A.constants[0]=A.constants[1]*N;
}


void DataIn_Array(Array &A)
{
    elemtype *y;
    int j1,j2,j3;
    float t;
    for(j1=0;j1<A.bounds[0];j1++)
        for(j2=0;j2<A.bounds[1];j2++)
            for(j3=0;j3<A.bounds[2];j3++)
            {
                scanf("%f",&t);
                y=A.base+A.constants[0]*j1+A.constants[1]*j2+A.constants[2]*j3;
                *y=t;
            }
}

void Print_Array (Array &A)
{
    int counter=0,i;
    int j2=0;
    for(i=0;i<A.bounds[0]*A.bounds[1]*A.bounds[2];i++)
    {
        counter++;
        j2++;
        printf("\n");
        printf("第%d层,第%d行,第%d列元素为:",(counter-1)/(A.bounds[1]*A.bounds[2]),
            (j2-1)/A.bounds[2],(counter-1)%A.bounds[2]);
        printf("%f",A.base[i]);
        if(counter%(A.bounds[1]*A.bounds[2])==0)
            j2=0;
    }

}


void MaxTem(Array &A)
{
    float max=-300.0;
    int i,j;
    for(i=0;i<A.bounds[0]*A.bounds[1]*A.bounds[2];i++)
    {
        if(A.base[i]>max)
        {
            max=A.base[i];
            j=i;
        }
    printf("\n最大值在%d层,%d行,%d列",(j-1)/(A.bounds[1]*A.bounds[2]),((j-1)%(A.bounds[1]*A.bounds[2]))/A.bounds[2],(j-1)%A.bounds[2]);
    }
}



void main()
{
    Array MyArry;
    int x;
    InitArray(MyArry);
    printf("\n***********************\n");
    printf("*1.读入数据 2.输出数据*\n");
    printf("*3.求最大值 4.退出    *\n");
    printf("***********************\n");
a:  printf("请输入你的选择\n");
    scanf("%d",&x);
    switch(x)
    {
    case 1:printf("\n向数组中读入数据为:\n");
           DataIn_Array(MyArry);
           printf("\n");
           break;
   
    case 2:printf("\n数组中的数据为:");
           Print_Array(MyArry);
           printf("\n");
           break;
   
    case 3:printf("\n当前数组中的最大值为:");
           MaxTem(MyArry);
           printf("\n");
           break;
   
    case 4:exit(0);break;
           
   
    default: printf("Error\n");
    }
    goto a;
}
搜索更多相关主题的帖子: 最大值 队列 打印 
2010-11-04 22:37
ice_callous
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2010-10-14
收藏
得分:0 
回复 2楼 寒风中的细雨
麻烦帮忙看看,新手,谢谢了,真的不知道哪里出错了

2010-11-05 18:09
ice_callous
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2010-10-14
收藏
得分:0 
回复 4楼 诸葛修勤
typedef struct
{
    elemtype *base;//数组元素基址   
    int dim;//数组维数
    int *bounds;//数组维界基址   
    int *constants;//数组映像函数常量基址
}Array;


2010-11-05 23:24
ice_callous
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2010-10-14
收藏
得分:0 
回复 7楼 寒风中的细雨
非常感谢你的帮助
2010-11-06 09:42
快速回复:请各位高手帮忙看看,为什么队列的打印和求最大值不能正确执行?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012592 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved