test(3)

#include<stdio.h>
long long fac(int n);
int main()
{
    int i,n;
    printf("Enter n: ");
    scanf("%d", &n);
    for (i = 1; i <= n; ++i)
    printf("%d! = %lld\n", i, fac(i));
    return 0;
}

long long fac(int n)
{
   static long long p = 1;
    p = p * n;

    return p;
}

 

 

 

#include<stdio.h>
long long fac(int n);
int main()
{
    int i,n;
    printf("Enter n: ");
    scanf("%d", &n);
    for (i = 1; i <= n; ++i)
    printf("%d! = %lld\n", i, fac(i));
    return 0;
}

long long fac(int n)
{
   static long long p = 1;
    p = p * n;
    printf("p = %lld\n", p);
    return p;
}

 

 

 

#include<stdio.h>
int func(int,int);
int main()
{
    int k = 4, m = 1, p1, p2;
    p1 = func(k, m);
    p2 = func(k, m);
    printf("%d,%d\n", p1, p2);
    return 0;
}
 
 int func(int a, int b)
 {
     static int m = 0, i = 2;
     i += m + 1;
     m = i + a + b;
     return (m);
 }

 

 

 

#include <stdio.h>
void  printSymbol(int n, char symbol);
int main()
{
    int n;
    char symbol;
    while( scanf("%d %c", &n, &symbol) != EOF )
    {
        printSymbol(n, symbol);
        printf("\n");
    }
    return 0;
}

void  printSymbol(int n, char symbol)
{
   int i;
   for(i=1;i<=n;i++)
   printf("%c",symbol);

}

 

 

 

#include <stdio.h>
void  printSymbol(int n, char symbol);
int main()
{
    int n;
    char symbol;
    while( scanf("%d %c", &n, &symbol) != EOF )
    {
        printSymbol(n, symbol);
        printf("\n");
    }
    return 0;
}

void  printSymbol(int n, char symbol)
{  if(n==1)
 printf("%c",symbol);
 else
  {printf("%c",symbol);
   printSymbol(n-1,symbol);
  }
}

#include <stdio.h>
long long fun(int n);
int main()
{
    int n;
    long long f;
    while (scanf("%d", &n) != EOF)
    {
        f = fun(n);
        printf("n = %d, f = %lld\n", n, f-1);
    }
    return 0;
}
 long long fun(int n)
 {
     long long int x; 
     if(n==0)
      x=1;
     else
     {
         x=2*fun(n-1);
     }
     return x;
 }

 

 

 

 

#include<math.h>
int isprime(int x);
int main()
{
    int i,a,c=0;
    for(i=101;i<=200;i++)
    {    a=isprime(i);
      if(a==1)
     {printf("%4d",i);
     c++;
      }
    }
    printf("\n");
    printf("%4d",c);
    return 0;     
}


 int isprime(int x)
 {
     int m=2;
    while(m<=sqrt(x))
     {
         if(x%m==0)
         {return 1;
          break;}
           else
           m++;
     }
     if(m>sqrt(x))
     return 0; 
     
 }

 

 

 

#include <stdio.h>
#include<math.h>
long fun(long s);
int main()
{
    long s, t;
    printf("Enter a number: ");
    while (scanf("%ld", &s) != EOF)
    {
        t = fun(s);
        printf("new number is: %ld\n\n", t);
        printf("Enter a number: ");
    }
    return 0;
}
long fun(long s)
{
    long  int x,z=1,sum=0,item=0;
     while(s>0)
    {
    x=s%10;
    if(x%2==1)
    {
     item=x*z;
      sum=sum+item;
     z=z*10;
    }
    s=s/10;
    }
     return sum;
}

 

 

 

#include <stdio.h>
double fun(int n);
int main()
{ 
    int n;
    double s;
    printf("Enter n(1~10): ");
    while (scanf("%d", &n) != EOF)
    {
        s = fun(n);
        printf("n = %d, s= %f\n\n", n, s);
        printf("Enter n(1~10): ");
    }
    return 0;
}

 double fun(int n)
 {
     int a,x=0,i,m,p=1;
      double item,sum;
     for(i=1;i<=n;i++)
     {
     x++;
     a=1;
     item=1;
     m=1;
      while(a<=x)
      {
          a++;
      item=item*m;
        m++;
     }
     sum=sum+p*(1/item);
     p=p*(-1);
     }
     return sum;
 }

 

 通过这一章节的学习,学会了递归的思想

posted @ 2021-11-25 19:44  lzy1  阅读(5)  评论(0编辑  收藏  举报