C语言(算法)

                                               C语言(算法)

#include <stdio.h>

typedef enum _Workday{


monday,
tuesday,
wednesday,
thurday,
friday

} Workday;


typedef struct _Student{

int number;
char *name;

} Student;


struct Student{

int number;
char *name;

};
int main(int argc, const char * argv[]) {
#pragma mark - 迭代
//用于求最值的问题
// int array[5] = {-1,-2,-3,-4,-5};
//
// int max = array[0];
//
// for (int i = 0; i < 5; i ++) {
// if (max < array[i] ) {
// max = array[i];
// }
// }
//
//
// printf("max = %d\n",max);



//练习:求一个二维数组中的最小值



// int array[2][3] = { {1,2,3},
// {4,5,6}
// };
//
// int min = array[0][0];
// for (int i = 0; i < 2; i ++) {
// for (int j = 0; j < 3; j ++) {
// if (min > array[i][j]) {
// min = array[i][j];
// }
// }
// }
//
// printf("min = %d\n",min);
//



#pragma mark - 递推
//递推算法
/*

* i = 1 * 2 * i - 1
***
*****


*/
//行数
// for (int i = 1; i <= 3; i ++) {
// //*
// for (int j = 1; j <= 2 * i - 1; j ++ ) {
// printf("*");
// }
//
// printf("\n");
// }
//


//例:猴子吃桃:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。

// int number = 1;
//
// for (int i = 1; i < 10; i ++) {
// number = (number + 1) * 2;
// }
// printf("%d\n",number);



#pragma mark - 穷举
//例:判定2000-2500年中那些年是闰年,并输出
//闰年:1.能被4整除但不能被100整除;2.或则能被400整除

// for (int i = 2000; i <= 2500; i ++) {
// if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)) {
// printf("i = %d\n",i);
// }
// }
//


//素数:1-100以内的素数,
//1要除外,除了能被1和它本身整除之外不能被小于它的任何数整除


//遍历数值
// for (int i = 2; i <= 100; i ++) {
// int flag = 1;//假设1代表是默认素数
// for (int j = 2; j < i; j ++) {
// //判断除1和它本身是否还有其他值能被整除
// if (i % j == 0) {
// flag = 0;//0表示不是素数
// break;
// }
// }
// //根据标记,将素数打印出来
// if (flag == 1) {
// printf("%d\n",i);
// }
//
//
// }




#pragma mark - 选择排序

//在要排序的一组数中,选出最小的一个数与第一个位置的数交换;然后在剩下的数当中再找最小的与第二个位置的数交换,如此循环到倒数第二个数和最后一个数比较为止
//从大到小
// int array[6] = {11,55,44,88,33,77};
//
// for (int i = 0; i < 6; i ++) {
// int m = i;//记录假设的最大值的数的下标
// //比较数的大小,记录最大的那个数的下标
// for (int j = i; j < 6; j ++) {
// if (array[m] < array[j]) {
// m = j;
// }
// }
// //将找到的最大值和假设的最大值通过下标进行调换
// if (m != i) {
// int temp = array[i];
// array[i] = array[m];
// array[m] = temp;
// }
//
//
// }
//
// //打印排序后的数组
// for (int i = 0; i < 6; i ++) {
// printf("%d ",array[i]);
// }
//


//
// struct Student student1 = {111, "lili"};
//
// student1.number = 222;
// student1.name = "zhangsan";
//
// printf("%d, %s\n",student1.number, student1.name);
//
//
// struct Student students[3] = {student1};
//
//
// struct Student *p = &student1;

#pragma mark - 结构体作为函数参数


struct Richer richer1 = {1, 999999999};
exchangeOfMoney(richer1);
// exchangeOfMoney1(&richer1);
// printf("main:%ld\n",richer1.money);


#pragma mark - typedef

// int a = 10;
//
// typedef int CustomInt;
//
// CustomInt b = 10;
// printf("b = %d\n",b);



// struct _Student student11;
//
// Student student22;
//
//
// enum _Workday day = monday;
// Workday day1 = monday;
//
// int number = 10;
// int *pa = &number;
// *pa = 100;
// printf("%d",*pa);

//指针数组

// char *name1 = "jack";
// char *name2 = "rose";
// char *names[2] = {name1, name2};



//数组指针
// int array1[2] = {1,2};
// int *pp = array1;
//
// char *s = "ios";
//
// char s1[] = "ios";
//
//
// char *ss = malloc(40);
// scanf("%s",ss);
//
// char sss[100];
// scanf("%s",sss);
//

return 0;

}


创建C File文件

.h文件

struct Richer{
    
    int number;
    long money;
    
};

void exchangeOfMoney(struct Richer richer);
void exchangeOfMoney1(struct Richer *richer);


.c文件

void exchangeOfMoney(struct Richer richer){
    
    richer.money = 88;
    printf("自定义:%ld\n",richer.money);
    
}

void exchangeOfMoney1(struct Richer *richer){
    
    (*richer).money = 88;
    
    //    richer ->money = 77;
    printf("自定义:%ld\n",(*richer).money);
    
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值