c语言已经上完了,自我感觉,要想学会c语言就要不停的敲,不停的敲代码,一个好的代码重复的敲,直到敲的和hello world一样熟悉,好多算法,好多解题思想我们想不到,但是,我们把前辈的东西敲会,敲熟,哪怕是敲的背下,最后掌握了这些解题的方法,能达到举一反三,那么这些方法就变成我们的东西了。
#include <stdio.h>
int main ( void )
{
int i=0;
int j=0;
int num=123045;
char buf[24]={};
do
{
buf[i++]=num%10+'0';
num /=10;
}while(num!=0);
buf[i]=0;
for (j=0;j<i/2;j++)
{
char tmp=buf[j];
buf[j]=buf[i-1-j];
buf[i-1-j]=tmp;
}
printf("%s\n",buf);
return 0;
}
#include <stdio.h>
int main ( void )
{
int i = 0;
char buf[1024] = {"mao mao chong"};
for( i=0; buf[i] != 0; i++ )
;
printf("len=%d\n",i);
return 0;
}
#include<stdio.h>
int main( void )
{
int arr[8]={1,2,3,4,5,6,7,8};
int i=0;
int cnt=0;
int person=8;
while (1)
{
if(arr[i]>0)
{
cnt++;
}
if(cnt==3)
{
person--;
printf("%d ",arr[i]);
arr[i]=0;
cnt=0;
}
if(person==0)
{
break;
}
i++;
i=i%8;
}
printf("\n");
return 0;
}
#include <stdio.h>
#include <string.h>
int main(void)
{
int age=0;
int money=0;
char buf[]="aobma|45|10000000|X|";
char name[32]={};
char tmp[1024]={};
double sal[100]={};
char hun[10]={};
char* p=buf;
char* q=strchr(p,'|');
int i=0;
while (p!=q)
{
name[i++]=*p;
p++;
}
name[i]=0;
printf("name=%s\n",name);
q++;
p=strchr(q,'|');
i=0;
while(q!=p)
{
tmp[i++]=*q;
q++;
}
tmp[i]=0;
i=0;
while(tmp[i]!=0)
{
age=age*10+(tmp[i]-'0');
i++;
}
printf("age=%d\n",age);
p++;
q=strchr(p,'|');
i=0;
while(q!=p)
{
sal[i++]=*p;
p++;
}
sal[i]=0;
i=0;
while(sal[i]!=0)
{
money=money*10+(sal[i]-'0');
i++;
}
printf("money=%d\n",money);
q++;
p=strchr(q,'|');
i=0;
while(p!=q)
{
hun[i++]=*q;
q++;
}
hun[i]=0;
printf("hun=%s\n",hun);
return 0;
}
//随机读取十个数字,从小到大排序
int main(void)
{
srand(time(NULL)); //产生随机数种子。
int i;
int j;
int a[10]={0};
for(i=0;i<10;i++)
{
a[i]=rand()%100+1;
}
printf("before:");
for(i=0;i<10;i++)
{
printf("%d ",a[i]);
}
printf("\n");
for(i=0;i<10;i++) //排序
{
for(j=i;j<10;j++)
{
if(a[i]>a[j])
{
int tmp = a[i];
a[i]=a[j];
a[j]=tmp;
}
}
}
printf("after:");
for(i=0;i<10;i++)
{
printf("%d ",a[i]);
}
printf("\n");
return 0;
}
#include<stdio.h>
int main( void )
{
int i;
int j;
char b[]=" zhe shi ge maomaochong";
for(i=0,j=0;b[i]!='\0';i++)
{
if(b[i]!=' ')
b[j++]=b[i];
}
b[j]='\0';
printf("%s",b);
printf("\n");
return 0;
}