• 第十次作业


    拆分实数

    #include "stdio.h"
    int main(void)
    {
    double x, y, z, *intpart = &y, *fracpart = &z;
    void splitfloat(double x, double *intpart, double *fracpart);
    printf("输入一个小数:");
    scanf("%lf", &x);
    splitfloat(x, intpart, fracpart);
    printf("The intpart is: %lf ", *intpart);
    printf("The fracpart is:%.6lf ", *fracpart);
    return 0;
    }
    void splitfloat(double x, double *intpart, double *fracpart)
    {
    *intpart = (int)x;
    *fracpart = x - *intpart;
    }

    在数组中查找指定元素

    #include <stdio.h>
    int search(int list[],int n,int x)
    {
    int i;
    for(i=0;i<n;i++)
    if(list[i]==x)return i;
    else return -1;
    }
    main()
    {
    int list[10],n,x,i;
    printf("输入一个正整数n(1<n<=10):");
    scanf("%d",&n);
    printf("输入%d个数: ",n);
    for(i=0;i<n;i++)
    scanf("%d",&list[i]);
    printf("输入x:");
    scanf("%d",&x);
    if(search(list,n,x)==-1)printf("N0T Found ");
    else printf("%d ",search(list,n,x));
    }

     删除字符

    #include"stdio.h"
    #include"string.h"
    void delchar(char* a,char* b,char c);
    int main(void)
    {
    char a[100];
    char b[100];
    char c;
    printf("Input the string:");
    scanf("%s",a);
    printf("Input a ch:");
    scanf("%s",&c);
    delchar(a,b,c);
    printf("%s",b);
    printf(" ");
    return 0;
    }
    void delchar(char* a,char* b,char c)
    {
    int i=0,j=0;

    while(a[i]!=''){
    if(a[i]!=c){

    b[j]=a[i];

    j++;}
    i++;
    }
    b[j]=''; }

     

    字符排序

    #include <stdio.h>
    #include <string.h>

    void m(char *p[])

    {
    int i,j,k;
    char *t;
    for (i=0; i<4; i++) {
    for (j=0; j<4-i; j++) {
    if (strcmp(p[j],p[j+1])>0) {
    t=p[j];
    p[j]=p[j+1];
    p[j+1]=t;
    }
    }
    }

    for (k=0; k<5; k++) {
    puts(p[k]);
    }

    }

    int main()
    {
    printf("请输入5个数:");
    int i;
    char a[5][80];
    char *p[5];
    for (i=0;i<5; i++) {
    scanf("%s",&a[i]);
    p[i]=a[i];
    }
    m(p);
    return 0;
    }

  • 相关阅读:
    Golang 版本 支付宝支付SDK app支付接口2.0
    用 Certbot-auto 在 letsencrypt.org申请免费 SSL 证书实现 HTTPS
    Go类型断言demo
    签名算法
    golang cron定时任务简单实现
    Chapter Zero 0.2.2 内存
    Linux-系统目录结构
    Linux-关于Bash
    Chapter Zero 0.2.1 执行运算与判断的CPU
    Chapter Zero 0.1.4 计算机上常用的计算单位
  • 原文地址:https://www.cnblogs.com/zhangxiaojiao/p/zxjjjjj.html
Copyright © 2020-2023  润新知