实验三

#include<stdio.h>
#include<math.h>

double jiecheng(int x){
    if(x==1)
    return 1;
    else
    return x*jiecheng(x-1);
    
}
double fun(int n){
    double t=0;
    int i;
    for(i=1;i<=n;i++){
    if(i%2==0)
        t-=(1/jiecheng(i));
        else 
    t+=(1/jiecheng(i));
    }return t;
}
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;}

实验三

 

#include<stdio.h>
#include<math.h>
int prime(int );
int main(){
    int i,t,n=0;
    for(i=101;i<=200;i++) 
    {
        t=prime(i);
        if(t==0){
            n=n+1;
            printf("%3d\t",i);
            if(n%10==0)
            printf("\n");
        }
}printf("\n");
printf("101~200之间有%d个非素数\n",n);
        return 0;
}
int prime(int x){

   int m,k;
   k=sqrt(x);
   
   for(m=2;m<=k;m++){
   
       if(x%m==0)
       return 0;
       else if(m>k)
       return 1;
}
}

实验三

 

#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",t);
         printf("Enter a number: "); 
     }
            return 0;}
 long fun(long s){
        long a=0,b=1,i=0;
        while(s>0){
       a=s%10;
       if(a%2!=0){
          i+=a*b;
          b*=10; 
      }s/=10;}
      return i;}

实验三

 

#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!=%11d\n",i,fac(i));}
	 
	  return 0;
}
 long long fac(int n){
 static long long p=1;
     
 	 printf("p=%11
实验三

 

d\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);
     }
     return ;
 }
 

实验三

 

#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 printSmbol(int n,char symbol){
   	if(n==0){
	   
   	return;
   	printf("%c",symbol);}
   	return printSmbol(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)
{
    long long f;
    if(n==1)
     f=1;
     else
     f=2*fun( n-1)+1;
     return f;
    
}

实验三

 

上一篇:21天好习惯 第一期-21


下一篇:JS Symbol + Proxy 实现按照后端返回字段重组展示数据