提交 4bb93a50 编写于 作者: Gongzi-Yu's avatar Gongzi-Yu

完成了第九章1-5题的编写,运行无误。

上级 a4016649
#include<stdio.h>
void exchange(int *pa,int *pb)
{
int t;
t = *pa; *pa = *pb; *pb = t;
}
int main()
{
int a, b, c,*pa,*pb,*pc;
scanf("%d,%d,%d", &a,&b,&c);
pa = &a; pb = &b; pc = &c;
if(a>b) exchange(pa,pb);
if(a>c) exchange(pa,pc);
if(b>c) exchange(pb,pc);
printf("%d\t%d\t%d\n",a,b,c);
return 0;
}
\ No newline at end of file
文件已添加
#include <stdio.h>
int main()
{
int a[10], *p=a;
for(int i=0; i<10; i++) scanf("%d",&a[i]);
for(int i=0; i<10; i++) if(*p>a[i]) p = &a[i];
for(int i=0; i<10; i++) printf("%d\t",a[i]);
printf("\nmin = %d",*p);
return 0;
}
\ No newline at end of file
文件已添加
#include <stdio.h>
int fsum(int *array,int n)
{
int i,s=0;
for(i=0;i<n;i++)
s += array[i];
return (s);
}
int main()
{
int a[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ,12, 13, 14, 15};
int shead, stail;
shead = fsum(a,10);
stail = fsum(&a[5], 10);
printf("%d,%d\n",shead,stail);
return 0;
}
\ No newline at end of file
文件已添加
#include <stdio.h>
void moveLeft(int *a, int n)
{
int *p = &a[n-1],b = a[n-1];
while(p != a)
{
int t;
t = b;
b = *(p-1);
*(p---1) = t;
}
a[n-1] = b;
}
void rotateLeft(int *a, int n, int k)
{
int i;
for(i = 0; i < k; i++) moveLeft(a,n);
}
int main()
{
int a[]={ 2, 3, 4, 5, 6, 7, 8, 9 };
int i, k;
printf("input k please: \n");
scanf("%d",&k);
for(i = 0; i < 8; i++) printf("%d\t",a[i]);
printf("\n");
rotateLeft(a,8,k);
for(i = 0; i < 8; i++) printf("%d\t",a[i]);
}
\ No newline at end of file
文件已添加
#include <stdio.h>
void statistic( int *a, int n, int *posinum_ptr, int *neganum_ptr)
{
int *p = a;
while(p != a+n)
{
if(*p > 0) (*posinum_ptr)++;
if(*p < 0) (*neganum_ptr)++;
p++;
}
}
int main()
{
int a[10];
int i,posi_num,nega_num;
for(i=0; i<10; i++) scanf("%d", &a[i]);
statistic(a, 10, &posi_num, &nega_num);
printf("posi_num: %d, nega_num: %d",posi_num,nega_num);
}
\ No newline at end of file
文件已添加
......@@ -24,6 +24,7 @@
<ProjectGuid>{2e2cb14a-5141-4136-9b14-56a832c31276}</ProjectGuid>
<RootNamespace>C语言课程设计</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>visualstudio2019</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册