首页 > 其他分享 >shiyan2

shiyan2

时间:2023-03-23 15:15:15浏览次数:9  
标签:main return int scanf shiyan2 printf include

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

#define N 5
#define R1 586
#define R2 701
int main()
{
    int number;
    int i;
    
    srand( time(0));
    
    for(i =0;i < N; ++i)
    {
        number = rand()%(R2-R1+1)+1;
        printf("20228330%04d\n",number);
    }
    
    return 0;
 } 

task2

#include<stdio.h>

int main()
{
 float x,y;
 char c1,c2,c3;
 int a1, a2, a3;

 scanf("%d,%d,%d",&a1,&a2,&a3);//a1,a2,a3前缺少&
 printf("a1=%d,a2=%d,a3=%d\n",a1 ,a2,a3);

 scanf("\n%c,%c,%c",&c1,&c2,&c3);
 printf("c1=%c, c2=%c, c3=%c\n",c1,c2,c3);

 scanf("\n%f,%f",&x,&y);
 printf("x=%f,y=%f\n",x,y);

 return 0;
}

 

task3

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

int main()
{
    double x,ans;
    
    while(scanf("%lf",&x)!=EOF)
    {
    ans = pow(x,365);
    printf("%.2f的365次方:%.2f\n",x,ans);
    printf("\n");
    }
    
    return 0;
    
}

 

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

int main()
{
    double c,f;
    while(scanf("%lf",&c)!=EOF){
    f=9*c/5+32;
    printf("摄氏度c=%.2lf时,华氏度f=%.2lf\n",c,f);
    printf("\n"); 
    }
    return 0;
    
}

task4

#include<stdio.h>

int main()
{
    int a;
    while(scanf("%d",&a)!=EOF){
    
    char n;
    n=getchar();
    if(n=='r'){
        printf("stop\n");
    }
    else if(n=='g'){
        printf("go go go\n");
    }
    else if(n=='y'){
        printf("wait a minute\n");
    }
    else{
    
    printf("something must be wrong\n");
    }
    printf("\n");
    }
    return 0;
}

task5

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int main()
{
    
       int n,i,k;
       
       srand((unsigned)time(NULL));
       n = rand() % 30 + 1;
       printf("猜猜2023年4月哪一天是你的lucky day吧");
       printf("\n开始咯,你有三次机会,猜吧(1~30):");
       scanf("%d",&i);
       for(k=1;i!=n&&k<=2;k++){
       if(i<n){
               printf("你猜小了\n");
           }
           else if(i>n){
               printf("你猜大了\n");
           }
           printf("再猜(1~30):");
           scanf("%d",&i);
           if(k==2&&i!=n){
           printf("\n");
           printf("次数用完了,偷偷告诉你,四月你的幸运日是%d\n",n);
           }
           }
           if(i==n){
           printf("哇,猜中了");}
         
           
       
       return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int i,n,k;
    for(i=1;i<=9;i++){
        for(n=1;n<=i;n++){
        k=i*n;
        printf("%3d*%d=%d",i,n,k);}
        printf("\n");
    }
    return 0;
 } 

#include<stdio.h>
#include<stdlib.h>
 int main()
 {
      int n,i,j,m,h;
    printf("input n: ");
    scanf("%d", &n);
    m = n;
    for (i = 1; i <= n; i++)
    {
        for (h = 1; h < i; h++)
            printf("\t");
        for (j = 1; j <= (2 * m - 1); j++)
        {
            printf(" O \t");
        }
        printf("\n");
        for (h = 1; h < i; h++)
            printf("\t"); 
        for (j = 1; j <= (2 * m - 1); j++)
        {            
            printf("<H>\t");
        }
        printf("\n");
        for (h = 1; h < i; h++)
            printf("\t");
        for (j = 1; j <= (2 * m - 1); j++)
        {
            printf("I I\t");
        }
        printf("\n");
        m = m - 1;
    
    }
    system("pause");
    return 0;
}

 

标签:main,return,int,scanf,shiyan2,printf,include
From: https://www.cnblogs.com/ctayy/p/17247496.html

相关文章