各位~我很菜。帮帮我啊~~~

fly_higher 2004-12-01 03:49:39
给定一字母,要求打印出一个菱形,该菱形中间一行由此字母组成,其相邻的上下两行由它直接前趋字母组成。按此规律,真到字母A出现在第一行和最后一行为止。
如: A
BBB
CCCCC →给定字母C
BBB
A
读入任一含加、减运算的表达式并计算值。其中数为整数,每一数前有一字符,表达式用“=”结束,如输入:+20-4-5+168=
...全文
144 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
fly_higher 2004-12-02
  • 打赏
  • 举报
回复
哇~~ 楼上这位强!
不过咧~ 我就是有点地方看不懂哦~ 能否详解~
Michael_555 2004-12-01
  • 打赏
  • 举报
回复
不好意思,要修修


#include <stdio.h>
#include <math.h>

int GetNumber( char *paramStr );
int mergeOperAndNum( char oper, int num );
int CalculateTwoNum( int n, int m, char operation );

void main()
{
char str[50];
char oper;
int val=0;
int num1, num2;

printf( "Please Input: ");
scanf( "%s", str );

printf( "You Input String: %s", str );

oper = *str;
str++;

num1 = GetNumber( str );
num1 = mergeOperAndNum( oper, num1 );

while( *str != '=' )
{
oper = *str;
str++;

num2 = GetNumber( str );
val = CalculateTwoNum( num1, num2, oper );
}

printf( "%d\n", val );

while( getchar() != Q ); //input Q to exit

}

int GetNumber( char *paramStr )
{
int value;

while ( *str >= '1' && *str <= '9' )
{
value = ( 10 * value + ( *str++ - '0' ) ) & 0xFFFF;
}

return value;
}

int mergeOperAndNum( char oper, int num )
{
if( oper == '+' )
{
return num;
}
else if( oper == '-' )
{
num = num - 2 * num;
return num;
}
else
{
printf( "Error1!\n");
return 0xFFFF;
}
}


int CalculateTwoNum( int n, int m, char operation )
{
switch( operation )
{
case '+':
return ( n + m );
case '-':
return ( n - m );
case '*'
return ( n * m );
case '/'
return ( n / m );
default:
printf( "Error2!\n");
return 0xFFFF;
}

}
Michael_555 2004-12-01
  • 打赏
  • 举报
回复
读入任一含加、减运算的表达式并计算值。其中数为整数,每一数前有一字符,表达式用“=”结束,如输入:+20-4-5+168=



#include <stdio.h>
#include <math.h>

int GetNumber( char *paramStr );
int mergeOperAndNum( char oper, int num );
int CalculateTwoNum( int n, int m, char operation );

void main()
{
char str[50];
char oper;
int val=0;
int num1, num2;

printf( "Please Input: ");
scanf( "%s", str );

printf( "You Input String: %s", str );

oper = *str;
str++;

num1 = GetNumber( str );
num1 = mergeOperAndNum( oper, num1 );

while( *str != '=' )
{
oper = *str;
str++;

num2 = GetNumber( str );
val = CalculateTwoNum( num1, num2, oper );
}

printf( "%d\n", val );

while( getchar() != Q ); //input Q to exit

}

int GetNumber( char *paramStr )
{
int value;

while ( *str >= '1' && *str <= '9' )
{
value = ( 10 * *value + ( *str++ - '0' ) ) & 0xFFFF;
}

return value;
}

int mergeOperAndNum( char oper, int num )
{
if( oper == '+' )
{
return num;
}
else if( oper == '-' )
{
num = num - 2 * num;
return num;
}
else
{
printf( "Error1!\n");
return 0xFFFF;
}
}


int CalculateTwoNum( int n, int m, char operation )
{
switch( operation )
{
case '+':
return ( n + m );
case '-':
return ( n - m );
case '*'
return ( n * m );
case '/'
return ( n / m );
default:
printf( "Error2!\n");
return 0xFFFF;
}

}
Michael_555 2004-12-01
  • 打赏
  • 举报
回复
第一个问题,在VC上调试通过。

#include <stdio.h>

void main()
{
char baseLetter, ch = 'A';
int count, i, m, j;

printf( "Please Input A Letter:" );
scanf( "%c", &baseLetter );

/* check the input character */
while( baseLetter < 'A'
|| baseLetter > 'z'
|| ( baseLetter > 'Z' && baseLetter < 'a' ) )
{
printf( "Input Error!\n" );
printf( "Please Input A Letter:" );
scanf( "%c", &baseLetter );
}

if( baseLetter >= 'a' && baseLetter <= 'z' )
{
baseLetter = baseLetter - ( 'a' - 'A' );
}

m = baseLetter - 'A' + 1;
count = 2 * ( baseLetter - 'A' ) + 1;

for( i = 1; i <= count ; i ++ )
{
for( j = 1; j <= count; j ++ )
{
if( j < m )
{
if( j < baseLetter - ch +1 )
{
printf( " " );
}
else
{
printf( "%c", ch );
}
}
else
{
if( ( count - j ) >= ( baseLetter - ch ) )
{
printf( "%c", ch );
}
else
{
printf( " " );
}
}
}

if( i >= m )
{
ch--;
}
else
{
ch++;
}

printf( "\n" );

}

while( getchar() != '5' ); // input 5 to exit.

}
huanmm 2004-12-01
  • 打赏
  • 举报
回复
main()
{
printf(" A \n");
printf(" BBB \n");
printf("CCCCC\n");
printf(" BBB \n");
printf(" A \n");
}
seasy 2004-12-01
  • 打赏
  • 举报
回复
第二题有个帖子刚讨论过
seasy 2004-12-01
  • 打赏
  • 举报
回复
char ch_out = 'a', ch_in;
int i,j;
int num = ch_in - ch_out;

for(j=num, j>=0; j--)
{
for(i=0; i<j; i++)
{
printf(" ");
}
printf("%c\n", ch_out++);
}

for(j=num, j>=0; j--)
{
for(i=j; i>=0; i--)
{
printf(" ");
}
printf("%c\n", --ch_in);
}

大概就这样吧
dean7411 2004-12-01
  • 打赏
  • 举报
回复
修改一下:
#include "stdio.h"
main()
{
int a,b,i;
for (a=3,b=1;a>1;a--,b++)
{
for (i=1;i<a;i++)
printf(" ");
for (i=b;i>1;i--)
printf("%c",a+b);

printf("/n");
}
......
写了一半,可能有些错,但思想是这样的,给你借鉴一下,看懂了上半段你应该可以写出下半段
fly_higher 2004-12-01
  • 打赏
  • 举报
回复
谢谢楼上的大哥啦~
dean7411 2004-12-01
  • 打赏
  • 举报
回复
第二题代码量会很多,
dean7411 2004-12-01
  • 打赏
  • 举报
回复
下一半你自己写吧
dean7411 2004-12-01
  • 打赏
  • 举报
回复
main()
int a,b,i;
for (a=3,b=1;a>1;a--,b++)
for (i=1;i<a;i++)
printf(" ");
for (i=b;i>1;i--)
printf("%c",a+b);

printf("/n");
写了一半,可能有些错,但思想是这样的,给你借鉴一下
fly_higher 2004-12-01
  • 打赏
  • 举报
回复
有没有搞错啊~
题目不是这样~
dudu妈 2004-12-01
  • 打赏
  • 举报
回复
很苯得办法
dudu妈 2004-12-01
  • 打赏
  • 举报
回复
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[])
{
static char d[][5]={{' ',' ','A',' ',' '},{' ','B','B','B',' '},{'C','C','C','C','C'},{' ','D','D','D',' '},{' ',' ','E',' ',' '}};
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
cout<<d[i][j];
cout<<endl;
}
system("PAUSE");
return 0;
}

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧