连数问题 c语言问题啊

为什么没有错误却运行不下去了呢?
题目的要求是这样的:
有一位超级战士被空降到一个未知的地区,该战士带有一个GPS接收机和PDA设备。该地区中有5个特殊的区域:A区、B区、C区、D区、O区。该地区的示意地图如下图所示。(略,不影响程序)
其中,A区为雷区,B区中有陷阱,C区中有埋伏,D区为武器库,O区为人质区。
该战士携带的GPS接收机,可以告诉他降落地点的经纬度坐标(用X, Y表示)。若将由GPS接收机显示的坐标值输入到他的PDA中,PDA中会显示出他所在的区域。
如果他的位置在A区,则PDA上会显示“你现在在A区,小心地雷!”;
如果他的位置在B区,则PDA上会显示“你现在在B区,小心有陷阱!”;
如果他的位置在C区,则PDA上会显示“你现在在C区,小心敌人埋伏!”;
如果他的位置在D区,则PDA上会显示“你现在在D区,可以补充武器!”;
如果他的位置在O区,则PDA上会显示“你现在在O区,快去解救人质!”;
如果他在上述5个区之外,则PDA上会显示“你现在在任务区外!”;
如果落在两个区域的边界线上,则PDA上会显示“你现在在两个区域的边界线上!”;
请你用C语言编程实现上面的PDA中的程序功能。
我的程序:
#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
float x,y;
printf("请输入超级战士所在的X坐标:\n\n");
scanf("%f",&x);
printf("请输入超级战士所在的Y坐标:\n\n");
scanf("%f",&y);
if (x==20,45,60||y==20,50,75){
//在边界上s
else if(x>75||y>60){
//任务区外t
else if(y45){
else if(y0){
else if(x0){
else if(x20){
else if(x50){
switch(zone){
case'1':printf("你现在在A区,小心地雷!\n");
case'2':printf("你现在在B区,小心有陷阱!\n");
case'3':printf("你现在在C区,小心敌人埋伏!\n");
case'4':printf("你现在在D区,可以补充武器!\n");
case'0':printf("你现在在O区,快去解救人质!\n");
case'5':printf("你现在在任务区外!\n");
case'6':printf("你现在在两个区域的边界线上!\n");
LZ的代码的确有问题,但是仍然会运行结束,只不过在界面上没有任何输出罢了,因为没有满足输出的任何一个条件。
1、首先变量x和y声明类型最好为int整型,因为代码中关系表达式用的是整数,而且输入时一般也都是整型数据。
2、变量zone为char型,但是后面的赋值语句如:zone=6;不正确,应该写为:zone='6';
3、第一个IF条件 if (x==20,45,60||y==20,50,75)存在严重的逻辑错误。括号之中是两个逗号表达式,前面的表达式x==20,45,60 最终结果是60,当然这个结果没有赋给任何变量,但它是一个非0值,为真,满足逻辑条件,逻辑或||后面的表达式,程序不会计算。所以这个条件永远满足,不管你输入什么,zone值都是'6',所以一直会输出这句话:"你现在在两个区域的边界线上!"。
回答数:1536几道c语言题目
求c语言大神啊_魔兽世界吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:5,727,088贴子:
几道c语言题目
求c语言大神啊收藏
小弟马上c语言考试
老师勾的题大部分都不会
望万能的窝吧能帮帮我
求大神啊~~~1.
Write a program to compute the value of Euler’s number e, which is used as the base of natural logarithms. Use the following formula.
e = 1+ 1/1! + 1/ 2! + 1/3! +…… + 1/n! Use a suitable loop construct. The loop must terminate when the difference between two successive values of e is less than 0.00001. 2.
Write program to print the following outputs using for loops. ***** **** *** ** *3.
Write program to print the following outputs using for loops. * ** *** **** ***** 4. Write program to print the following outputs using for loops. * *** ***** ******* ********* 5.
The numbers in the sequence 1 1 2 3 5 8 13 21 ……. are called Fibonacci numbers. Write a program using a do…while loop to calculate and print the first m Fibonacci numbers. 6.
Given a number, write a program using while loop to reverse the digits of the numbers. For example, the number 12345 should be written as 54321 (Hint: Use modulus operator to extract the last digit and the integer division by 10 to get the n-1 digit number from the n digit number.) 7.
Write a program to evaluate the equation y = xn , When n is a non-negative integer. 8.
Write a program to print all the daffodil numbers. Daffodil numbers are those numbers, which are 3-digit numbers, sum of cubic of each digit equals to the number, for example, 153=13+53+33 9.
Input a positive number from keyboard, and then judge whether the input number is a prime, if it is a prime, then print “yes”, else print “no”. 10.
Input a number n from keyboard, then calculate
1!+2!+…+n!. 11.
Input a number n from keyboard, then calculate
1+(1+2)+(1+2+3)+…+(1+2+3+…+n). 12.
Input a year n from keyboard, and then judge whether the year is a leap year. Leap year is a year which satisfies only one of the following conditions: (1) It is divisible by 4, but not divisible by 100 (2) It is divisible by 400.13. Write a program according to the following function, which requires input x from keyboard, then output the corresponding y.14. Input an arithmetic expression from keyboard, and then output its result. Format of the arithmetic expression is as follows, a op b, in which a and b are integers, op is operand, such as +、-、*、/、%. 15. We all knew that the months 1, 3, 5, 7, 8, 10, 12 in 1998 has 31 days, months 4, 6, 9, 11 has 30 days, month 2 has 28 days. Write a program to give days of the month, which requires input month from keyboard. 16. Input a positive number from keyboard, and then judge whether the input number is divisible by 3 and divisible by 5, and then print “yes” or “no” respectively.
17. Write a program which requires input a character from keyboard, and then print the character itself and its ASCII value. 18. Calculate the following expressions, then gives the results. (1)x+a%3*(int)(x+y)%2/4,设x=2.5,a=7,y=4.7 (2)(float)(a+b)/2+(int)x%(int)y,设a=2,b=3,x=3.5,y=2.5 19. Give the results of the following programs. void
main() { int
i,j,m,n; i=8, j=10; m=++i;n=j++; printf(“%d,%d,%d,%d\n”,i,j,m,n); }
main() { int
a,b,c,i=5; a=i++; b=++i; --i; c=i--; printf(“a=%d,b=%d,c=%d\n”,a,b,c); } 20.
Input a number from keyboard, if the number is great or equal 0, then print its square root, else print “input wrong number” 21. Write a program to evaluate the equation sum = 1+ 1/2 + 1/3 + 1/4 +…+ 1/n,
while n is put from keyboard. 22.
Write a program that prints the even numbers from 1 to 100. 23.
Write a program that prints the odd numbers from 1 to 100. 24.
Input two numbers x and y from keyboard, find the maximum. 25. Man retires at 60, female retires at 55, please input man or female’s age and sex, then judge whether he or she retires or not. Take F or f to indicate female, M or m to indicate male. 26.
Input three integers a, b and c from keyboard, calculate the roots of equation ax2+bx+c=0(a≠0), maintaining 2 digits after decimal point.. 27.
Input a 3-digit number from keyboard, and then judge whether it is a daffodil number. Daffodil numbers are those numbers, which are 3-digit numbers, sum of cubic of each digit equals to the number, for example, 153=13+53+33 28. Write a program according to the following function, which requires input x from keyboard, then output the corresponding y.
29. Write a program, input three edges of the triangle, and figure out its area. Hints, sum of every two edges must be greater than the third edge, for unreasonable edges, error message should be given, 30. Input a character from keyboard, if it is a lowercase, change into upper case, if it is an uppercase, change into lower case, else print the original character. 31. The following formula converts the given temperature in Fahrenheit to Celsius
, in which, C shows temperature in Celsius, F shows temperature in Fahrenheit. Write a program, input the given temperature in Fahrenheit, and then output in Celsius, maintaining 2 digits after decimal point.
....瞬间沉了啊 自己顶
C语言真心不会
登录百度帐号我的游戏推荐游戏
后查看最近玩过的游戏
使用签名档&&
为兴趣而生,贴吧更懂你。或C语言问题_百度知道
void Print(char e){
printf(&%c&,e);}void First(BiTree T,int (*Visit)(char e)){
if(Visit(T-&date))
if(First(T-&lchild,Visit))
if(First(T-&rchild,Visit));
printf(&出错!&);
}}C:\Users\Administrator\Desktop\1\main.c|39|error: void value not ignored as it ought to be|C:\Users\Administrator\Desktop\1\main.c|40|error: void value not ignored as it ought to be|什么意思?
提问者采纳
答案应该是B,这个没什么好解释的(就是指针变量指向变量的地址)2
答案应该是D
如果直接用字符串对字符数组初始化的话字符数组的长度要比实际字符串长度大1的
因为字符串在字符数组中是以'\0'结束的,这个你也可以用sizeof() 分别测试一下
我已经测试过了A比B大1的3
答案应该是D,这个没的说,括号的作用就是避免二义4
答案应该是C,不要把 int *ptr();搞混了,题上的是返回一个整形数据的指针函数,后者是一个
返回指针的函数5
答案是A,呵呵,这个你好好想一下就明白了6
答案是A 47
答案是23 这个你要好好看一看,特别是(&Arr+1)它和(Arr+1)区别很大,前者在地址上加了
1而后者在地址上加了1*sizeof(int);8.
这道题你是不是搞错了,你仔细看看有很多错误的。9. 答案是 B 为了帮助你理解,对此程序我写了段代码#include&stdio.h&
void main(){
void func(char str[100]);
char str[100];
printf(&%d\n&,sizeof(str));//答案是100
func(str);
void func(char str[100]){
printf(&%d\n&,sizeof(str));//答案是4}为什么会出现这种情况呢,原因是因为两者有着本质性的区别,第一个sizeof(str)中的str是一个地址常量,它索引着一段大小为100的内存堆,而第二个sizeof(str)中的str是一个字符指针变量sizeof(str)的结果就是一个字符指针变量所具有的内存,它的内存应该是为4的10
答案是D二: 1.错,应该放在静态存储区(或全局数据区的)2 对3. 对4.错,不可能是float 型的5.对三1. int main(void) {
Unsigned char index = 0;//这个地方应该是unsigned int index=0;注意第一个u不能大写
While(index & 256)
Printf(“index value %d\n”,index);
Return 0; }2.char*f(){
//应该是static char s[4]={'0','1','2','3','\0'}; Char s[4]={‘1’,’2’,’3’,’0’};//关键字的开头是不能大写的,还有就是符号‘也不对 R//ruturn 第一个字母也不能大写,}
Void main(){ Char *s;//应该是char 第一个字母不能大写
s=f(); printf(“%s”,s);}//你这道题的本意是想通过函数调用来获得一个字符串的首地址从而在主函数中输出,//但是,有一点这个程序没有考虑到那就是当被调函数结束后那个char s[4] 所占内存将自动//操作系统回收,因为它只是个动态局部变量,所以要想达到目的应该是声明成静态变量的//static char s[4],还有一点错误就是字符串都要'\0'结尾否则输出的字符串的将不会是你想要的那样3.这道题没什么错误,能达到预期的效果工尝递渴郛韭店血锭摩,除了有几处拼写错误,例如你第一个是GetmMnory而第二个是GetMemory这一点你注意一下就可以了void GetMenory(char**p){ *p = (char*)malloc(100);}Void Test(void){ char*str = NULL; GetMemory(&str); strcpy(str,”hello morld”); printf(str);}4.这道题没什么语法错误,除了单引号格式不对,还有就就违反了字符串都要以'\0'结尾这一约定5.这道题没有什么语法错误,就是有个字符串函数写错了strcopy,应该写成 strcpy的四:你这道题具体是让做什么的,我不是太明白,是让建一个动态链表啊还是静态链表啊,请你把问题写详细点五。int judgment(int a[],int length )//这个函数是判断是否对称的{ for(int i=0;i&=length/2;i++)
if(a[i]!=a[length-i])
if(i==length/2+1)
return 0; }void main(void){ int a[10]; int num;
printf(&请输入你要检测的数\n&) ;
scanf(&%d&,&num); int length=0;//这个循环是为了把整数拆开放到一个整形数组中,拆开以后放进数组里面的刚好是和正常的数//反序的,不过这个不会影响结果的,因为只要数对称反序后一样对称,如果数不对称反序后依然不对称do {
int temp=num%10;
a[length]=
num=num/10;
} while(num&=10);a[length]=if( judgment(a,length))printf(&是\n&);}如果这个程序有什么不懂得话,可以提出来,随时帮你解析希望我的答案对你有点帮助……
要分也不至于这样吧........
提问者评价
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁一个C语言问题_百度知道
提问者采纳
scanf(&%.f,%.f,%.f,%.f&,&l,&h,&w,&weight);错了%.f,多了个点
提问者评价
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 连数问题 c语言 的文章

 

随机推荐