//5.3
/*
1) 0
2) 1
3) 1
4) 0
5) 1
*/
//5.4见第一章的第二题
//5.5
/*
#include <stdio.h>
void main()
{
int x = 0;
int y = 0;
printf("Please input x value:\n");
scanf("%d",&x);
if(x < 1)
{
y = x;
}
else if(x >= 1 && x < 10)
{
y = 2*x-1;
}
else
{
y = 3*x-11;
}
printf("y = %d\n",y);
}
#include <stdio.h>
void main()
{
int GetY(int x);
int x = 0;
printf("Please input x value:\n");
scanf("%d",&x);
printf("y = %d\n",GetY(x));
}
int GetY(int x)
{
int y = 0;
if(x < 1)
{
y = x;
}
else if(x >= 1 && x < 10)
{
y = 2*x-1;
}
else
{
y = 3*x-11;
}
return y;
}
*/
//5.6
/*
#include <stdio.h>
void main()
{
void Print(float score);
float score = 0;
printf("please input your score:\n");
scanf("%f",&score);
Print(score);
}
void Print(float score)
{
if(score < 60 && score >= 0)
{
printf("E\n");
}
else if(score >= 60 && score < 70)
{
printf("D\n");
}
else if(score >= 70 && score < 80)
{
printf("C\n");
}
else if(score >= 80 && score < 90)
{
printf("B\n");
}
else if(score >= 90 && score <= 100)
{
printf("A\n");
}
}
#include <stdio.h>
void main()
{
float score = 0;
int choise = 0;
printf("Please input your score:\n");
scanf("%f",&score);
choise = (int)score/10;
switch(choise)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
printf("E\n");
break;
case 6:
printf("D\n");
break;
case 7:
printf("C\n");
break;
case 8:
printf("B\n");
break;
case 9:
printf("A\n");
break;
default :printf("输入有错误!\n");
break;
}
}*/
//5.7
/*
#include <stdio.h>
void main()
{
void Operater(int num);
int num = 0;
printf("请输入一个不超过5位的数字:\n");
scanf("%d",&num);
Operater(num);
}
void Operater(int num)
{
int gewei = num % 10;
int shiwei = num % 100 / 10;
int baiwei = num % 1000 / 100;
int qianwei = num % 10000 / 1000;
int wanwei = num / 10000;
//主要的判断方法,考虑到的是if - else 的执行形势,
//从万位开始像个位流向如果万位有数字那么就是万位数,要么就再往下看!
if(wanwei != 0)
{
printf("%d是个5位数:\n",num);
printf("%d\n%d\n%d\n%d\n%d\n",wanwei,qianwei,baiwei,shiwei,gewei);
printf("%d%d%d%d%d\n",gewei,shiwei,baiwei,qianwei,wanwei);
}
else if(qianwei != 0)
{
printf("%d是个4位数:\n",num);
printf("%d\n%d\n%d\n%d\n",qianwei,baiwei,shiwei,gewei);
printf("%d%d%d%d\n",gewei,shiwei,baiwei,qianwei);
}
else if(baiwei != 0)
{
printf("%d是个3位数:\n",num);
printf("%d\n%d\n%d\n",baiwei,shiwei,gewei);
printf("%d%d%d\n",gewei,shiwei,baiwei);
}
else if(shiwei != 0)
{
printf("%d是个2位数:\n",num);
printf("%d\n%d\n",shiwei,gewei);
printf("%d%d\n",gewei,shiwei);
}
else if(gewei != 0)
{
printf("%d是个1位数:\n",num);
printf("%d\n",gewei);
printf("%d\n",gewei);
}
}
#include <stdio.h>
void main()
{
int num = 0;
int gewei = 0;
int shiwei = 0;
int baiwei = 0;
int qianwei = 0;
int wanwei = 0;
printf("请输入一个不超过5位的数字:\n");
scanf("%d",&num);
if(num >= 10000 && num <= 99999)
{
printf("%d是个5位数字:\n",num);
gewei = num % 10;
shiwei = num % 100 / 10;
baiwei = num % 1000 / 100;
qianwei = num % 10000 / 1000;
wanwei = num / 10000;
printf("%d\n%d\n%d\n%d\n%d\n",wanwei,qianwei,baiwei,shiwei,gewei);
printf("%d%d%d%d%d\n",gewei,shiwei,baiwei,qianwei,wanwei);
}
else if(num >= 1000 && num <= 9999)
{
printf("%d是个4位数字:\n",num);
gewei = num % 10;
shiwei = num % 100 / 10;
baiwei = num % 1000 / 100;
qianwei = num / 1000;
printf("%d\n%d\n%d\n%d\n",qianwei,baiwei,shiwei,gewei);
printf("%d%d%d%d\n",gewei,shiwei,baiwei,qianwei);
}
else if(num >= 100 && num <= 999)
{
printf("%d是个3位数字:\n",num);
gewei = num % 10;
shiwei = num % 100 / 10;
baiwei = num / 100;
printf("%d\n%d\n%d\n",baiwei,shiwei,gewei);
printf("%d%d%d\n",gewei,shiwei,baiwei);
}
else if(num >= 10 && num <= 99)
{
printf("%d是个2位数字:\n",num);
gewei = num % 10;
shiwei = num / 10;
printf("%d\n%d\n",shiwei,gewei);
printf("%d%d\n",gewei,shiwei);
}
else if(num >= 1 && num <= 9)
{
printf("%d是个1位数字:\n",num);
gewei = num % 10;
printf("%d\n\n",gewei);
printf("%d\n",gewei);
}
}
#include <stdio.h>
void main()
{
int num = 0;
int gewei = 0;
int shiwei = 0;
int baiwei = 0;
int qianwei = 0;
int wanwei = 0;
int place = 0;
printf("请输入一个不超过5位的数字:\n");
scanf("%d",&num);
if(num >= 10000 && num <= 99999)
{
printf("%d是个5位数字:\n",num);
place = 5;
}
else if(num >= 1000 && num <= 9999)
{
printf("%d是个4位数字:\n",num);
place = 4;
}
else if(num >= 100 && num <= 999)
{
printf("%d是个3位数字:\n",num);
place = 3;
}
else if(num >= 10 && num <= 99)
{
printf("%d是个2位数字:\n",num);
place = 2;
}
else if(num >= 1 && num <= 9)
{
printf("%d是个1位数字:\n",num);
place = 1;
}
gewei = num % 10;
shiwei = num % 100 / 10;
baiwei = num % 1000 / 100;
qianwei = num % 10000 / 1000;
wanwei = num / 10000;
switch(place)
{
case 5:
printf("%d\n%d\n%d\n%d\n%d\n",wanwei,qianwei,baiwei,shiwei,gewei);
printf("%d%d%d%d%d\n",gewei,shiwei,baiwei,qianwei,wanwei);
break;
case 4:
printf("%d\n%d\n%d\n%d\n",qianwei,baiwei,shiwei,gewei);
printf("%d%d%d%d\n",gewei,shiwei,baiwei,qianwei);
break;
case 3:
printf("%d\n%d\n%d\n",baiwei,shiwei,gewei);
printf("%d%d%d\n",gewei,shiwei,baiwei);
break;
case 2:
printf("%d\n%d\n",shiwei,gewei);
printf("%d%d\n",gewei,shiwei);
break;
case 1:
printf("%d\n",gewei);
printf("%d\n",gewei);
break;
}
}
*/
//5.8
/*
#include <stdio.h>
void main()
{
float MyTiCheng(int l);
long lirun = 0;
float ticheng = 0;
printf("请输入利润值:\n");
scanf("%ld",&lirun);
ticheng = MyTiCheng(lirun);
printf("你可以提成%f\n",ticheng);
}
float MyTiCheng(int l)
{
float ticheng = 0.0;
if(l <= 100000)
{
ticheng = (float)(l * 0.1);
}
if(l > 100000 && l <= 200000)
{
ticheng = (float)(100000*0.1 + (l-100000)*0.075);
}
if(l > 200000 && l <= 400000)
{
ticheng = (float)(100000*0.1 + 100000*0.075 + (l-200000)*0.05);
}
if(l > 400000 && l <= 600000)
{
ticheng = (float)(100000*0.1 + 100000*0.075 + 200000*0.05 + (l-400000)*0.03);
}
if(l > 600000 && l <= 1000000)
{
ticheng = (float)(100000*0.1 + 100000*0.075 + 200000*0.05 + 200000*0.03 +
(l-600000) * 0.015);
}
if(l > 1000000)
{
ticheng = (float)(100000*0.1 + 100000*0.075 + 200000*0.05 + 200000*0.03 +
400000 * 0.015 + (l-1000000)*0.01);
}
return ticheng;
}
*/
//5.9
/*
#include <stdio.h>
void main()
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int t = 0;
printf("Please input frou numbers:\n");
scanf("%d %d %d %d",&a,&b,&c,&d);
if(a > b)
{
t = a;
a = b;
b = t;
}
if(a > c)
{
t = a;
a = c;
c = t;
}
if(a > d)
{
t = a;
a = d;
d = t;
}
if(b > c)
{
t = b;
b = c;
c = t;
}
if(b > d)
{
t = b;
b = d;
d = t;
}
if(c > d)
{
t = c;
c = d;
d = t;
}
printf("This numbers sort is %d %d %d %d\n",a,b,c,d);
}*/
/*/////////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
void main()
{
int a[4] = {0};
int temp = 0;
printf("Please input frou numbers:\n");
for(int i = 0; i < 4; i++)
{
scanf("%d",&a[i]);
}
for(i = 0; i < 4-1; i++)
{
for(int j = i; j < 4; j++)
{
if(a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(i = 0; i < 4; i++)
{
printf("%d ",a[i]);
}
printf("\n");
}*/
/*
#include <stdio.h>
void main()
{
void MySort(int *a, int *b);
int a = 0;
int b = 0;
int c = 0;
int d = 0;
printf("Please input frou numbers:\n");
scanf("%d %d %d %d",&a,&b,&c,&d);
//////////////////////////////////////
MySort(&a,&b);
MySort(&a,&c);
MySort(&a,&d);
MySort(&b,&c);
MySort(&b,&d);
MySort(&c,&d);
//////////////////////////////////////
printf("This numbers sort is %d %d %d %d\n",a,b,c,d);
}
void MySort(int *a, int *b)
{
int temp = 0;
if(*a > *b)
{
temp = *a;
*a = *b;
*b = temp;
}
}*/
//5.10
/*
#include <stdio.h>
struct Point1
{
int x;
int y;
}p1 = {-1,-1},
p2 = {1,1};
void main()
{
int h = 10;
float x,y;
printf("请输入你要查询的点的坐标:\n");
scanf("%f %f",&x,&y);
// printf("%d %d",);
if((x >= p1.x && x <= p2.x) && (y >= p1.y && y <= p2.y))
{
printf("H = %d\n",h);
}
else
{
printf("H = %d\n",0);
}
}*/
/*
#include <stdio.h>
void main()
{
int h = 10;
float x,y;
printf("请输入你要查询的点的坐标:\n");
scanf("%f %f",&x,&y);
if((x >= -1 && x <= 1) &&(y >= -1 && y <= 1))
{
printf("H = %d\n",h);
}
else
{
printf("H = %d\n",0);
}
}*/
//6.1输入两个正整数m和n 求其最大公约数和最小弓背数:
/*
#include <stdio.h>
void main()
{
int m = 0;
int n = 0;
int temp = 0;
printf("Please input m and n:\n");
scanf("%d %d",&m,&n);
if(m < n)
{
temp = m;
m = n;
n = temp;
}
for(int i = 2; i <= n; i++)
{
if(m % i == 0 && n % i == 0)
{
printf("最小公倍数是:%d\n",i);
break;
}
}
for(i = n; i >=1; i--)
{
if(m % i == 0 && n % i == 0)
{
printf("最大公倍数为%d:\n",i);
break;
}
}
}
#include <stdio.h>
int FindMax(int m, int n);
void main()
{
int ZuiXiaoGBS(int m, int n);
int ZuiDaGYS(int m, int n);
int m = 0;
int n = 0;
int zuiDaGYS = 0;
int zuiXiaoGBS = 0;
printf("请输入两个正整数m和n:\n");
scanf("%d %d",&m,&n);
zuiDaGYS = ZuiDaGYS(m,n);
zuiXiaoGBS = ZuiXiaoGBS(m,n);
printf("最小公倍数是:%d\n",zuiXiaoGBS);
printf("最大公倍数为%d:\n",zuiDaGYS);
}
int ZuiXiaoGBS(int m, int n)
{
int gongYueShu = 0;
int i = 0;
for(i = 2; i <= FindMax(m,n); i++)
{
if(m % i == 0 && n % i == 0)
{
break;
}
}
return i;
}
int ZuiDaGYS(int m, int n)
{
int gongyueshu = 0;
int i = 0;
for(i = FindMax(m,n); i >= 1; i--)
{
if(m % i == 0 && n % i == 0)
{
break;
}
}
return i;
}
int FindMax(int m, int n)
{
return ((m > n) ? m : n);
}*/
/*
#include <stdio.h>
void main()
{
int m = 0;
int n = 0;
int *p = 0;
int *q = 0;
int temp = 0;
p = &m;
q = &n;
printf("请输入两个正整数:\n");
scanf("%d %d",&m,&n);
if(m > n)
{
temp = *p;
*p = *q;
*q = temp;
}
for(int i = 2; i <= m; i++)
{
if(m % i == 0 && n % i == 0)
{
printf("最小公倍数是:%d\n",i);
break;
}
}
for(i = m; i >=1; i--)
{
if(m % i == 0 && n % i == 0)
{
printf("最大公倍数为%d:\n",i);
break;
}
}
}*/
//6.2 输入一行字符串统计其中英文字母,空格,数字、其他字符的数量:
/*
#include <stdio.h>
void main()
{
int countSpace = 0;
int countChar = 0;
int countInt = 0;
int countOthers = 0;
char c = ' ';
while((c = getchar()) != '\n')
{
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
countChar++;
}
else if(c >= '0' && c <= '9')
{
countInt++;
}
else if(c == ' ')
{
countSpace++;
}
else
{
countOthers++;
}
}
printf("字母的数量是:%d\n",countChar);
printf("数字的数量是:%d\n",countInt);
printf("空格的数量是:%d\n",countSpace);
printf("其他字符的数量是:%d\n",countOthers);
}
#include <stdio.h>
void main()
{
int countSpace = 0;
int countChar = 0;
int countInt = 0;
int countOthers = 0;
char c = ' ';
char strArray[20] = "";
int i = -1;
int NI = 0;
gets(strArray);
//用来计算到字符数组的长度!
while(1)
{
i++;
if(strArray[i] == '\0')
{
NI = i;
break;
}
}
//用来判断是什么字符,然后相应的计数器加一!
for(i = 0; i < NI; i++)
{
c = strArray[i];
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
countChar++;
}
else if(c >= '0' && c <= '9')
{
countInt++;
}
else if(c == ' ')
{
countSpace++;
}
else
{
countOthers++;
}
}
printf("字母的数量是:%d\n",countChar);
printf("数字的数量是:%d\n",countInt);
printf("空格的数量是:%d\n",countSpace);
printf("其他字符的数量是:%d\n",countOthers);
}*/
//6.3求s(n) = a + aa + aaa.....n, a由键盘输入,
/*
#include <stdio.h>
void main()
{
int n = 0;
int a = 0;
int sum = 0;
int temp = 1;
printf("请输入a和n:\n");
scanf("%d %d",&a,&n);
for(int i = 0; i < n; i++)
{
temp *= i*10 +1;
sum += a * temp;
}
printf("sum = %d\n",sum);
}
#include <stdio.h>
void main()
{
int a = 0;
int n = 0;
int temp = 0;
int sum = 0;
printf("请输入a和n得值:\n");
scanf("%d %d",&a,&n);
for(int i = 0;i < n; i++)
{
temp = temp + a;
sum += temp;
temp *= 10;
}
printf("sum = %d\n",sum);
}*/
//6.4 求sum = 1! + 2! + 3! +.......其中有n个,n 由键盘输入
/*
#include <stdio.h>
void main()
{
int n = 0;
int sum = 0;
printf("请输入n得值:\n");
scanf("%d",&n);
for(int i = 1; i <= n; i++)
{
int temp = 1;
for(int j = 1; j <= i; j++)
{
temp *= j;
}
printf("%d\n",temp);
sum += temp;
}
printf("sum = %d\n",sum);
}*/
/*
#include <stdio.h>
int Sum(int m);
int JieCheng(int n);
void main()
{
int n = 0;
int sum = 0;
printf("请输入n得值:\n");
scanf("%d",&n);
for(int i = 1; i <= n; i++)
{
sum += Sum(JieCheng(i));
}
printf("sum = %d:\n",sum);
}
int JieCheng(int n)
{
int temp = 1;
for(int i = 1; i <= n; i++)
{
temp *= i;
}
return temp;
}
int Sum(int m)
{
int sum = 0;
sum += m;
return sum;
}
*/
//6.5
/*
#include <stdio.h>
void main()
{
float sum1 = 0;
float sum2 = 0;
float sum3 = 0;
for(int i = 1; i <= 100; i++)
{
sum1 += i;
}
for(i = 1; i <= 50; i++)
{
sum2 += i * i;
}
for(i = 1; i <= 10; i++)
{
sum3 += (float)(1.0 / (float)i);
}
printf("sum = %f\n",sum1 + sum2 + sum3);
}*/
//6.6打印水仙花数:
/*
#include <stdio.h>
void main()
{
int gewei = 0;
int shiwei = 0;
int baiwei = 0;
for(int i = 100; i <= 999; i++)
{
gewei = i % 10;
shiwei = i % 100 / 10;
baiwei = i / 100;
if(i == gewei*gewei*gewei+shiwei*shiwei*shiwei
+baiwei*baiwei*baiwei)
{
printf("%d是水仙花数:\n",i);
}
}
}*/
/*
#include <stdio.h>
void main()
{
for(int i = 1; i <= 9; i++)
{
for(int j = 0; j <= 9; j++)
{
for(int k = 0; k <= 9; k++)
{
if(i*i*i + j*j*j + k*k*k == 100*i+10*j+k)
{
printf("%d是水仙花数:\n",100*i+10*j+k);
}
}
}
}
}*/
//6.7一个数如果等于他的因子之和那么这个数就数一个完数,打印1000以内的完数
/*//
#include <stdio.h>
#include <math.h>
void main()
{
int i = 0;
int j = 0;
for(i = 1; i <= 1000; i++)
{
int temp = 0;
for(j = 1; j < i; j++)
{
if(i % j == 0)
{
temp += j;
}
}
if(i == temp)
{
printf("%d是个完数\n",i);
printf("因子数为:");
for(int k = 1; k < i; k++)
{
if(i % k == 0)
{
printf("%d ",k);
}
}
printf("\n");
}
}
}*/
////////////////////////////////////////////////////////////////////////
/*
#include <stdio.h>
void main()
{
for(int i = 1, k = 0; i <= 1000; i++)
{
int a[11] = {0};
int temp = 0;
for(int j = 2; j < i; j++)
{
if(i % j == 0)
{
a[k] = j;
temp += j;
k++;
}
}
if(i == temp)
{
printf("%d是一个完数:",i);
}
for(int m = 0; m <= k; m++)
{
printf("%d",a[m]);
}
printf("\n");
}
}*/
////////////////////////////////////////////////////////////////////
//6.8 求前二十项的和2/1 + 3/2 + 5/3 + 8/5
/*
#include <stdio.h>
void main()
{
int fenzi = 2;
int fenmu = 1;
double sum = fenzi/fenmu;
for(int i = 1; i < 20; i++)
{
fenzi = fenmu + fenzi;
fenmu = fenzi - fenmu;
sum += (double)(fenzi/(double)fenmu);
}
printf("Sum = %f\n",sum);
}
*/
/*
#include <stdio.h>
void main()
{
float a = 2,b=1;
float sum = 0, t = 0;
for(int i = 0; i < 20; i++)
{
sum += (a/b);
t = a;
a = a+b;
b = t;
}
printf("Sum = %f\n",sum);
}*/
//6.9一球从100m高处落下,每次落地后反跳回原来高度的一半,再落下,求在第10次落地时共经过了多少m?
//反弹多高?
/*
#include <stdio.h>
#define N 10
void main()
{
float height = 100;
float length = 100;
float sumLength = 0;
for(int i = 1; i < N; i++)
{
height /= 2;
length += (height * 2);
}
height /= 2;
printf("总经过路程为:%f\n",length);
printf("第十次弹的高度为:%f\n",height);
}*/
//6.10猴子吃桃子的问题,第一天吃了摘得桃子总数的一半又多吃了一个,
//以后一直是吃掉前一天的一半加一个,到第十天发现只剩下一个桃子了,
//求第一天的时候摘了多少个桃子!
/*
#include <stdio.h>
void main()
{
int x = 1;
for(int i = 1; i < 10; i++)
{
x = (x+1)*2;
}
printf("Sum = %d",x);
}
*/
/*
#include <stdio.h>
void main()
{
int Add(int n);
int sum = 0;
printf("Sum = %d\n",Add(1));
}
int Add(int n)
{
int sum = 0;
if(n == 10)
{
sum = 1;
}
else
{
sum = (Add(n+1)+1)*2;
}
return sum;
}*/
//6.14打印一个菱形
/*
#include <stdio.h>
void main()
{
for(int i = 1; i <= 4; i++)
{
for(int j = 1; j <= 8-2*i; j++)
{
printf(" ");
}
for(int k = 1; k <= 2*i-1; k++)
{
printf("* ");
}
printf("\n");
}
for(i = 1; i <= 3; i++)
{
for(int j = 1; j <= 2*i; j++)
{
printf(" ");
}
for(int k = 1; k <= 7-2*i;k++)
{
printf("* ");
}
printf("\n");
}
}*/
//6.15两队乒乓球比赛,各出三人,甲队A,B,C已队X,Y,Z抽完签后,A说他不和X比赛
//C说他不和X,Z比赛!
/*
#include <stdio.h>
void main()
{
for(char a = 'X'; a <= 'Z'; a++)
{
for(char b = 'X'; b <= 'Z'; b++)
{
for(char c = 'X'; c <= 'Z'; c++)
{
if(a != b && b != c && a != c)
{
if(a != 'X' && c != 'X' && c != 'Z')
{
printf("A<--> %c\n",a);
printf("B<--> %c\n",b);
printf("C<--> %c\n",c);
}
}
}
}
}
}*/
//7.1用筛选法求100以内的素数!
/*////////////通过这种方法以后可以求报数问题,报三就向后推出!
#include <stdio.h>
#include <math.h>
void main()
{
int a[101] = {0};
for(int i = 1; i <= 100; i++)
{
a[i] = i;
}
for(int j = 1; j <= 100; j++)
{
for(i = 2; i <= sqrt(j); i++)
{
if(a[i] != 0 && a[j] != 0)
{
if(a[j] % a[i] == 0)
{
a[j] = 0;
}
}
}
}
for(i = 2; i <= 100; i++)
{
if(a[i] != 0)
{
printf("%d ",a[i]);
}
}
printf("\n");
}*/
//7.2用筛选法对十个整数排序(小到大)
/*
#include <stdio.h>
#define N 10
void main()
{
int num[N] = {0};
printf("请输入你要排序的十个整数:\n");
for(int i = 0; i < N; i++)
{
scanf("%d",&num[i]);
}
for(i = 0; i< N; i++)
{
int temp = 0;
for(int j = i+1; j < N; j++)
{
if(num[i] > num[j])
{
temp = num[i];
num[i] = num[j];
num[j] = temp;
}
}
}
for(i = 0; i < N; i++)
{
printf("%d ",num[i]);
}
printf("\n");
}
*/
//7.3求一个 3 * 3 矩阵的对角线和
/*
#include <stdio.h>
#define N 3
void main()
{
int juZhen[N][N] = {0};
int sum = 0;
printf("请输入9个数字:\n");
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
scanf("%d",&juZhen[i][j]);
}
}
for(i = 0; i < N; i++)
{
sum += juZhen[i][i];
}
printf("Sum = %d\n",sum);
}
*/
//7.4有一个已经排好序的数组,今输入一个数字,插入数组并且保持顺序不变
/*
#include <stdio.h>
#define N 10
void main()
{
int num[N] = {1,4,6,9,13,16,19,28,40,100};
int num2[N+1] = {0};
int newNum = 0;
int tempI = 0;
printf("请输入一个你要插入的数字:\n");
scanf("%d",&newNum);
for(int i = 0; i < N; i++)
{
num2[i] = num[i];
}
num2[N] = 0;
for(i = 0; i < N; i++)
{
if(num2[i] >= newNum)
{
tempI = i;
break;
}
}
for(i = N-1; i >= tempI; i--)
{
num2[i+1] = num2[i];
}
num2[tempI] = newNum;
for(i = 0; i <= N; i++)
{
printf("%d ",num2[i]);
}
printf("\n");
}*/
/*
#include <stdio.h>
#define N 10
void main()
{
int num[N] = {1,4,6,9,13,16,19,28,40,100};
int num2[N+1] = {0};
int newNum = 0;
int temp = 0;
printf("请输入一个你要插入的数字:\n");
scanf("%d",&newNum);
for(int i = 0; i < N; i++)
{
num2[i] = num[i];
}
num2[N] = newNum;
for(i = 0; i <= N; i++)
{
for(int j = 1; j <= N-i; j++)
{
if(num2[j-1] >= num2[j])
{
temp = num2[j-1];
num2[j-1] = num2[j];
num2[j] = temp;
}
}
}
for(i = 0; i <= N; i++)
{
printf("%d ",num2[i]);
}
printf("\n");
}*/
//7.5将一个数组按逆序输出
/*
#include <stdio.h>
#define N 5
void main()
{
int num[N] = {0};
int temp = 0;
printf("请输入5个数字作为一个数组:\n");
for(int i = 0; i < N; i++)
{
scanf("%d",&num[i]);
}
for(i = 0; i < N/2; i++)
{
temp = num[i];
num[i] = num[N-i-1];
num[N-i-1] = temp;
}
for(i = 0; i < N; i++)
{
printf("%d ",num[i]);
}
printf("\n");
}*/
//7.6打印杨辉三角(打印十行)
/*
#include <stdio.h>
#define N 10
void main()
{
int a[N][N] = {0};
a[0][0] = 1;
a[1][0] = 1;
a[1][1] = 1;
for(int i = 2; i < N; i++)
{
a[i][0] = 1;
a[i][i] = 1;
for(int j = 1; j < N-1; j++)
{
a[i][j] = a[i-1][j-1] + a[i-1][j];
}
}
for(i = 0; i < N; i++)
{
for(int j = 0; j <= i; j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
}*/
//7.7打印魔方阵
//7.10有一篇文章,共三行,每行80个字符,统计大写字母,小写字母的个数,数字空格和其他字符的个数
/*
#include <stdio.h>
void main()
{
char a[3][80];
int numSpace = 0;
int numBigChar = 0;
int numSmallChar = 0;
int numInt = 0;
int numOthers = 0;
for(int i = 0; i < 3; i++)
{
printf("Please input %d line :",i+1);
gets(a[i]);
for(int j = 0; j < 80 && a[i][j] != '\0'; j++)
{
if(a[i][j] >= 'A' && a[i][j] <= 'Z')
{
numBigChar++;
}
else if(a[i][j] >= 'a' && a[i][j] <= 'z')
{
numSmallChar++;
}
else if(a[i][j] >= '0' && a[i][j] <= '9')
{
numInt++;
}
else if(a[i][j] == ' ')
{
numSpace++;
}
else
{
numOthers++;
}
}
}
printf("Upper case: %d\n",numBigChar);
printf("lower case: %d\n",numSmallChar);
printf("digit case: %d\n",numInt);
printf("space case: %d\n",numSpace);
printf("other case: %d\n",numOthers);
}*/
//7.11打印一个图形
/*
#include <stdio.h>
void main()
{
for(int i = 0; i <= 5; i++)
{
for(int j = 0; j <= i; j++)
{
printf(" ");
}
for(int k = 0; k < 5; k++)
{
printf("* ");
}
printf("\n");
}
}*/
/*
#include <stdio.h>
void main()
{
char a[5] = {'*','*','*','*','*'};
for(int i = 0; i < 5; i++)
{
for(int j = 0; j <= i; j++)
{
printf(" ");
}
for(int k = 0; k < 5; k++)
{
printf("%c ",a[i]);
}
printf("\n");
}
}*/
//7.12编码,前面已经做过!
//7.13编写一个函数代替strcat();
/*
#include <stdio.h>
void main()
{
char a[20] = "Very ,";
char b[10] = "Good!";
int iTemp = 0;
int iTemp2 = 0;
for(int i = 0; i < 20; i++)
{
if(a[i] == '\0')
{
iTemp = i;
break;
}
}
for(i = 0; i < 10; i++)
{
if(b[i] == '\0')
{
iTemp2 = i;
break;
}
}
int j = 0;
for(i = iTemp; i < 20 && j <= iTemp2;i++,j++)
{
a[i] = b[j];
}
puts(a);
}*/
//7.14实现strcmp
/*
#include <stdio.h>
void main()
{
char a[20] = "";
char b[20] = "";
int iTemp1 = 0;
int iTemp2 = 0;
printf("请输入第一个字符串:\n");
gets(a);
printf("请输入第二个字符串:\n");
gets(b);
for(int i = 0; i < 20; i++)
{
if(a[i] == '\0')
{
iTemp1 = i;
break;
}
}
for(i = 0; i < 20; i++)
{
if(b[i] == '\0')
{
iTemp2 = i;
break;
}
}
for(i = 0; i < iTemp2 && i < iTemp1; i++)
{
if(a[i] > b[i])
{
printf("String A > String B\n");
break;
}
else if(a[i] < b[i])
{
printf("String A < String B\n");
break;
}
else
{
}
}
if(i == iTemp2 || i == iTemp1)
{
if(iTemp1 > iTemp2)
{
printf("String A > String B\n");
}
else if(iTemp1 < iTemp2)
{
printf("String A < String B\n");
}
else
{
printf("String A = String B\n");
}
}
}
*/
/*//////////////////////////////////////////谭好强的缺点//////////////////////////
#include <stdio.h>
void main()
{
char a[20] = "";
char b[20] = "";
printf("请输入第一个字符串:\n");
gets(a);
printf("请输入第二个字符串:\n");
gets(b);
int i = 0;
while((a[i] == b[i]) && a[i] != '\0')
i++;
if(a[i] != '\0' && b[i] != '\0')
{
printf("%d \n",a[i] - b[i]);
}
}
////////////////////////////////////////例如i love 与 i loves////////////////////////
*/
//7.15实现strcpy()
/*
#include <stdio.h>
void main()
{
char a[20] = "";
char b[100] = "";
int iTemp = 0;
printf("请输入一个字符串:\n");
gets(a);
for(int i = 0; i < 20; i++)
{
if(a[i] == '\0')
{
iTemp = i;
break;
}
}
for(i = 0; i < iTemp; i++)
{
b[i] = a[i];
}
b[iTemp] = '\0';
printf("b 为:");
puts(b);
}*/
//8.1前面做过
//8.2求方程的根的问题:
/*
#include <stdio.h>
#include <math.h>
void main()
{
double x1 = 0,x2 = 0,a = 0,b = 0,c = 0;
printf("请输入三个数字关于a,b,c:\n");
scanf("%d %d %d",&a,&b,&c);
if(b*b - 4*a*c == 0)
{
x1 = x2 = (-b)/(2 * a);
printf("x1 = x2 = %f",x1);
}
else if(b*b - 4*a*c > 0)
{
x1 = (-b + sqrt(b*b - 4*a*c));
x2 = (-b - sqrt(b*b - 4*a*c));
printf("x1 = %f\nx2 = %f\n",x1,x2);
}
else
{
printf("没得结果!\n");
}
}*/
//8.3写一个判断素数的函数,在主函数中输入个数字径行判断是否为素数!
/*
#include <stdio.h>
#include <math.h>
void main()
{
void IsOrNo(int n);
int num = 0;
printf("请输入你要判断的数字:\n");
scanf("%d",&num);
IsOrNo(num);
}
void IsOrNo(int n)
{
int j = 0;
for(j = 2; j <= (int)sqrt(n); j++)
{
if(n % j == 0)
{
break;
}
}
if(j == (int)sqrt(n) + 1)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
*/
//8.4把3*3 的矩阵转换行和列
/*
#include <stdio.h>
void main()
{
int a[3][3] = {1,2,3,4,5,6,7,8,9};
int temp = 0;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("\n\n");
for(i = 0; i < 3; i++)
{
for(int j = 0; j <= i; j++)
{
temp = a[i][j];
a[i][j] = a[j][i];
a[j][i] = temp;
}
}
for(i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
}*/
//8.5输入一行字符串,按反序存放,在主函数中输入与输出!
/*
#include <stdio.h>
#include <string>
void main()
{
void reSet(char a[], int n);
char strArray[20] = "";
printf("请输入一行字符串:\n");
gets(strArray);
reSet(strArray,strlen(strArray));
puts(strArray);
}
void reSet(char a[], int n)
{
char temp = ' ';
for(int i = 0; i < n/2; i++)
{
temp = a[i];
a[i] = a[n-1-i];
a[n-1-i] = temp;
}
}*/
//8.6编写个函数用于字符串的连接
/*
#include <stdio.h>
#include <string.h>
void main()
{
void AddString(char a[],int n,char b[],int m);
char a[50] = "";
char b[20] = "";
printf("请输入第一个字符串:\n");
gets(a);
printf("请输入第二个字符串:\n");
gets(b);
AddString(a,strlen(a),b,strlen(b));
printf("输出后的数组a 为:\n");
puts(a);
}
void AddString(char a[],int n,char b[],int m)
{
for(int i = 0; i < m; i++)
{
a[n+i] = b[i];
}
}
*/
/*
#include <stdio.h>
#include <string.h>
void main()
{
void AddString(char *p,int n,char *q,int m);
char a[50] = "";
char b[20] = "";
printf("请输入第一个字符串:\n");
gets(a);
printf("请输入第二个字符串:\n");
gets(b);
AddString(a,strlen(a),b,strlen(b));
printf("输出后的数组a 为:\n");
puts(a);
}
void AddString(char *p,int n,char *q,int m)
{
for(int i = 0; i < m; i++)
{
*(p+n+i) = *(q+i);
}
}
*/
//8.7写一个函数将一个字符串中的元音字母拷贝到另外一个数组,然后输出。
/*
#include <stdio.h>
#include <string.h>
void main()
{
void Research(char a[],char b[],int n);
char a[20] = "";
char b[20] = "";
printf("请输入一个字符串:\n");
gets(a);
Research(a,b,strlen(a));
printf("输出b 为:\n");
puts(b);
}
void Research(char a[],char b[],int n)
{
char c = ' ';
for(int i = 0,j = 0; i < n; i++)
{
c = a[i];
switch(c)
{
case 'a':
case 'A':
case 'o':
case 'O':
case 'e':
case 'E':
case 'u':
case 'U':
case 'i':
case 'I':
b[j] = c;
j++;
break;
default:
break;
}
}
}*/
/*//////////////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <string.h>
char b[20] = ""; //为什么放在函数中就不起作用了呢?
void main()
{
char * Research(char a[],int n);
char a[20] = "";
printf("请输入一个字符串:\n");
gets(a);
printf("输出b 为:\n");
puts(Research(a,strlen(a)));
}
char * Research(char a[],int n)
{
char c = ' ';
//char b[20] = ""; //为什么放在函数中就不起作用了呢?
char *p = 0;
int i = 0;
int j = 0;
for(i = 0,j = 0; i < n; i++)
{
c = a[i];
switch(c)
{
case 'a':
case 'A':
case 'o':
case 'O':
case 'e':
case 'E':
case 'u':
case 'U':
case 'i':
case 'I':
b[j] = c;
j++;
break;
default:
break;
}
}
b[j] = '\0';
p = b;
return p;
}*////////////////////////////////////////////////////////////////////////////
//8.8 输入4个数字,输出这四个数字字符要求每个字符间有个空格,如输入1999输出1 9 9 9;
/*
#include <stdio.h>
#include <string.h>
void main()
{
void Insert(char a[], int n);
char num[20] = "";
printf("请输入四个数字:\n");
gets(num);
Insert(num,strlen(num));
printf("输出的结果为:\n");
puts(num);
}
void Insert(char a[], int n)
{
for(int i = n; i > 0; i--)
{
a[i*2] = a[i];
a[i*2-1] = ' ';
}
}
*/
//写个函数统计空格,字母,数字,其他字符的个数
/*
#include <stdio.h>
#include <string.h>
int letterCount,digitCount,spaceCount,otherCount;
void main()
{
void Count(char a[], int n);
char str[20] = "";
printf("请输入一个字符串:\n");
gets(str);
Count(str,strlen(str));
printf("letter = %d\ndigit = %d\nspace = %d\nother = %d\n",
letterCount,digitCount,spaceCount,otherCount);
}
void Count(char a[], int n)
{
for(int i = 0; i < n; i++)
{
if((a[i]>='a' && a[i]<='z') || (a[i]>='A' && a[i]<='Z'))
{
letterCount++;
}
else if(a[i] >= '0' && a[i] <= '9')
{
digitCount++;
}
else if(a[i] == ' ')
{
spaceCount++;
}
else
{
otherCount++;
}
}
}*/
//8.10写一个函数,输入一行自付,将里面最长的一个单词输出
/*
#include <stdio.h>
#include <string.h>
int IsWord(char c)
{
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
return 1;
}
else
{
return 0;
}
}
int longest(char string[])
{
int len = 0,length = 0,flag = 1,place = 0,point,n = strlen(string);
for(int i = 0; i <= n; i++)
{
if(IsWord(string[i]))
{
if(flag)
{
point = i;
flag = 0;
}
else
len++;
}
else
{
flag = 1;
if(len >= length)
{
length = len;
place = point;
len = 0;
}
}
}
return place;
}
void main()
{
int i = 0;
char str[20] = "";
printf("请输入一个字符串:\n");
gets(str);
printf("最长的单词是:\n");
for(i = longest(str);IsWord(str[i]);i++)
{
printf("%c",str[i]);
}
printf("\n");
}*/
//8.11写一个函数,用冒泡法对十个字符排序由小到大
/*
#include <stdio.h>
#include <string.h>
void main()
{
void Sort(char a[] ,int n);
char str[20] = "";
printf("输入十个字符:\n");
gets(str);
Sort(str,strlen(str));
printf("排序后的字符串为:\n");
puts(str);
}
void Sort(char a[] ,int n)
{
for(int i = 0; i < n; i++)
{
char c = ' ';
for(int j = n-1; j > i; j--)
{
if(a[j] < a[j-1])
{
c = a[j];
a[j] = a[j-1];
a[j-1] = c;
}
}
}
}*/
//8.12用牛顿迭代法求根,方程为:a*x*x*x + b*x*x + c*x + d = 0;a,b,cd依次为:1,2,3,4
//求在1附近的一个根。
/*
#include <stdio.h>
#include <math.h>
void main()
{
float solut(float a, float b,float c,float d);
float a,b,c,d;
printf("请输入a,b,c,d:\n");
scanf("%d %d %d %d",&a,&b,&c,&d);
printf("\nX = %f\n",solut(a,b,c,d));
}
float solut(float a, float b,float c,float d)
{
float x = 1,x0,f,f1;
do
{
x0 = x;
f = ((a * x0 + b)*x0 + c)*x0 + d;
f1 = (3 * a * x0 + 2 * b) * x0 + c;
x = x0 - f/f1;
}
while(fabs(x-x0) >= 1e-3);
return x;
}*/
//8.13用递归调用法求n阶勒让德多项式的值,
/*
#include <stdio.h>
int x = 0;
void main()
{
float p(int n);
int n;
printf("请输入x 和 n 的值:\n");
scanf("%d %d",&n,&x);
printf("f = %f\n",p(n));
}
float p(int n)
{
float y = 0.0;
if(n == 0)
{
y = 1;
}
else if(n == 1)
{
y = (float)x;
}
else
{
y = ((2*n - 1)*x*p(x-1)-(n-1)*p(x-2))/2;
}
return y;
}*/
//8.14输入10个同学5门成绩求1)每个同学的平均成绩2)每门课程的平均成绩3)最高分数对应的学生和课程
//4)求平均分差。
/*
#include <stdio.h>
#define N 5
#define M 10
int line,row;
float avg_stu(float a[][N],int n);
float avg_keCheng(float a[][N],int n);
float hight(float a[][N]);
float FangCha(float a[][N]);
void main()
{
float num[M][N] = {0};
float gaofen = 0;
printf("请输入10各同学5门课程的成绩\n");
for(int i = 0; i < M; i++)
{
for(int j = 0; j < N; j++)
{
scanf("%f",&num[i][j]);
}
}
for(i = 0; i < M; i++)
{
printf("%d名同学的平均成绩%f\n",i,avg_stu(&num[0],i));
}
for(i = 0; i < N; i++)
{
printf("%d门学科的平均成绩%f\n",i,avg_keCheng(&num[0],i));
}
gaofen = hight(&num[0]);//不能直接写在下面的printf()中,printf()好像是从坐往右运算;
printf("最高分为:%f,第%d个同学,第%d门学科\n",gaofen,line,row);
printf("方差为%f\n",FangCha(&num[0]));
}
float avg_stu(float a[][N],int n)
{
float sum = 0,avg = 0;
for(int i = 0; i < N; i++)
{
sum += a[n][i];
}
avg = sum / N;
return avg;
}
float avg_keCheng(float a[][N],int n)
{
float sum = 0, avg = 0;
for(int i = 0; i < M; i++)
{
sum += a[i][n];
}
avg = sum / M;
return avg;
}
float hight(float a[][N])
{
float high = a[0][0];
for(int i = 0; i < M; i++)
{
for(int j = 0; j < N; j++)
{
if(high < a[i][j])
{
high = a[i][j];
line = i+1;
row = j+1;
}
}
}
return high;
}
float FangCha(float a[][N])
{
int i = 0;
int j = 0;
float sumx = 0,sumnx = 0;
for(i = 0; i < N; i++)
{
sumx += avg_stu(&a[0],i)*avg_stu(&a[0],i);
sumnx += avg_stu(&a[0],i);
}
return (sumx/N-(sumnx/N)*(sumnx/N));
}*/
//8.15写几个函数1)输入10个员工的编号和姓名2)按编号排序注意姓名与编号对应
//3)再主函数中输入一格编号输出对应的姓名:
/*
#include <stdio.h>
#include <string.h>
#define N 10
void Insert(int num[], char name[N][20]);
void display(int num[],char name[][20], int n);
void Sort(int num[], char name[][20]);
void main()
{
int num[N] = {0};
char name[N][20];
int n = 0;
Insert(num,&name[0]);
printf("\n\n");
Sort(num,&name[0]);
printf("\n\n您要显示编号是:\n");
scanf("%d",&n);
display(num,&name[0],n);
}
void Insert(int num[], char name[N][20])
{
for(int i = 0; i < N; i++)
{
printf("请输入第%d个员工的编号与姓名:\n",i+1);
scanf("%d",&num[i]);
gets(name[i]);
}
}
void Sort(int num[], char name[][20])
{
for(int i = 0; i < N; i++)
{
int temp = 0;
char nameTemp[20] = "";
for(int j = 0; j < N-i; j++)
{
if(num[j] > num[j+1])
{
temp = num[j];
num[j] = num[j+1];
num[j+1] = temp;
strcpy(nameTemp,name[j]);
strcpy(name[j],name[j+1]);
strcpy(name[j+1],nameTemp);
}
}
}
for(i = 0; i < N; i++)
{
printf("%d",num[i]);
puts(name[i]);
}
}
void display(int num[],char name[][20], int n)
{
int i = 0;
for(i = 0; i < N; i++)
{
if(num[i] == n)
{
break;
}
}
if(i == N)
{
printf("没有找到\n");
}
else
{
printf("%d ",num[i]);
puts(name[i]);
}
}*/
//写一个函数,将16精制转换成10禁制
/*
#include <stdio.h>
void main()
{
int HToI(char a[]);
char c = ' ';
char letter[] = "";
int i = 0;
for(i = 0; (c = getchar()) != '\0'; i++)
{
if(c >= '0' && c <= '9' || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
{
letter[i] = c;
}
else
{
break;
}
}
printf("%d\n",HToI(letter));
}
int HToI(char a[])
{
int m = 0;
for(int i = 0; a[i] != '\0'; i++)
{
if(a[i] >= '0' && a[i] <= '9')
{
m = m * 16 + a[i] - '0';
}
if(a[i] >= 'a' && a[i] <= 'f')
{
m = m * 16 + a[i] - 'a' + 10;
}
if(a[i] >= 'A' && a[i] <= 'F')
{
m = m * 16 + a[i] - 'A' + 10;
}
}
return m;
}*/
//8.17用递归法将数字转换成字符串:例如483 “483”
/*
#include <stdio.h>
void main()
{
void f(int n);
int num = 0;
printf("请输入num的值:\n");
scanf("%d",&num);
f(num);
printf("\n");
}
void f(int n)
{
int i;
if((i = n / 10) != 0)
{
f(i);
}
putchar(n%10+'0');
}
*/
//8.18给个年月日求是该年低级天,以前写过查看前几章习题!
//9.1定义一个带参数的宏使两个参数交换
/*
#include <stdio.h>
#define SORT(a,b) t = a;a = b; b = t
void main()
{
int t = 0;
int a , b;
printf("请输入a,b得值:");
scanf("%d %d",&a,&b);
SORT(a,b);
printf("a = %d, b = %d",a,b);
} */
//9.2用带参的宏来实现求一个数的余数
/*
#include <stdio.h>
#define N(a,b) a%b
void main()
{
int a = 0,b = 0;
printf("请输入a,b得值\n");
scanf("%d %d",&a,&b);
printf("余数为:%d\n",N(a,b));
}*/
//9.3求三角形的面积
/*
#include <stdio.h>
#include <math.h>
#define S (a+b+c)/2
#define AREA sqrt(S*(S-a)*(S-b)*(S-c))
void main()
{
int a,b,c;
printf("请输入a,b,c的值:\n");
scanf("%d %d %d",&a,&b,&c);
printf("面积为:%.2f\n",AREA);
}*/
//9.4输入一个年份判断是否为闰年
/*
#include <stdio.h>
#define N(a) ((a % 4 == 0 && a % 100 != 0) || (a % 400 == 0))
void main()
{
int year = 0;
printf("请输入一个年份:\n");
scanf("%d",&year);
if(N(year))
{
printf("%d 是闰年\n",year);
}
else
{
printf("%d 不是闰年\n",year);
}
}*/
//9.6编写个宏用来控制,一行输出1个,2个,3个实数,且都为6.2f
/*
#include <stdio.h>
#define N "\n"
#define ONE "%6.2f" N
#define TWO ONE ONE
#define THREE TWO ONE
void main()
{
double a = 656.21354;
printf(ONE,a);
printf(TWO,a,a);
printf(THREE,a,a,a);
}
*/
//9.7设计出实数,整数,字符串的输出格式
/*
/////////////format.h//////////
#define D "%d\n"
#define F "%f\n"
#define S "%s\n"
/////////////////////////////
#include <stdio.h>
#include "format.h"
void main()
{
int a = 9;
double f = 9.999876;
char str[] = "Hello World";
printf(D,a);
printf(F,f);
printf(S,str);
}
*/
//9.8分别用函数和带参的宏,从3个数中找出最大数
/*
#include <stdio.h>
#define MAX(a,b,c) ((a>b)?((a>c)?a:c):((b>c)?b:c))
void main()
{
int num1 = 0;
int num2 = 0;
int num3 = 0;
printf("Please input three numbers:\n");
scanf("%d %d %d",&num1,&num2,&num3);
printf("%d",MAX(num1,num2,num3));
}*/
//9.10控制是否需要译码
/*
#include <stdio.h>
#define YES 1
#define NO 0
void main()
{
char a[50] = "";
printf("请输入一行字符串:\n");
gets(a);
#if(YES)
for(int i = 0; a[i] != '\0' && i < 50; i++)
{
if(a[i] == 'A')
{
a[i] = 'Z';
}
if(a[i] == 'a')
{
a[i] = 'z';
}
else
{
a[i] = a[i] - 1;
}
}
#endif
printf("%s\n",a);
}*/
//10.1输入三个整数按有小到大顺序输出
/*
#include <stdio.h>
void main()
{
void Swap(int *a,int *b);
int a,b,c;
printf("请输入三个整数:\n");
scanf("%d %d %d",&a,&b,&c);
if(a>b)
Swap(&a,&b);
if(a > c)
Swap(&a,&c);
if(b > c)
Swap(&b,&c);
printf("从小到大顺序%d %d %d\n",a,b,c);
}
void Swap(int *a,int *b)
{
int temp = 0;
temp = *a;
*a = *b;
*b = temp;
}*/
//10.2输入三个字符串按从小到大顺序输出
/*
#include <stdio.h>
#include <string.h>
void main()
{
void Find(char *a, char *b);
char a[10] = "";
char b[10] = "";
char c[10] = "";
printf("Please input three strings:\n");
printf("One is:\n");
gets(a);
printf("Two is:\n");
gets(b);
printf("Three is:\n");
gets(c);
Find(a,b);
Find(a,c);
Find(b,c);
printf("the three sort is :%s,%s,%s\n",a,b,c);
}
void Find(char *a, char *b)
{
char temp[20];
if(strcmp(a,b) > 0)
{
strcpy(temp,a);
strcpy(a,b);
strcpy(b,temp);
}
}*/
//输入10个数字,将其中最大的与第一个对换,最小的与最后一个对换
/*
#include<stdio.h>
#define N 10
void Input(int *p);
void OutPut(int *p);
void Operate(int a[], int n);
void main()
{
int num[N] = {0};
Input(num);
Operate(num,N);
OutPut(num);
}
void Input(int *p)
{
printf("请输入10个整数:\n");
for(int i = 0; i < N; i++)
{
scanf("%d",p+i);
}
}
void OutPut(int *p)
{
printf("调整后的数组为:\n");
for(int i = 0; i < N; i++)
{
printf("%d ",*(p+i));
}
}
void Operate(int a[], int n)
{
int *p = 0;
int *max = &a[0];
int *min = &a[9];
int temp1 = 0;
int temp2 = 0;
int i = 0;
int j = 0;
p = a;
for(i = 1; i < n; i++)
{
if(*(p+i) > *max)
{
temp1 = *max;
*max = *(p+i);
*(p+i) = temp1;
}
}
for(j = 0; j < n-1; j++)
{
if(*(p+j) < *min)
{
temp2 = *(p+j);
*(p+j) = *min;
*min = temp2;
}
}
}
*/
//10.5有n个人围成一圈,顺序排号。从第1个人开始报数(从1到3报数),
//凡报到3得人退出圈子,问最后留下得是原来第几号的那位。
/*
#include "stdio.h"
#define nmax 50
void main()
{
int i,k,m,n,num[nmax],*p;
printf("please input the total of numbers:");
scanf("%d",&n);
p=num;
for(i=0;i<n;i++)
*(p+i)=i+1;
i=0;
k=0;
m=0;
while(m<n-1)
{
if(*(p+i)!=0) k++;
if(k==3)
{
*(p+i)=0;
k=0;
m++;
}
i++;
if(i==n) i=0;
}
while(*p==0) p++;
printf("%d is left\n",*p);
}*/
/*
#include <stdio.h>
void main()
{
int a[100] = {0};
int num = 0;
int m = 1;
int *p = 0;
int j = 0;
int count = 0;
p = a;
printf("请输入num的值:\n");
scanf("%d",&num);
for(int i = 0; i < num; i++)
{
a[i] = i+1;
}
j = 0;
count = 0;
while(count < num-1)
{
if(*(p+j) != 0)
{
m++;
}
if(m == 3)
{
*(p+j) = 0;
m = 0;
count++;
}
j++;
if(j == num)
{
j = 0;
}
}
j = 0;
while(j < num)
{
if(*(p+j) != 0)
{
break;
}
j++;
}
printf("%d\n",*(p+j)+1);
}
*/
//10.4
/*
#include <stdio.h>
#define N 5
void main()
{
void Operate(int *p,int n);
int num[N] = {0};
int n = 0;
printf("请输入%d个数字:\n",N);
for(int i = 0; i < N; i++)
{
scanf("%d",&num[i]);
}
printf("你要截取的首地址:\n");
scanf("%d",&n);
Operate(num,n);
for(i = 0; i < N; i++)
{
printf("%d ",num[i]);
}
printf("\n");
}
void Operate(int *p,int n)
{
int temp = 0;
int a[N] = {0};
for(int i = n,j = 0; i < N && j < N;i++,j++)
{
a[j] = *(p+i);
}
for(i = 0,j = n+1; i < n && j < N; i++,j++)
{
a[j] = *(p+i);
}
for(i = 0; i < N; i++)
{
*(p+i) = a[i];
}
}*/
//10.6写个函数计算字符串的长度,再main函数中输入字符串
/*
#include <stdio.h>
void main()
{
int Length(char *p);
char str[50] = "";
printf("请输入你的字符串:\n");
gets(str);
printf("%s的长度为:%d\n",str,Length(str));
}
int Length(char *p)
{
int count = 0;
for(int i = 0; *(p+i) != '\0'; i++)
{
count++;
}
return count;
}*/
//10.7将一个字符串从m开始复制到另外一个字符串中,
/*
#include <stdio.h>
#include <string.h>
#define M 20
void main()
{
void Operate(char *p,char *q,int n,int h);
int n = 0;
char str1[M] = "";
char str2[M] = "";
printf("请输入第一个字符串:\n");
gets(str1);
printf("请输入你要截取的首地址 :\n");
scanf("%d",&n);
int h = strlen(str1);
Operate(str1,str2,n,h);
printf("复制到s2 的结果是:\n");
puts(str2);
}
void Operate(char *p,char *q,int n,int h)
{
for(int i = n,j = 0; i < h && j < M; i++,j++)
{
*(q+j) = *(p+i);
}
}*/
//10.8计算大写字母,小写字母,空格,数字,以及其他字符的个数
/*
#include <stdio.h>
#include <string.h>
#define M 50
void main()
{
char str[M] = "";
char *p = 0;
int space = 0;
int upper = 0;
int digit = 0;
int lower = 0;
int other = 0;
p = str;
printf("请输入一个字符串:\n");
gets(str);
int h = strlen(str);
for(int i = 0; i < h && *p != '\0'; i++,p++)
{
if(*p == ' ')
{
space++;
}
else if(*p >= 'a' && *p <= 'z')
{
lower++;
}
else if(*p >= 'A' && *p <= 'Z')
{
upper++;
}
else if(*p >= '0' && *p <= '9')
{
digit++;
}
else
{
other++;
}
}
printf("Upper = %d\n",upper);
printf("Lower = %d\n",lower);
printf("Digit = %d\n",digit);
printf("Space = %d\n",space);
printf("Other = %d\n",other);
}
*/
//10.93*3转阵
/*
#include <stdio.h>
#define N 3
void main()
{
void Operate(int *p);
int num[N][N] = {0};
printf("请输入3*3矩阵:\n");
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
scanf("%d",&num[i][j]);
}
}
printf("\n转阵前的矩阵为:\n");
for(i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
printf("%d ",num[i][j]);
}
printf("\n");
}
Operate(num[0]);
printf("\n转阵后的矩阵为:\n");
for(i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
printf("%d ",num[i][j]);
}
printf("\n");
}
}
void Operate(int *p)
{
int temp = 0;
for(int i = 0; i < N; i++)
{
for(int j = 0; j < i; j++)
{
temp = *(p+3*i+j);
*(p+3*i+j) = *(p+3*j+i);
*(p+3*j+i) = temp;
}
}
}*/
//10.10把一个5*5的矩阵中的最大数字放在中间的位置,四个小的分别放在左上右上左下右下!
/*
#include <stdio.h>
#define N 5
void main()
{
void FangZhi(int *p);
int num[N][N] = {0};
//int *p = num[0][0];
printf("请输入5*5矩阵的数字:\n");
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
scanf("%d",&num[i][j]);
//scanf("%d",*(p+i+j));
}
}
FangZhi(&num[0][0]);
printf("\n按要求搞定后的输出为:\n");
for(i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
printf("%d ",num[i][j]);
}
printf("\n");
}
}
void FangZhi(int *p)
{
int max = 0;
int *min1 = 0;
int *min2 = 0;
int *min3 = 0;
int *min4 = 0;
int temp = 0;
min1 = p;
min2 = p+N-1;
min3 = p+N*(N-1);
min4 = p+N*N-1;
//换位置,主要是找最大数,并且放在在中间
for(int i = 0; i < N*N; i++)
{
if(max < *(p+i))
{
max = *(p+i);
}
}
for(i = 0; i < N*N; i++)
{
if(max == *(p+i))
{
break;
}
}
printf("%d ",max);
temp = *(p+i);
*(p+i) = *(p+N*N/2);
*(p+N*N/2) = temp;
//找最小的四位数字,然后放在适合位置!
for(i = 0; i < N*N; i++)
{
if(*min1 > *(p+i))
{
temp = *(p+i);
*(p+i) = *min1;
*min1 = temp;
}
}
printf("%d ",*min1);
//第二小的数字
for(i = 0; i < N*N ; i++)
{
if(i != 0)
{
if(*min2 > *(p+i))
{
temp = *(p+i);
*(p+i) = *min2;
*min2 = temp;
}
}
}
printf("%d ",*min2);
//第三小的数字
for(i = 0; i < N*N ; i++)
{
if(i != 0 && i != N-1)
{
if(*min3 > *(p+i))
{
temp = *(p+i);
*(p+i) = *min3;
*min3 = temp;
}
}
}
printf("%d ",*min3);
//第四小的数字
for(i = 0; i < N*N ; i++)
{
if((i != 0) && (i != N-1) && (i != N*(N-1)))
{
if(*min4 > *(p+i))
{
temp = *(p+i);
*(p+i) = *min4;
*min4 = temp;
}
}
}
printf("%d ",*min4);
}*/
//10.11在主函数中输入10个等长的字符串,用另外一个函数对他们排序,然后在主函数中输出!
/*
#include <stdio.h>
#include <string.h>
#define R 10
#define M 20
void main()
{
void Sort(char a[][M]);
char str[R][M] = {""};
printf("请输入10个字符串:\n");
for(int i = 0; i < R; i++)
{
gets(str[i]);
}
Sort(&str[0]);
printf("\n排序后的顺序为:\n");
for(i = 0; i < R; i++)
{
puts(str[i]);
}
}
void Sort(char a[][M])
{
for(int i = 0; i < R; i++)
{
char temp[M] = "";
for(int j = 0; j < R-1-i; j++)
{
if(strcmp(a[j],a[j+1]) > 0)
{
strcpy(temp,a[j]);
strcpy(a[j],a[j+1]);
strcpy(a[j+1],temp);
}
}
}
}*/
/*
#include <stdio.h>
#include <string.h>
#define R 5
#define M 20
void main()
{
void Sort(char *a[]);
char str[R][M] = {""};
char *p[R];
for(int i =0; i < R;i++)
{
p[i] = str[i];
}
printf("请输入10个字符串:\n");
for(i = 0; i < R; i++)
{
gets(str[i]);
}
Sort(p);
printf("\n排序后的顺序为:\n");
for(i = 0; i < R; i++)
{
puts(str[i]);
}
}
void Sort(char *a[])
{
for(int i = 0; i < R; i++)
{
char temp[M] = "";
for(int j = 0; j < R-1-i; j++)
{
if(strcmp(*(a+j),*(a+j+1)) > 0)
{
strcpy(temp,*(a+j));
strcpy(*(a+j),*(a+j+1));
strcpy(*(a+j+1),temp);
}
}
}
}*/
//10.4输入n个数,按输入顺序的逆序输出!用函数实现
/*
#include <stdio.h>
#define N 20
void main()
{
void Resort(int *p, int n);
int num[N] = {0};
int *p = 0;
int n = 0;
p = num;
printf("请输入你要输入几个数字:\n");
scanf("%d",&n);
printf("请输入n个数:\n");
for(int i = 0; i < n && i < N; i++)
{
scanf("%d",&num[i]);
}
Resort(p,n);
printf(" 逆序后打印的结果为:\n");
for(i = 0; i < n; i++)
{
printf("%d ",num[i]);
}
printf("\n");
}
void Resort(int *p, int n)
{
int temp = 0;
for(int i = 0; i < n/2; i++)
{
temp = *(p+i);
*(p+i) = *(p+n-1-i);
*(p+n-1-i) = temp;
}
}*/
/*
#include <stdio.h>
#include <string.h>
#define N 20
void main()
{
void Resort(char *p,int n);
char *p = 0,num[N] = "";
int length = 0;
printf("请输入n个数字:\n");
gets(num);
p = num;
length = strlen(num);
Resort(p,length);
printf("逆序后的输出结果是:\n");
puts(num);
}
void Resort(char *p,int n)
{
char tempC = ' ';
for(int i = 0; i < n/2; i++)
{
tempC = *(p+i);
*(p+i) = *(p+n-1-i);
*(p+n-1-i) = tempC;
}
}*/
//10.15一个班有4位同学,5门学科求:1)第一门学科的平均成绩2)找出有两门课程不及格的学生,输出学号
//每门课程的成绩,以及平均成绩3)找出平均成绩90分以上的或每门都在85分以上的学生,
//分别编写三个函数分别实现3个要求
/*//////////////////////////////////////////////////////////////////////
#include <stdio.h>
#define N 2
#define M 2
void main()
{
void AvgFirst(float *p);
void FindLose(float *p);
void DisplayGood(float *p);
float stu[N][M] = {0.0};
printf("请输入该班同学的成绩:\n");
for(int i = 0; i < N; i++)
{
for(int j = 0; j < M; j++)
{
scanf("%d",&stu[i][j]);
}
}
AvgFirst(&stu[0][0]);
FindLose(&stu[0][0]);
DisplayGood(&stu[0][0]);
}
void AvgFirst(float *p)
{
float sum = 0.0f;
float avg = 0.0f;
for(int i = 0; i < N; i++)
{
sum += (*(p + M*i));
}
avg = sum/N;
printf("第一门学科的平均成绩是:%f\n",avg);
}
void FindLose(float *p)
{
int i = 0, j = 0;
for(i = 0; i < N; i++)
{
int count = 0;
float sum = 0.0f;
float avg = 0.0f;
for(j = 0; i < M; j++)
{
if((*(p+i+j)) < 60)
{
count++;
sum += (*(p+i+j));
}
}
if(count >= 2)
{
avg = sum / M;
printf("第%d个学生",i);
printf("各门课程的成绩是:");
for(int k = 0; k < M; k++)
{
printf("%f\t",*(p+i+k));
}
printf("\n平均成绩为%f\n",avg);
}
}
}
void DisplayGood(float *p)
{
for(int i = 0; i < N; i++)
{
float sum = 0.0f;
float avg = 0.0f;
int count = 0;
for(int j = 0; j < M; j++)
{
sum += (*(p+i+j));
if((*(p+i+j)) >= 85)
{
count++;
}
}
avg = sum / M;
if(count == M || avg >= 90)
{
printf("第%d名学生是好学生:\n",i);
}
}
}
//////////////////////////////////////////////////////////////////////
*/
/////////////////////////////////////////////////////////////////////
//10.17自己写函数实现strcmp()
/*
#include <stdio.h>
#define N 20
void main()
{
int MyStrcmp(char *p, char *q);
char numOne[N] = "";
char numTwo[N] = "";
int myBool = 0;
printf("请输入第一个字符串:\n");
gets(numOne);
printf("请输入第二个字符串:\n");
gets(numTwo);
if(MyStrcmp(numOne,numTwo) > 0)
{
printf("第一个字符串大于第二个字符串\n");
}
else if(MyStrcmp(numOne,numTwo) < 0)
{
printf("第一个字符串小于第二个字符串\n");
}
else
{
printf("第一个字符串等于第二个字符串\n");
}
}
int MyStrcmp(char *p, char *q)
{
int i = 0;
int j = 0;
int ReValue = 0;
for(i = 0; i < N; i++)
{
if(*(p+i) == '\0')
{
break;
}
}
for(j = 0; j < N; j++)
{
if(*(q+j) == '\0')
{
break;
}
}
if(i != j)
{
for(int k = 0; k < i && k < j; k++)
{
if(*(p+k) > *(q+k))
{
return 1;
}
else if(*(p+k) < *(q+k))
{
return -1;
}
}
if(i > j)
{
return 1;
}
else
{
return -1;
}
}
else
{
for(int k = 0; k < i; k++)
{
if(*(p+k) > *(q+k))
{
return 1;
}
else if(*(p+k) < *(q+k))
{
return -1;
}
}
if(k == i)
{
return 0;
}
}
return 0;
}*/
//10.18输入一个月份,输出相应的月份英文名
/*
#include <stdio.h>
void main()
{
char *p[13] = {"error Month","January","February","March","April",
"May","June","July","August","September","October","november","December"};
int month = 0;
printf("请输入你要查询的月份:\n");
scanf("%d",&month);
if(month <= 12 && month >= 0)
{
printf("%d是: %s\n",month,*(p+month));
}
}
*/
/*
#include <stdio.h>
#include <string.h>
void main()
{
char * DigitToLetter(int n);
int month = 0;
char *p = 0;
printf("请输入你要查询的月份:\n");
scanf("%d",&month);
printf("%d月份是:%s\n",month,DigitToLetter(month));
}
char * DigitToLetter(int n)
{
char *p[13] = {"error Month","January","February","March","April",
"May","June","July","August","September","October","november","December"};
if(n >= 1 && n <= 12)
{
return *(p+n);
}
return *p;
}*/
//10.19研究中……
//10.20用指向指针的指针来对输入的字符排序并输出
/*
#include <stdio.h>
#include <string.h>
#define N 5
void main()
{
void Sort(char **p);
char *str[N] = {""};
char s[N][20];
char **pr;
for(int i = 0; i < N; i++)
{
str[i] = s[i];
}
printf("请输入%d个字符串:\n",N);
for(i = 0; i < N; i++)
{
printf("请输入第%d个字符串:\n",i+1);
scanf("%s",str[i]);
}
pr = str;
Sort(pr);
for(i = 0; i < N; i++)
{
printf("%s\t",str[i]);
}
printf("\n");
}
void Sort(char **p)
{
for(int i = 0; i < N; i++)
{
char temp[20] = "";
for(int j = i+1; j < N; j++)
{
if(strcmp(*(p+i),*(p+j+1)) > 0)
{
strcpy(temp,*(p+i));
strcpy(*(p+i),*(p+j));
strcpy(*(p+j),temp);
}
}
}
}*/
//10.21用指向指针的指针来对n个整数排序并输出!
/*
#include <stdio.h>
#define N 5
void main()
{
void Sort(int **p);
int *p[N] = {0};
int a[N] = {0};
int **pr = 0;
int i = 0;
for(i = 0; i < N; i++)
{
p[i] = &a[i];
}
printf("请输入%d个整数:\n",N);
for(i = 0; i < N; i++)
{
scanf("%d",p[i]);
}
pr = p;
Sort(pr);
for(i = 0; i < N; i++)
{
printf("%d ",*p[i]);
}
printf("\n");
}
void Sort(int **p)
{
int temp = 0;
for(int i = 0; i < N; i++)
{
temp = 0;
for(int j = i+1; j < N; j++)
{
if(**(p+i) > **(p+j))
{
temp = **(p+i);
**(p+i) = **(p+j);
**(p+j) = temp;
}
}
}
}*/
//11.1定义一个结构体包括年月日,计算输入的年月日食该年的第几天!注意闰年问题
/*
#include <stdio.h>
struct Date
{
int year;
int month;
int day;
}date;
void main()
{
int days = 0;
printf("请输入你要查询的年月日:\n");
scanf("%d %d %d",&date.year,&date.month,&date.day);
switch(yue)
{
case 1 :
days = date.day;
break;
case 2 :
days = 31 + date.day;
break;
case 3 :
days = 31 + 28 + date.day;
break;
case 4 :
days = 90 + date.day;
break;
case 5:
days = 120 + date.day;
break;
case 6 :
days = 151 + date.day;
break;
case 7 :
days = 181 + date.day;
break;
case 8 :
days = 212 + 28 + date.day;
break;
case 9 :
days = 243 + date.day;
break;
case 10:
days = 279 + date.day;
break;
case 11 :
days = 304 + date.day;
break;
case 12:
days = 334 + date.day;
break;
default :
printf("输入有误:\n");
break;
}
if((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 ==0)
{
if(date.month > 2)
{
days += 1;
}
}
printf("%d年%d月%d日是该年的第%d天\n",date.year,date.month,date.day,days);
}*/
/*
#include <stdio.h>
struct Date
{
int year;
int month;
int day;
};
void main()
{
int MonthDays[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int days = 0;
struct Date date;
printf("请输入你要查询的年月日:\n");
scanf("%d %d %d",&date.year,&date.month,&date.day);
for(int i = 0; i < date.month; i++)
{
days += MonthDays[i];
}
days += date.day;
if((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 ==0)
{
if(date.month > 2)
{
days += 1;
}
}
printf("%d年%d月%d日是该年的第%d天\n",date.year,date.month,date.day,days);
}*/
//11.2
/*
#include <stdio.h>
struct Date
{
int year;
int month;
int day;
}date;
void main()
{
int CountDays(int n);
int days = 0;
printf("请输入你要查询的年月日:\n");
scanf("%d %d %d",&date.year,&date.month,&date.day);
days = CountDays(date.month) + date.day;
if((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 ==0)
{
if(date.month > 2)
{
days += 1;
}
}
printf("%d年%d月%d日是该年的第%d天\n",date.year,date.month,date.day,days);
}
int CountDays(int n)
{
int MonthDays[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int days = 0;
for(int i = 0; i < n; i++)
{
days += MonthDays[i];
}
return days;
}*/
//11.3 编写个函数print,打印一个学生的成绩数组,该数组中游5个学生的数据记录,每个纪录包括
//num,name,score[3],用主函数输入这些记录,用该函数输出
/*
#include <stdio.h>
#define N 5
struct Student
{
int num;
char name[20];
float score[3];
}stu[N];
void print(struct Student a[N])
{
for(int i = 0; i < N; i++)
{
printf("num = %d ,name = %s ,score[0] = %.3f ,score[1] = %.3f ,score[2] = %.3f\n",
a[i].num,a[i].name,a[i].score[0],a[i].score[1],a[i].score[2]);
}
}
void main()
{
printf("请输入5各学生的编号姓名以及3门成绩:\n");
for(int i = 0; i < N; i++)
{
scanf("%d",&stu[i].num);
scanf("%s",&stu[i].name);
scanf("%f %f %f",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}
print(stu);
}*/
/*
#include <stdio.h>
#define N 5
struct Student
{
int num;
char name[20];
float score[3];
}stu[N];
void main()
{
void Input(struct Student stu[N]);
void Print(struct Student a[N]);
Input(stu);
Print(stu);
}
void Print(struct Student a[N])
{
for(int i = 0; i < N; i++)
{
printf("num = %d ,name = %s ,score[0] = %.3f ,score[1] = %.3f ,score[2] = %.3f\n",
a[i].num,a[i].name,a[i].score[0],a[i].score[1],a[i].score[2]);
}
}
void Input(struct Student stu[N])
{
printf("请输入5各学生的编号姓名以及3门成绩:\n");
for(int i = 0; i < N; i++)
{
printf("请输入第%d学生的编号姓名以及3门成绩:\n",i+1);
scanf("%d",&stu[i].num);
scanf("%s",&stu[i].name);
scanf("%f %f %f",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}
}
*/
//11.5
/*
#include <stdio.h>
#define N 10
struct Student
{
int num;
char name[20];
float score[3];
float avg[N];
}stu[N];
void main()
{
void Input(struct Student stu[N]);
void Print(struct Student a[N]);
Input(stu);
Print(stu);
}
void Print(struct Student a[N])
{
float sum = 0.0f;
float sum2 = 0.0f;
float avg = 0.0f;
float max = 0;
int i = 0;
int iTemp = 0;
for(i = 0; i < N; i++)
{
sum = (a[i].score[0] + a[i].score[1] + a[i].score[2]);
sum2 += (a[i].score[0] + a[i].score[1] + a[i].score[2]);
//printf("num = %d ,name = %s ,score[0] = %.3f ,score[1] = %.3f ,score[2] = %.3f\n",
// a[i].num,a[i].name,a[i].score[0],a[i].score[1],a[i].score[2]);
a[i].avg[i] = sum/N;
}
avg = sum/(3*N);
for(i = 0; i < N; i++)
{
if(max < a[i].avg[i])
{
max = a[i].avg[i];
iTemp = i;
}
}
printf("三门课程的总平均成绩是:%.3f\n",avg);
printf("成绩最好的学生num = %d ,name = %s ,score[0] = %.3f ,score[1] = %.3f ,score[2] = %.3f ,avg = %.3f\n",
a[iTemp].num,a[iTemp].name,a[iTemp].score[0],a[iTemp].score[1],a[iTemp].score[2],a[iTemp].avg[iTemp]);
}
void Input(struct Student stu[N])
{
printf("请输入%d各学生的编号姓名以及3门成绩:\n",N);
for(int i = 0; i < N; i++)
{
printf("请输入第%d学生的编号姓名以及3门成绩:\n",i+1);
scanf("%d",&stu[i].num);
scanf("%s",&stu[i].name);
scanf("%f %f %f",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}
}*/
//11.6--11.7
//11.8又两个链表,要求合并并且安学号升序输出
/*
#include <stdio.h>
#include <malloc.h>
#define N 2
#define SIZE sizeof(struct Student)
struct Student
{
int num;
float score;
struct Student *p;
}a[N],b[N];
struct Student * CreatList();
struct Student * AddList(struct Student *A,struct Student *B);
void Print(struct Student *p);
struct Student *listA;
struct Student *listB;
struct Student *listC;
void main()
{
listA = CreatList();
listB = CreatList();
listC = AddList(listA,listB);
Print(listC);
}
struct Student * CreatList()
{
struct Student *p1,*p2,*ph;
p1 = p2 = (struct Student *)malloc(SIZE);
for(int i = 0; i < N; i++)
{
printf("请输入%d个元素的num和score:\n",i+1);
scanf("%d %f",&(p1->num),&(p1->score));
if(i == 0)
{
ph = p1;
}
else
{
p2->p = p1;
}
p2 = p1;
p2->p = NULL;
}
return ph;
}
struct Student * AddList(struct Student *A,struct Student *B)
{
struct Student *temp;
temp = A;
for(int i = 0; i < N; i++)
{
if(A->p == NULL)
{
A->p = B;
}
}
return temp;
}
void Print(struct Student *pm)
{
int temp = 0;
int i = 0;
int j = 0;
for(i = 0; i < N*2; i++)
{
temp = 0;
for(j = i+1; j < N*2-1; j++)
{
if((p+j)->num > (p+j+1)->num)
{
temp = (p+j)->num;
(p+j)->num = (p+j+1)->num;
(p+j+1)->num = temp;
}
}
}
for(i = 0; i < N*2; i++)
{
printf("%d %.3f\n",pm->num,pm->score);
pm = pm->p;
}
}
*/
#include <stdio.h>
#define N 10
struct person
{
int num;
int nextp;
}link[N+1];
void main()
{
int i = 0;
int count,h;
for(i = 1; i <=N; i++)
{
if(i == 1)
{
link[i].nextp = 1;
}
else
{
link[i].nextp = i + 1;
}
link[i].num = i;
}
count = 0;
h = N;
printf("\n最后一个是:\n");
while(count < N - 1)
{
i = 0;
while(i != 3)
{
h = link[h].nextp;
if(link[i].num)
{
i++;
}
}
printf("%4d",link[h].num);
link[h].num = 0;
count++;
}
printf("最后一个是:\n");
for(i = 1; i < N; i++)
{
if(link[i].num)
{
printf("%3d",link[i].num);
}
}
}
//12.1
/*
#include <stdio.h>
void main()
{
int getbits(unsigned value, int n1, int n2);
unsigned int a;
int n1,n2;
printf("请输入一个16位的数字:\n");
scanf("%o",&a);
printf("请输入n1,n2:\n");
scanf("%d %d",&n1,&n2);
printf("resut = %o\n",getbits(a,n1-1,n2));
}
int getbits(unsigned value, int n1, int n2)
{
unsigned int z;
z = ~0;
z = (z >> n1) & (z << (16-n2));
z = value & z;
z = z >> (16-n2);
return z;
}*/
//12.2
/*
#include <stdio.h>
void main()
{
unsigned getbits(unsigned);
unsigned int a;
printf("\nInput an ocyal number:\n");
scanf("%o",&a);
printf("Resualt:%o\n",getbits(a));
}
unsigned getbits(unsigned value)
{
int i,j;
unsigned int z,a,q;
z = 0;
for(i = 1; i <= 15;i+=2)
{
q = 1;
for(j = 1; j <= (16-i-1)/2;j++)
{
q = q *2;
}
a = value>>(16-i);
a = a<<15;
a = a>>15;
z = z + a * q;
}
return z;
}*/