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

实验3

 

#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);
}

  实验3

#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 a;
	for(a=1;a<=n;a++){
		printf("%c",symbol);
	}
}

  实验3

 

#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);}
    if(n>1){
    printf("%c",symbol);
    printSymbol(n-1, symbol);
}
}

实验3

 

#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 sum,f,a;
    sum=1;
    for(a=1;a<=n;a++){
        sum=sum*2;
    }
    f=sum-1;
    
}

实验3

 

#include<stdio.h>
#include<math.h>
int isPrime(int n);
int main(){
    int i,a;
    a=0;
    for(i=101;i<=200;i++){
        if(isPrime(i)==0){
        printf("%5d",i);
        a++;}
    }
    printf("\n100~200之间一共有%d个非素数",a);
    return 0;
}
int isPrime(int i){
    int a,b,c;
    b=sqrt(i);c=0;
    for(a=2;a<=b;a++){
        if(i%a==0)break;}
    if(a>b&&i!=1)
    return 1;
    else return 0;
    
}

实验3

 

#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 a,b,c;
    b=0;c=0;
    while(s!=0){
    a=s%10;s=s/10;
    if(a%2!=0){
    b=b*10+a;
    }}
    while(b!=0){
    a=b%10;b=b/10;
    if(a%2!=0){
    c=c*10+a;}
}
    return c;
}

实验3

 

#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 i;
    double t=-1,s=0;
    for(i=1;i<=n;i++){
        t=-t*i;    
        s=s+1/t;
    }
    
    return s;
}

实验3

 

 

 

 

上一篇:实验三


下一篇:美国大选科普加写代码预(找)测(乐)比(子)分