int x=100;
f (int a)
{
int b=0;
static int c=1;
b+=2;
c+=3;
return a+b+c;
}
void g()
{
x=50;
printf("%d",x);
}
void main ()
{int a=100;
printf ("%d",f(a));
g()
printf ("%d",f(a));
}
补充:不知道x=100与x=50是否对f(a)的输出值是否有影响?
x的值只对调用g()有影响,而调用f(a)时,实参是a=100,不是x,而且返值是a+b+c,所以x的值对调用f(a)后的输出没有影响。在此程序把printf()输出格式中增加了\n(每次打印后换行),即程序为:
int x=100;
f(int a)
{
int b=0;
static int c=1;
b+=2;
c+=3;
return a+b+c;
}
void g()
{
x=50;
printf("%d\n",x);
}
void main ()
{int a=100;
printf ("%d\n",f(a));
g();
printf ("%d\n",f(a));
}
程序的输出结果为:
106
50
109
问题:c语言,看看我写的哪有问题?
输入字符串,计算大写字母,小写字母,数字的个数(用for循环)
回答:
这个循环不能写n<=100的(超过99就下标溢出了)
且你a[100]只用gets(a)得到没有100个数据的,真实数据后面的是随机数
对你程序的修改是头上加
#include <string.h>
然后改循环为
for(n=0;n<strlen(a);n++)
且你的判断全错了,不是判n,而要用a[n]
(贴程序时不要用图,否则别人要费时帮你输入程序的,直接用文本就可以了)