C语言第七天-结构体-分支循环

C语言第七天-结构体-分支循环

结构体

结构体初始化

#include<stdio.h>
struct stu {
    
    
	char name[10];
	int age;
};
int main(void)
{
    
    
	struct stu s = {
    
     "name",20 };
	printf("%s\n %d", s.name, s.age);
	return 0;
}
name
20

if循环

int main(void)
{
    
    
	int a = 2;
	if (a == 2) {
    
    
		printf("a is two");
	}
	else
	{
    
    
		printf("a is not two");
	};

	return 0;
}

判断0-100的数是否为奇数

int main(void)
{
    
    
	int a = 0;
	while (a <= 100) {
    
    
		if (a % 2 == 1) {
    
    
			printf("%d ", a);
		};
		a++;
	};
	return 0;
}
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99

猜你喜欢

转载自blog.csdn.net/A4545156/article/details/131884495