c语言第三次作业
‘壹’ C璇瑷鍑芥暟浣滀笟锛 閲嶈祻锛侊紒 鎸夎佹眰鍟婏紒锛 50鍒嗭紒
#include<stdio.h>
intwork(int*p,intn)
{inti,j,s=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(i==j||i+j==n-1)*(p+i*n+j)=0;
elses+=*(p+i*n+j);
returns;
}
intmain()
{intn=4,i,j,s;
inta[n][n];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
s=work(a[0],n);
printf("澶勭悊钖庣殑a鏁扮粍锛歕n");
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
printf("%4d",a[i][j]);
printf(" ");
}
printf("澶勭悊钖庣殑鏁扮粍鍏幂礌涔嫔拰=%d ",s);
return0;
}
‘贰’ c语言程序设计作业!!急!!
第一题:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int i,j, a,b, res, sum=0;
char ch;
printf("Now ready to answer!\nEvery question you have 3 chances to answer, first chance you answer right you can got 10, second got 7, third got 5. Otherwise can not got score!\n");
for(i=0; i<10; i++)
{
printf("%dth question:", i+1);
srand(time(NULL));
a = rand()%50;
b = rand()%(a>25?(50-a):a);
ch = rand()%2;
if(ch) ch='+';
else ch='-';
printf("%d %c %d = ", a, ch, b);
for(j=0; j<3; j++)
{
scanf("%d", &res);
if(ch=='+')
if(res==a+b){
printf("right!\n");
switch(j){
case 0: sum+=10;break;
case 1: sum+=7; break;
case 2: sum+=5; break;
}
break;
}
else{
printf("wrong!\n");
if(j!=2)printf("try again:");
}
else
if(res==a-b){
printf("right!\n");
switch(j){
case 0: sum+=10;break;
case 1: sum+=7; break;
case 2: sum+=5; break;
}
break;
}
else{
printf("wrong!\n");
if(j!=2)printf("try again:");
}
}
}
printf("your score is : %d\n", sum);
return 0;
}
‘叁’ C语言编程作业,求解答
作业1:result(int)= c (char) * i (int) + f (float) / d (double) -(f + i);
第一步:f+i, 一个float和int相加,按精度高的float进行计算,结果为float
result = char * int + float/double - float;
第二步:char * int, 他们都是整数相加为int
result =int + float/double - float;
第三步:float/double,按精度高的double进行计算结果为double
result =int + double - float;
第四步:int + double 结果为double
result =double - float;
第五步:double - float 结果为double,result为整形,赋值给整形会强制把double转化成int,保留整数。
作业二:
a=3, b=5
原因,swap的形参是值传递,实参传值给形参,子函数无法改变实参的值;要改变得传址。
作业三:
顺序查找法适应性好,可以适用在无序和有序数组查找;
折半查找法只适用于有序数组,无序查找会失败;但是在有序数组查找时查找效率高于顺序查找。
‘肆’ C语言习题
先看for语句
1、当i=9,满足i<=11的条件,接下来就做switch语句,9/10等于0(int整型自动取整),满足case 0的条件,做m++;n++;这时m为1,n为1
2、当i=10,满足i<=11的条件,接下来就做switch语句,10/10等于1,不满足所给的条件,做default: k++;n++;这时k为1,n为2
3、当i=11,满足i<=11的条件,接下来就做switch语句,11/10等于1,不满足所给的条件,做default: k++;n++;这时k为2,n为3
4、当i=12,不满足i<=11的条件,跳出整个循环,做pringf
最后输出结果为:1 3 2
‘伍’ C璇瑷浣滀笟 璁╁啓鍦ㄤ綔涓氭湰涓婄殑 姹傚ぇ 绁
绗涓娆′綔涓
锛1锛
鈶.缂栬緫浠g爜锛屾妸绋嫔簭浠g爜杈揿叆璁$畻链)銆
鈶$紪璇戞垚鐩镙囩▼搴忔枃浠.obj
鈶㈤摼鎺ユ垚鍙镓ц岀▼搴忔枃浠.exe
鈶h繍琛屽彲镓ц岀▼搴忔枃浠.exe
锛2锛
#include
<stdio.h>
intmain()
{printf("*********************** ");
printf("Verygood! ");
printf("*********************** ");
return0;
}
绗浜屾′綔涓氾细
锛1锛
锛1锛
#include<stdio.h>
main()
{charn1='C',n2='H',n3='I',n4='N',n5='A';
n1+=3;
n2+=3;
n3+=3;
n4+=3;
n5+=3;
printf("瀵嗙爜鏄%c%c%c%c%c",n1,n2,n3,n4,n5);
}
锛2锛
#include<stdio.h>
voidmain()
{
chararray[3];
for(inti=0;i<3;i++)
scanf("%c",&array[i]);
for(inti=2;i>=0;i--)
printf("%c",array[i]);
}