• c语言数组那些骚事儿


    找出最大和第二大值
    #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int mynum[] = {43, 88, 56, 24, 78, 12, 8,29,57,80}; int max=0; printf("%d ", max); int smax=0; printf("%d ", smax); if (mynum[0] > mynum[1]) { max = mynum[0]; smax = mynum[1]; } else { max = mynum[1]; smax = mynum[0]; } for (int i = 2; i < 10; i++) { if (max < mynum[i]) { smax = max; max = mynum[i]; } else if ((mynum[i]<max) && (mynum[i]>smax)) { smax = mynum[i]; } } printf("%d ",max); printf("%d ", smax); system("pause"); }
    •  数组的逆序----思想是第一个和最后一个,第二个和倒数第二个
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    int main()
    {
        int mynum[] = { 43, 88, 56, 24, 78, 12, 8, 29, 57, 80 };
        int cnt = sizeof(mynum) / 4;
        printf("%d
    ",cnt);
        for (int i = 0; i < cnt/2; i++)
        {
            int temp = mynum[i];
            mynum[i] = mynum[cnt - i - 1];
            mynum[cnt - i - 1] = temp;
        }
        for (int i = 0; i < 10; i++)
        {
            printf("%d,", mynum[i]);
        }
        system("pause");
        return EXIT_SUCCESS;
    }
    •  字符串逆序,------目前只能应用于中间带空格的英文字符串
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    int main()
    {
        char mywords[] = "hello world";
        int cnt;
        cnt = sizeof(mywords)-1;
        printf("%d
    ",cnt);
        for (int i = 0; i < cnt/2; i++)
        {
            if (i == 6)
            {
            }
            else
            {
                char temp = mywords[i];
                mywords[i] = mywords[cnt - i - 1];
                mywords[cnt - i - 1] = temp;
            }
            
        }
        for (int i = 0; i < sizeof(mywords); i++)
        {
            printf("%c", mywords[i]);
        }
        system("pause");
        return EXIT_SUCCESS;
    }
  • 相关阅读:
    js学习笔记之(call、apply)
    windows8 应用的激活与挂起
    SharePoint2010分享
    Windows8 Metro 设计与开发vs11风格样式
    windows8 应用激活
    Windows8 Metro 设计与开发平台预览
    windows8 账户图片设置
    Windows8 Metro 设计与开发必须关注的新特性
    Windows8 Metro 设计与开发你不知道的C模型
    Windows8 Metro 设计与开发VS11的win8模拟器
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/10338577.html
Copyright © 2020-2023  润新知