初学c语言,写了两个程序,但都运行不了。能帮我找出问题并解释一下吗?

2025-06-22 11:04:18
推荐回答(1个)
回答1:

您好,你看下,第一个

#include 
#include 
int main()     //函数的返回值是int  
{
int sum(int c1,int c2,int c3,int c4,int c5);  //函数声明少了函数名 
int c1,c2,c3,c4,c5;
scanf("%c,%c,%c,%c,%c",&c1,&c2,&c3,&c4,&c5);
/* c1=c1;
c2=c2;
c3=c3;
c4=c4;        //这几条语句都没有意义 
c5=c5;*/
printf("%c,%c,%c,%c,%c\n",c1,c2,c3,c4,c5);
}
int sum(int c1,int c2,int c3,int c4,int c5)
{
// int c1;                 //不知道你的函数功能是干什么的,你这些变量都重复定义了 
if (c1>86&&c1<90)c1=c1-22;
else if(c1>118)c1=c1-22;
else c1=c1+4;
return(c1);
// int c2;
if (c2>86&&c2<90)c2=c2-22;
else if(c2>118)c2=c2-22;
else c2=c2+4;
return(c2);
// int c3;
if (c3>86&&c3<90)c3=c3-22;
else if(c3>118)c3=c3-22;
else c3=c3+4;
return(c3);
// int c4;
if (c4>86&&c4<90)c4=c4-22;
else if(c4>118)c4=c4-22;
else c4=c4+4;
return(c4);
// int c5;
if (c5>86&&c5<90)c5=c5-22;
else if(c5>118)c5=c5-22;
else c5=c5+4;
return(c5);
}

第二个

#include 
#include 
#include 
int main()   //这里为int  
{
int a,b;
printf("我们来玩石头剪刀布的游戏。0代表石头,1代表剪刀,2代表布\n");  //双引号打错,是英文状态下的 
do                      //你下面的引号全部打错 
{
printf("请出");
scanf("%d",&a);   //
if(a<0||a>2)
{
printf("输入有误,请重新输入");   //这儿打错 
scanf("%d",&a);  //
}
while(a<0||a>2);
srand(time(0));
b=rand()%3;
printf("我出%d,电脑出%d\n",a,b);
if(a==b)
{
printf("打平\n");
}
else if(a==0&&b==1||a==1&&b==2||a==2&&b==0)
{
printf("赢了\n");
}
else
{
printf("输了\n");
}
}while(1);      //少了while 
}