#include
void print_table ( int n )
{
int n=0;
int i=0;
int j=0;
for (i=0;i<n;i++)
{
for (j=0;j<=i;j++)
printf ("%d*%d=%d\n",i,j,i*j);
}
}
int main ( )
{
int line =0;
scanf ("%d",&line);
print_table (line);
return 0;
}
#include
void Init (int arr[],int sz,int set)
{
int i=0;
for (i=0;i<sz;i++)
{
arr[i]=set;
printf ("%d ",arr[i]);
}
int main ( )
{
int arr[6]={1,2,3,4,5,6};
int sz=sizeof (arr) /sizeof(arr[0]);
Init (int arr,int sz,6);
return 0;
}
#include
void Empty (int arr[],int sz)
{
int i=0;
for (i=0;i<sz;i++)
{
arr[i]=0;
printf ("%d ",arr[i]);
}
int main ( )
{
int arr[6]={1,2,3,4,5,6};
int sz =sizeof (arr) /sizeof (arr[0]);
Empty (int arr,int sz );
return 0;
}
#include
void Revsrse (int arr[],int sz)
{
int left=0;
int right=sz-1;
int tmp=0;
if (left<right)
{
tmp=arr[left];
arr[left]=arr[right];
arr[right]=tmp;
left++;
right--;
}
int i=0;
for (i=0;i<sz;i++)
{
printf ("%d ",arr[i]);
}
int main ( )
{
int arr[6]={1,2,3,4,5,6]};
int sz=sizeof (arr) /sizeof (arr[0]);
Reverse (int arr,int sz );
return 0;
}
#include
void print (int n)
{
if (n>9)
print (n/10);
printf ("%d ",n%10);
}
int main ( )
{
int num=0;
scanf ("%d",&num);
print (num);
return 0;
}
注:存在限制条件,当满足这个限制条件时,递归便不再继续;每次递归调用之后越来越接近这个限制条件。
#include
int fac ( int n)
{
if (n<=1)
return 1;
else
return n*fac (n-1);
}
int main ( )
{
int n=0;
int ret =0;
scanf ("%d",&n);
ret=fac (n);
printf ("%d\n",ret);
return 0;
}
#include
int fib (int n)
{
if (n<=2)
return 1;
else
{
int a=1,b=1,c=0;
int i=0;
for (I=0;I<n-2;i++)
{
c=a+b;
a=b;
b=c;
return b;
}
}
}
int main ( )
{
int n=0;
scanf ("%d",&n);
printf ("%d", fib( n));
return 0;
}