实验3

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#define N 80

void printText(int line,int col,char text[]);
void printSpaces(int n);
void printBlankLines(int n);

int main()
{
    int line,col,i;
    char text[N]="hi,May~";
    
    srand(time(0));
    
    for(i=1;i<=10;++i)
    {
        line=rand()%25;
        col=rand()%80;
        printText(line,col,text);
        Sleep(1000);
    }
    
    return 0;
} 

void printSpaces(int n)
{
    int i;
    
    for(i=1;i<=n;++i)
    printf(" ");
}

void printBlankLines(int n)
{
    int i;
    
    for(i=1;i<=n;++i)
    printf("\n");
}

void printText(int line,int col,char text[])
{
    printBlankLines(line-1);
    printSpaces(col-1);
    printf("%s",text);
    
}

#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>

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",n,f);
    }
    
    return 0;
}

long long fun(int n)
{
    static long long m;
    if(n>=1&&n<=32)
    {
        m=2*fun(n-1)+1;
    }
    else if(n==0) m=0;
    
    return m;
}

#include<stdio.h>
#define N 20

void is_prime(int n);

int main()
{
    int j;
    for(j=4;j<=N;j++)
    {
        if(j%2==0)
        {
            is_prime(j);
        }    
    }
    return 0;
}

void is_prime(int n)
{
    int i,k,num1,num2;
    for(num1=2;num1<n;num1++)
    {
        k=0;
        for(i=2;i<num1;i++)
        {
            if(num1%i==0) k++;
        }
        
        if(k==0)
        {
            num2=n-num1;
        }
        
        k=0;
        for(i=2;i<num2;i++)
        {
            if(num2%i==0) k++;
        }
        
        if(k==0&&num2>1&&num1<=num2)
        {
            printf("%d = %d + %d\n",n,num1,num2);
            break;
        }
    }
}

#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 n,k=1;long m,p=0;
    m=s;
    while(m!=0)
    {
        n=m%10;
        if(n%2!=0)
        {
            p+=k*n;
            k*=10;
        }
        m/=10;
    }
    s=p;
    
    return s;    
}

 

posted @ 2022-04-24 15:10  施乐乐  阅读(13)  评论(3编辑  收藏  举报