标题:帮忙把程序改成任意进制都能转换、还有程序的流程图!求解!
取消只看楼主
fan1
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2012-5-23
结帖率:50%
已结贴  问题点数:20 回复次数:1 
帮忙把程序改成任意进制都能转换、还有程序的流程图!求解!
#include <stdio.h>
 #include <stdlib.h>
 #include <malloc.h>
 #define MAX 100

typedef struct
 {
      int data[MAX];
      int top;
 }seqstack, *pseqstack;
 pseqstack s;
 //s = (pseqstack)malloc(sizeof(seqstack));

 pseqstack init_seqstack()
 {
      pseqstack s;
      s = (pseqstack)malloc(sizeof(seqstack));
      if(s)
          s ->top = -1;
      return s;
 }

 int empty_seqstack(pseqstack s)
 {
      if(s ->top == -1)
          return 1;
      else
          return 0;
 }

 int input_seqstack(pseqstack s,int x)
 {
      if(s ->top ==MAX - 1)
          return 0;//栈满不能入栈
      else
      {
          s ->top ++;
          s ->data[s ->top] = x;
          return 1;
      }
 }

 int out_seqstack(pseqstack s)
 {
      int x;
      if (empty_seqstack(s)) //栈空不能出栈
          return 0;
      else
      {
          x = s ->data[s ->top];
          s ->top--;
          printf("%d",x);
          return 1;
      }
 }

 int gettop_seqstack(pseqstack s)
 {
      int x;
      if(empty_seqstack(s))
          return 0;
      else
      {
          x = s->data[s ->top];
          return (1);
      }
 }

 int change(int x)
 {
      int n;
      pseqstack s;
      s = (pseqstack)malloc(sizeof(seqstack));
      s->top=-1;         
     
     while(x != 0)
      {
          n = x % n;
          input_seqstack(s,n);
          x = x / n;
      }
      while(s->top>-1)
      {
          out_seqstack(s);//
      }
      putchar('\n');
      return 1;
 }

 int main()
 {
      int n;
      pseqstack s;
      s = (pseqstack)malloc(sizeof(seqstack));
      printf("输入要转化的进制整数:\n");
      scanf("%d",&n);
      //printf("选择你要转换成的进制数:\n");
      change(n);
      return 0;
 }
搜索更多相关主题的帖子: top include return 流程图 
2012-05-26 09:44
fan1
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2012-5-23
得分:0 
回复 2楼 pauljames
能帮画下流程图么?谢谢!
2012-05-28 14:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-368056-1-1.html




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

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