| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1571 人关注过本帖, 1 人收藏
标题:大家好,我刚学c语言
只看楼主 加入收藏
hongcheng668
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2009-10-15
结帖率:100%
收藏(1)
已结贴  问题点数:20 回复次数:22 
大家好,我刚学c语言
  刚学C语言 ,怎么输出  

    *
  * * *
* * * * *
  * * *
    *           谢谢!!!
搜索更多相关主题的帖子: c语言 
2009-10-15 13:30
无能为力
Rank: 2
来 自:哈尔滨
等 级:论坛游民
帖 子:28
专家分:25
注 册:2009-7-10
收藏
得分:0 
这个很简单,但是俺不会,路过,帮顶
2009-10-15 13:32
hongcheng668
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2009-10-15
收藏
得分:0 
是啊 刚学 希望谁能帮帮俺
2009-10-15 13:35
a826469452
Rank: 1
等 级:新手上路
帖 子:7
专家分:2
注 册:2009-10-15
收藏
得分:0 
我都是刚学求高手帮忙
2009-10-15 13:47
UserYuH
Rank: 12Rank: 12Rank: 12
来 自:毅华
等 级:火箭侠
威 望:8
帖 子:720
专家分:3300
注 册:2009-8-10
收藏
得分:20 
这个之前写的,可能不好理解,但很简结。
程序代码:
#define N 5   /* 可以改,最长一行的星数,要是奇数。 */
#include<stdio.h> 
int main(void) 
{ 
    int i=1,j,k=1; 
    while(i>0) 
    { 
     for(j=N-i;j;j--) 
       printf(" "); 
     for(j=i;j;j--) 
       printf(" *"); 
     printf("\n"); 
     if(i==N)k=0; 
     if(k) i+=2;  
     else i-=2;  
    }  
    getch();
   return 0;
} 

努力—前进—变老—退休—入土
2009-10-15 13:55
hongcheng668
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2009-10-15
收藏
得分:0 
厉害 向你学习 有什么好的编译工具吗 推荐下
2009-10-15 14:16
vcx
Rank: 2
等 级:论坛游民
帖 子:61
专家分:81
注 册:2009-9-15
收藏
得分:0 
来一个最直接的...#include <stdio.h>
main()
{
    printf("    *\n");
    printf("  * * *\n");
    printf("* * * * *\n");
    printf("  * * *\n");
    printf("    *\n   ");
}
纯属玩笑....5楼是高手
2009-10-15 15:06
hongcheng668
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2009-10-15
收藏
得分:0 
刚运行了5楼大哥的代码 出现了错误 不知道是不是我弄错了 还是代码有问题
 Compiling...
Text1.c
D:\c++\aa\Text1.c(7) : error C2065: 'N' : undeclared identifier
D:\c++\aa\Text1.c(16) : warning C4013: 'getch' undefined; assuming extern returning int
执行 cl.exe 时出错.
 
Text1.exe - 1 error(s), 0 warning(s)
2009-10-15 15:19
gaofei52022
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-10-15
收藏
得分:0 
那位大哥帮帮我的,谢谢,小弟实在不会了
2009-10-15 15:30
gaofei52022
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2009-10-15
收藏
得分:0 
#include "stdio.h"
#include "conio.h"
#define stack_size 100
typedef struct /*栈的定义*/
{  char elem[stack_size];
   int top;
 
}SqStack;
 
SqStack InitStack()/*栈的初始化*/
{ SqStack s;
  s.top=-1; /*栈空*/
 
  return s;
}
 
char GetTop(SqStack * s,char * e)/*取栈顶的元素*/
{ if(s->top==-1) return 0;
  *e=s->elem[s->top];
 
 
}
void Push(SqStack * s,char e)
{ /*if(s->top==(stack_size-1)) printf("Stack Overflow!"); */
  s->top++;
  s->elem[s->top]=e;
}
char Pop(SqStack * s,char * e)
{ /* if(s->top==-1) printf("Stack Overflow!"); */
  * e=s->elem[s->top--];
 
}
 
typedef struct /*栈的定义*/
{  float elem[stack_size];
   int top;
 
}SqStack1;
 
SqStack1 InitStack1()/*栈的初始化*/
{ SqStack1 s;
  s.top=-1; /*栈空*/
 
  return s;
}
 
int GetTop1(SqStack1 * s,int * e)/*取栈顶的元素*/
{ if(s->top==-1) return 0;
  *e=s->elem[s->top];
 
 
}
void Push1(SqStack1 * s,int e)
{ /*if(s->top==(stack_size-1)) printf("Stack Overflow!"); */
  s->top++;
  s->elem[s->top]=e;
}
int Pop1(SqStack1 * s,int * e)
{ /* if(s->top==-1) printf("Stack Overflow!"); */
  * e=s->elem[s->top--];
 
}
 
 
 
 
 
int SelLeve(char c1)
{ if(c1=='+'|| c1=='-') return 1;
  else
    if (c1=='*'|| c1=='/' || c1=='%') return 2;
    else
     if(c1=='(') return -1;
 }
 
 
 
main()
{  char expr[100]="6+(7-5)-8*6";
 
  houzhui(expr);
 
 
    getch();
}
int  num1,num2,l;
 
 
 
int  houzhui(char expr[])
{  SqStack Optr=InitStack();
   char c,d,b[10];
   int index=0,i=0,j=0,k,dlevel;
char hz[100];
   while(expr[index]!='\0')
    { c=expr[index];
      if(c>='0'&& c<='9')/*判断是不是数,如果是就把它取出放在运算数数组中*/
       {      ;
         hz[i]=c;j=i;
          i=index+1;k=i;
 
          c=expr[i];
          if(i<j){i=j+1;}
          j=0;
          while(c!='\0' && c>='0'&& c<='9' ||c=='.')
              {hz[i]=c;i++;c=expr[i];j++;}
              index=k+j;
              hz[i]='@'; i++;
 
       }
 
 
       if(c=='+'|| c=='-')
       { int clevel=1;
        d=GetTop(&Optr,&d);
        dlevel=SelLeve(d);
         if(d!='' && dlevel>=clevel)  {hz[i]=Pop(&Optr, &d);i++;hz[i]='@';i++;}
 
          Push(&Optr,c);
           index++;
 
          }
      if(c=='*'|| c=='/'|| c=='%')
       {  int clevel=2;
          d=GetTop(&Optr,&d);
 
 
          dlevel=SelLeve(d);
          if(d!='' &&dlevel >=clevel)  {hz[i]=Pop(&Optr, &d);i++;hz[i]='@';i++;}
 
          Push(&Optr,c);
          index++;
 
          }
       if(c=='(')
         { Push(&Optr,c);index++;}
       if(c==')')
         { d=GetTop(&Optr,&d);
           while(d!='('){hz[i]=Pop(&Optr,&d);i++;hz[i]='@';i++;d=GetTop(&Optr,& d);}
           Pop(&Optr,&d); index++;
         }
     }
        while(GetTop(&Optr,&d)!=''){hz[i]=Pop(&Optr,&d);i++;hz[i]='@';i++;}
        l=i;
        printf("hou zhui biao da shi :");
 
 
        for(i=0;i<l;i++)printf("%c",hz[i]);
        printf("\n------------------------------------------------------------");
        printf("%d",l);
        EvaluateExpr(hz);
}
 
 
 
int  EvaluateExpr(char hz[])
{ SqStack1 Opnd=InitStack1();
  int i=0;
  char c,d;
  c=hz[i];
  printf("\n%d",l);
  while(i<l)
{   printf("\n%c",hz[i]);
 
 
    if(c=='@'||c==''){i++;c=hz[i];}
    else
    {
      if( c>='0'&& c<='9' ||c=='.')
     {Push1(&Opnd,(int)(c));i++;c=hz[i];}
     else{
           switch(c)
                 {case '+' :num1=Pop1(&Opnd,&d);num2=Pop1(&Opnd,&d);num1=num2+num1; Push1(&Opnd,num1);break;
                  case '-' :num1=Pop1(&Opnd,&d);num2=Pop1(&Opnd,&d);num1=num2-num1; Push1(&Opnd,num1);break;
                  case '*' :num1=Pop1(&Opnd,&d);num2=Pop1(&Opnd,&d);num1=num2*num1; Push1(&Opnd,num1);break;
                  case '/' :num1=Pop1(&Opnd,&d);num2=Pop1(&Opnd,&d);num1=num2/num1; Push1(&Opnd,num1);break;
                  case '%' :num1=Pop1(&Opnd,&d);num2=Pop1(&Opnd,&d);num1=num2%num1; Push1(&Opnd,num1);break;
                }
 
           }
      }
    }
/* printf("\n%d", Pop1(&Opnd,&d));*/
 
 }
2009-10-15 15:30
快速回复:大家好,我刚学c语言
数据加载中...
 
   



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

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