高速代理:3道C语言基础题-我等着急用

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 02:31:59
我没怎么学过C语言,但缺要考-我现在解不出这样的题-大家帮个忙啊-急
第一题:完成下面的分段函数的计算,程序运行时用户从键盘输入一个数值X,在屏幕上输出Y值.
Y= (这里有个大括号) X的2次方 X>0
0 X=0
-X的2次方 X<0
2.通过键盘输入一串字符,统计并输出其中英文字母的个数.
3.已有按从小到大的顺序排列的10个数,现输入一个数,要求插入到数列中.插入后数列仍然按从小到大的顺序排列.

第一题
main( ){
int x,y;
scanf("%d",&x);
if(x>0)
y=x*x;
else if(x==O)
y=0;
else y=(-x)*(-x);
printf("%d",y);}
第二题
#include "string.h"
main( )
{char str[30];
int i,k=0;
scanf("%s",str);
for(i=0; str[i]!='\0';i++)
if(str[i]>=a&&str[i]<=z||str[i]>=A&&str[i]<=Z)
k++;
prinf("%d",k);}
第三题
main( )
{int a[10]={1,3,5,7,9,11,13,15,17,19},b[11]
int x,i;
scanf( "%d",&x);
for(i=0;i<10;i++)
if(a[i]<=x&&a[i+1]>=x)
break;
for(j=0;j<11;j++)
if(j<=i)
b[j]=a[j];
elseif(j=i+1)
b[j]=x;
else b[j]=a[i-1];
for(i=0;i<11;i++)
prinf("%d",b[i]);}
你上机实现一下吧,应该没有问题的.

#include<stdio.h>
void main()
{int x,y;
if (x>0)
y=x2;
else
if(x=0)
y=0;
else
y=-x2
}

第一题:
#include<stdio.h>
main()
{ int x,y;
printf("请输入x的值:\n");
scanf("%d",&x);
if(x>=0)
y=x*x;
else
y=(-x)*(-x);
printf("y的值为:%d",y);
}
第二题
#include<stdio.h>
main()
{ char c,
int leter=0,other=0;
printf("请输入一行字符:\n");
while((c=getchar())!=‘\n’);
{ if(c>'a'&&c<='z'//c>='A'&&c<='Z')
leter++;
else
other++;
}
printf("字母数=%d,其他字符=%d\n",leter,other);
}
第三题:
#include<stdio.h>
main()
{ int a[11]={1,4,6,9,13,16,19,28,40,100};
int temp1,temp2,number,end,i,j;
printf("原数字串为:\n");
for(i=0;i<10;i++)
printf("%5d",a[i]);
printf("\n");
printf("insert data:");
scanf("%d",&number);
end=a[9];
if(number>end)
a[10]=number;
else
{ for(i=o;i<10;i++)
{ if(a[i]>number)
{temp1=a[i];
a[i]=number;
for(j=i+1;j<11;j++)
{ temp2=a[j];
a[j]=temp;
temp1=temp2;
}
break;
}
}
}
printf("插入后的数字串为:\n");
for(i=0;i<11;i++)
printf("%6d",a[i]);
}

(注意不要把分号看成冒号)

第三题
main()
{int h,i,j,k,l,m,a[11];
clrscr();
printf("intput 10 number with the regular(min....max):\n");
for(h=0;h<=9;h++)
{ scanf("%d",&a[h]);
}
printf("please input one number:\n");
scanf("%d",&k);

for(i=0;i<=9;i++)
{
if(k<a[i])
{for(j=i;j<=9;j++)
{a[10-j+i]=a[9-j+i];
}
a[i]=k;
break;
}
else
a[10]=k;
}
for(m=0;m<=10;m++)
printf("%5d",a[m]);
getch();
}