zoukankan      html  css  js  c++  java
  • 第七章

    #include<stdio.h>
    int main(void)
    {
        int i,number;
        char str[10];
     
        printf("Enter a string:");
        i=0;
        while((str[i]=getchar())!='
    ')
            i++;
        str[i]='';
     
        number=0;
        for(i=0;str[i]!='';i++)
            if(str[i]>='0'&&  str[i]<='9')
                number=number*10+str[i]-'0';
     
            printf("digit=%d
    ",number);
     
            return 0;
    }
    #include<stdio.h>
    int main(void)
     
    {
        int count[9];
        int i,response;
     
        for(i=1;i<=8;i++)
            count[i]=0;
        for(i=1;i<=1000;i++){
            printf("input your response:");
            scanf("%d",&response);
            if(response<1||response>8)
                printf("this is a bad response:%d
    ",response);
            else
                count[response]++;
        }
     
        printf("result:
    ");
        for(i=1;i<=8;i++)
            printf("%4d%4d
    ",i,count[i]);
     
        return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int i;
        int fid[10]={1,1};
        for(i=2;i<=10;i++)
            fid[i]=fid[i-1]+fid[i-2];
        for(i=0;i<=10;i++){
            printf("%6d",fid[i]);
            if((i+1)%5==0)
                printf("
    ");
        }
     
        return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int i,flag,x;
        int a[5];
     
        printf("Enter 5 integers:");
        for(i=0;i<5;i++)
            scanf("%d",&a[i]);
        printf("Enter x:");
        scanf("%d",&x);
        flag=0;
        for(i=0;i<=5;i++)
            if(a[i]==x){
                printf("Index is %d
    ",i);
                flag=1;
                break;
            }
            if(flag==0)
                printf("Not Fount
    ");
     
            return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int i,index,n;
        int a[10];
     
        printf("Enter n:");
        scanf("%d",&n);
        printf("Enter %d integers:",n);
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
     
        index=0;
        for(i=1;i<n;i++)
            if(a[i]<a[index])
                index=i;
     
            printf("min is %d	sub is %d
    ",a[index],index);
     
            return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int i,index,k,n,temp;
        int a[10];
     
        printf("Enter n:");
        scanf("%d",&n);
        printf("Enter %d integers:",n);
        for(i=0;i<=n;i++)
            scanf("%d",&a[i]);
        for(k=0;k<n-1;k++){
            index=k;
            for(i=k+1;i<n;i++)
                if(a[i]<a[index])  index=i;
            temp=a[index];
            a[index]=a[k];
            a[k]=temp;
        }
        printf("After sorted: ");
        for(i=0;i<n;i++)
            printf("%d ",a[i]);
        printf("
    ");
     
        return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int a[10]={1,2,3,4,5,6,7,8,9,10};
        int low,high,mid,n=10,x;
     
        printf("Enter x: ");
        scanf("%d",&x);
     
        low=0;high=n-1;
        while(low<=high)  {
            mid=(low+high)/2;
            if(x==a[mid])
                break;
            else if(x<a[mid])
                high=mid-1;
            else
                low=mid+1;
        }
        if(low<=high)
            printf("Index is %d 
    ",mid);
        else
            printf("Not found
    ");
     
        return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int col,i,j,row;
        int a[3][2];
     
        printf("Enter 6 integers:
    ");
        for(i=0;i<3;i++)
            for(j=0;j<2;j++)
                scanf("%d",&a[i][j]);
            for(i=0;i<3;i++){
                for(j=0;j<2;j++)
                    printf("%4d",a[i][j]);
                printf("
    ");
            }
     
            row=col=0;
            for(i=0;i<3;i++)
                for(j=0;j<2;j++)
                    if(a[i][j]>a[row][col]){
                        row=i;
                        col=j;
                    }
                    printf("max=a[%d][%d]=%d
    ",row,col,a[row][col]);
     
                    return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int i,j;
        int a[3][2];
     
        for(i=0;i<3;i++)
            for(j=0;j<2;j++)
                a[i][j]=i+j;
     
            for(i=0;i<3;i++){
                for(j=0;j<2;j++)
                    printf("%4d",a[i][j]);
                printf("
    ");
            }
     
            return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int i,j,n,temp;
        int a[6][6];
     
        printf("Enter n:");
        scanf("%d",&n);
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
                a[i][j]=i*n+j+1;
     
            for(i=0;i<n;i++)
                for(j=0;j<n;j++)
                if(i<=j){
                    temp=a[i][j];
                    a[i][j]=a[j][i];
                    a[j][i]=temp;
                }
     
                for(i=0;i<n;i++){
                    for(j=0;j<n;j++)
                        printf("%4d",a[i][j]);
                    printf("
    ");
                }
     
                return 0;
    }

    int day_of_year(int year,int month,int day)
    {
        int k,leap;
        int tab[2][13]=[
        {0,31,28,31,30,31,30,31,31,30,31,30,31},
        {0,31,29,31,30,31,30,31,31,30,31,30,31},
    };
     
    leap=(year %4 ==0&& year%100!=0 || year%400==0);
     
    for(k=1;k<month;k++)
    day=day+tab[leap][k];
     
    return day;
    }
    运行无结果
    #include<stdio.h>
    int main(void)
    {
        int i,n,m;
        char s[10];
     
        printf("Enter a string:");
        i=0;
        while((s[i]=getchar())!='
    ')
            i++;
        s[i]='
    ';
     
        for(n=0,m=i-1;n<m;n++,m--)
            if(s[n]!=s[m])
                break;
            if(n>=m)
                printf(" It is a plalindrome
    ");
            else
                printf(" It is not a plalindrome
    ");
     
            return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int i,number;
        char str[10];
     
        printf("Enter a string:");
        i=0;
        while((str[i]=getchar())!='
    ')
            i++;
        str[i]='';
     
        number=0;
        for(i=0;str[i]!='';i++)
            if(str[i]>='0'&&  str[i]<='9')
                number=number*10+str[i]-'0';
     
            printf("digit=%d
    ",number);
     
            return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int count,i;
        char str[80];
     
        printf("Enter a string:");
        i=0;
        while((str[i]=getchar())!='
    ')
            i++;
        str[i]='';
     
        count=0;
        for(i=0;str[i]!='';i++)
            if(str[i]<='9'&& str[i]>='0')
                count++;
            printf("count=%d
    ",count);
     
            return 0;
    }

    #include<stdio.h>
    int main(void)
    {
        int i,k;
        char str1[80],str2[80];
        long number;
     
        printf("Enter a string:");
        i=0;
        while((str1[i]=getchar())!='
    ')
            i++;
        str1[i]='';
     
        k=0;
        for(i=0;str1[i]!='';i++)
            if
                (str1[i]>='0'&&str1[i]<='9'||str1[i]>='a'&&str1[i]<='f'||str1[i]>='A'&&str1[i]<='F')
            {
                str2[k]=str1[i];
                k++;
            }
            str2[k]='';
     
            number=0;
            for(i=0;str2[i]!='';i++)
                if(str2[i]>='0'&&str2[i]<='9')
                    number=number*16+str2[i]-'0';
                else if(str2[i]>='a'&&str2[i]<='f')
                    number=number*16+str2[i]-'a'+10;
                else if(str2[i]>='A'&&str2[i]<='F')
                    number=number*16+str2[i]-'A'+10;
     
                printf("New string:");
                for(i=0;str2[i]!='';i++)
                    putchar(str2[i]);
                printf("
    ");
                printf("number=%ld
    ",number);
     
                return 0;
    }

  • 相关阅读:
    一行转多行 及多行转一行的 hive语句
    sparkSQL、dataframe
    特征工程
    python相关
    pyspark dataframe 格式数据输入 做逻辑回归
    hive sql 随机抽样
    pyspark 逻辑回归程序
    3.27模拟赛
    luogu P3217 [HNOI2011]数矩形
    bzoj 4403 序列统计
  • 原文地址:https://www.cnblogs.com/liyang1995/p/3355890.html
Copyright © 2011-2022 走看看