大侠们帮忙做几个C语言编程题吧~~~考试要用的(请尽快,在线等)

2024-12-26 16:35:01
推荐回答(5个)
回答1:

不知道是帮了你还是害了你,你学什么的,多大了,这些是最基础的题,很简单的,自己多看看书吧,这些程序都试过,可以运行,自己好好看看
1.
#include
main()
{
int x,y;
printf("please input x :");
scanf("%d",&x);
/*下面三句可以用这一句代替: y=(x<0)?(x-1):(x=0?0:1);*/
if(x<0) y=x-1;
else if(x==0) y=0;
else y=1;
printf("the value of y=%d",y);
getch();
}
2.
#include
main()
{
int h,i,s;
s=560;
h=s/60;
i=s%60;
printf("%d minutes equals %d hours %dminutes",s,h,i);
getch();
}
3.
#include
main()
{
int a,b,c,d,max,temp;
max=0;
temp=0;
printf("please input the value of a,b,c,d:\n");
scanf("%d%d%d%d",&a,&b,&c,&d);
/*以下六行可被这一行代替: max=(a>b?a:b)>(c>d?c:d)?(a>b?a:b):(c>d?:d);*/
if(a>=b)max=a;
else max=b;
if(c>=d)temp=c;
else temp=d;
if(maxprintf("the max of a,b,c,d is %d ",max);
getch();
}
4
#include
main()
{
char c;
int character=0 ,number=0,space=0 ,others=0;
/*
输入
abcdefg1234 <><>
输出
character=7
number=4
space=3
others=5
*/
do
{
c=getchar();
if(c>='a'&&c<='z'||c>='A'&&c<='Z')character++;
else if(c>='0'&&c<='9')number++;
else if(c==' ')space++;
else others++;
}
while(c!='\n') ;
printf("character=%d\nnumber=%d\nspace=%d\nothers=%d\n",character,number,space,others);
getch();
}
5.
#include
main()
{
printf(" * * * * * * * ** *\n");
printf(" * * * * * * * * * *\n");
printf(" * * * * * * * * * *\n");
printf(" * * * * * * * * * *\n");
getch();
}
6.
#include
main()
{
int i=0;
int j=0;
printf(" ");
for(;i<5;i++)
{
for(j=5-i;j>0;j--)
printf(" ");
printf("@");
for(j=0;j printf("@@");
printf("\n");
}
getch();
}
7.
#include
float a(float n)
{
float an;
if(n<1)
return -1;
else if(n==1)
an=1;
else
an=a(n-1)+(2*n-1)/(n*n);
return an;
}
main()
{
float n;
printf("please input n:");
scanf("%f",&n);
printf("a(n)=%f",a(n));
getch();
}
8.
#include
int a(int n)
{
int i,an=0;
for(i=1;i<=n;i++)
{
an+=i;
}
return an;
}
main()
{
int n;
printf("please input n:");
scanf("%d",&n);
printf("a(n)=%d",a(n));
getch();
}
9.
#include
int a(int n)
{
int i,an=0;
for(i=1;i<=n;i++)
{
if(i%2==1)
an+=2*i-1;
else
an-=2*i-1;
}
return an;
}
main()
{
int n;
printf("please input n:");
scanf("%d",&n);
printf("a(n)=%d",a(n));
getch();
}
10.
#include
main()
{
int a[3][4]={{1,2,3,4}, {9,8,7,6}, {-10,10,-5,2}};
int i,j,max,maxi,maxj;
max=0;
maxi=0;
maxj=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(max {
max=a[i][j];
maxi=i;
maxj=j;
}
}
printf("maximum of the array is a[%d][%d]=%d",maxi,maxj,max);
getch();
}
11.
#include
main()
{
int i,n,num=0,sum=0;
int a[100];
printf("please input the number of the

students n=");
scanf("%d",&n);
for(i=0;i {
printf ("please input the NO.%d student's score",i+1);
scanf("%d",&a[i]);
if(a[i]>90)num++;
sum+=a[i];
}
printf("sum of the score is %d\nthe number of student whose score passed 90 is %d",sum,num);
getch();
}
12.
#include
main()
{
int f,g,x;
printf("please input the value of x:") ;
scanf("%d",&x);
g=2*x+1;
f=(g+1)/2;
printf("G(x)=%d\n",g);
printf("F(G(x))=%d\n",f);
getch();
}

回答2:

参考资料
http://hi.baidu.com/ttcc2009/blog/item/c2cc7195d20e2414d31b70af.html

回答3:

楼上强大,我正说写一下的,好多分呐
那我不写了

回答4:

答案已经发到邮箱了,记得给分哦

回答5:

第一题你没有说明白。

做了几个了,我先睡觉了,明天再帮你做。

完成的我放在下面的这个连接中了,