实验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;
    printf("p = %lld\n",p);
    p = p*n;
    
    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)
{
    
    printf("%c",symbol);
    if ( n!=1)
    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);
        
    }
    return 0;
 } 
 long long fun(int n)
 {
     int i;
     long long f = 1,s;
     for(i = 1;i<=n;++i)
     {
         f = f*2;
     }
     s = f - 1;
     return s;
 }

  

 

 

#include<stdio.h>
int isprime(int);
int main()
{
	int a;
	int b=0;
	for(a=101;a<201;a++)
	{	
	if(isprime(a)==1)
		{
	printf("%d\t",a);
	b=b+1;
		}
	}
	printf("\n101~200之间一共有%d个非素数",b);
	return 0;
	
 } 
int isprime(int n)
 {
 	int i;
 	for(i=2;i<n;i++)
 		if(n%i==0)
 		return 1;
		return 0;
 }

  

 

#include<stdio.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)
{
	
	int t,i=1;
    int num=0;
    while(s>0)
	{
        t = s%10;
        if (t % 2 ==1)
		{
        num = num + t*i;
        i *=10;
        }
        s/=10;
    }
    return num;
	}

  

 

 

#include<stdio.h>
#include<math.h>
double fun(int n);
double fac(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)
{
	if(n==1)
	return 1;
	else	
	return fun((n-1))+pow((-1),(n-1))/fac(n);
}
double fac(int a)
{
	int i;
	double p = 1;
    for(i=1;i<=a;i++)
    {
    p = p*i;
	}
    return p;
}

  

 

 

posted @ 2021-11-29 23:05  淮左谪仙  阅读(3)  评论(0编辑  收藏  举报