博文
熟悉字符串指针作为函数参数(2009-10-08 12:23:00)
摘要:/*=============================================================
熟悉字符串指针作为函数参数
==============================================================
作者:最后的村长
时间:2009年10月28日
工具:DEV C++ 4.9.9.2
version:1.0
==============================================================*/
#include <stdio.h>
#include <stdlib.h>
/*=============================================================*/
void copy_string1(char *p1,char *p2)//以字符串指针作为函数参数
{
int i=0;
while(*p2!='\0')
{
&nb......
求1~20!之和(2009-10-08 10:36:00)
摘要:#include <stdio.h>
#include <stdlib.h>
int main()
{
double mid,sum=0;//一定要double型的
int n,m;
for(n=1;n<=20;n++)
{
mid=1;
for(m=1;m<=n;m++)
mid*=m;
sum+=mid;
}
printf("20个自然数阶乘之和:%.9e\n",sum);
system("PAUSE");
return 0;
}......
求100个自然数之和、50个自然数平方和、1个自然数倒数(2009-10-08 10:36:00)
摘要:#include <stdio.h>
#include <stdlib.h>
int main ()
{
float sum=0;
int sum1=0;
int sum2=0;
float sum3=0;
//-----------100个自然数之和--------------
for(int k=1;k<=100;k++)
{
sum1=sum1+k;
}
printf("100个自然数之和:%d\n",sum1);
//---------50个数的平方之和----------
for(int k=1;k<=50;k++)
{
sum2=sum2+k*k;
&n......
/*--------求1000之内的所有完熟--*/(2009-10-08 10:35:00)
摘要:#include <stdio.h>
#include <stdlib.h>
int main()
{
for(int n=1;n<=1000;n++)
{
int sum=0;
for(int m=1;m<n;m++)
{
if(n%m==0)
sum=sum+m;
}
if(sum==n)
printf("%d是完数\n",n);
}
system("PAUSE");
return 0;
} ......
球从100m落下问题(2009-10-08 10:35:00)
摘要:#include <stdio.h>
#include <stdlib.h>
int main()
{
int H=100;
float sum_distance=H,h;
h=H/2;
for(int i=1;i<10;i++)
{
sum_distance=2*h+sum_distance;
h=h/2;
}
printf("第10次反弹的高度是%4.2f米\n 经过10次反弹经历的距离为:%4.2f\n",h,sum_distance);
system("PAUSE");
return 0;
} ......
猴子吃桃问题(2009-10-08 10:34:00)
摘要:#include<stdio.h>
#include<stdlib.h>
int main()
{
int peach_num=1;
int day=9;
while(day>0)
{
peach_num=2*(peach_num+1);
day--;
}
printf("第一天总共摘了%d桃子",peach_num);
system("PAUSE");
return 0;
......
迭代法求平方根(2009-10-08 10:33:00)
摘要:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
float x1=1,x2,t;
int a;
printf("请输入求平方根的值:");
scanf("%d",&a);
while(fabs(x2-x1)>1e-5)
{
x2=0.5*(x1+a/x1);
t=x1;
x1=x2;
x2=t;
}
 ......
求二维数组中的鞍点(2009-10-08 10:32:00)
摘要:#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 5//定义数组的行列数
#define M 3
int main()
{
int a[N][M];
time_t t;
srand((unsigned) time(&t));
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
a[i][j]=1+(int)(10.0*rand()/(RAND_MAX+1.0));//利用随机函数生成1-10范围内的任意整数,RAND_MAX是随机函数的上限
printf("%d ",a[i][j]);
}
printf("\n");//隔行换行
}
int none=0;//none代表无鞍点的数目
for(int i=0;i<N;i++)
{
int column,line;//column,line代表最大值的列号 、行号。
int max=a[i][0];//定义每行的第一个元素为初始最大值
&n......
应用二维数组的行指针输出二维数组的元素(2009-10-07 22:41:00)
摘要:/*=============================================================
应用二维数组的行指针输出二维数组的元素
==============================================================
作者:最后的村长
时间:2009年10月6日
工具:DEV C++ 4.9.9.2
version:1.0
==============================================================*/
#include <stdio.h>
#include <stdlib.h>
/*=============================================================*/
int main()
{
int a[3][4]={1,3,5,7,9,11,13,15,17,19,21,23};//定义并初始化二维数组
int (*p2)[......
指针变量输出数组元素的值(2009-10-07 22:40:00)
摘要:/*=============================================================
指针变量输出数组元素的值
==============================================================
作者:最后的村长
时间:2009年10月28日
工具:DEV C++ 4.9.9.2
version:1.0
==============================================================*/
#include <stdio.h>
#include <stdlib.h>
/*=============================================================*/
int main()
{
int a[3][4]={1,3,5,7,9,11,13,15,17,19,21,23};
......