实验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;
}

实验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){
printf("%c",symbol);
if (n!=1)
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){
    long long a;
    if(n==1)
        return 1;
        else
        a=2*fun(n-1)+1;
        return a;
}
实验3

#include <stdio.h>
#include <math.h>
int isprime(int);
int main(){
int a,b;
b=0;
for (a=101;a<=200;a++)
if (isprime(a)==1){
printf("%d ",a);
b=b+1;}
printf("101~200之间有%d个素数",b);
return 0;
}
int isprime(int s){
    int h;
    for (h=2;h<=sqrt(s);h++)
        if (s%h==0)break;
        if (h>sqrt(s)&&s>1) 
        return 0;
        else
        return 1;    
}
实验3

 

实验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 d,a,b;
    do{
        if(s%10%2==1){
        d=d+s%10;
        s=s/10;
        d=d*10;}
        else
        s=s/10;
    }
    while(s!=0);
    d=d/10;
    a=0;
    b=0;
    while(d!=0){
        a=d%10;
        b=b*10+a;
        d=d/10;
    }
    return b;
}

 

 实验3

 

 

#include <stdio.h>
#include <math.h>
unsigned int jiec(unsigned int);
double fun(int n); 
int main()
{
int n,a;
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){
    double g,h;
    g=0;
    if (n==1)
    return 1;
    else
    g=fun(n-1)+1/double(jiec(n))*pow(-1,n-1);
    return g;
}
unsigned int jiec(unsigned int n){
    unsigned int a;
    if(n==0)
    a=1;
    else 
    a= n*jiec(n-1);
    return a;
}

 

实验3

 

上一篇:实验3


下一篇:实验3