存储例题


#include <stdio.h>
int main()
{
unsigned char a = 200;
//原码00000000 00000000 00000000 11001000
//无符号char类型 只能在内存里存储 11001000
//运算时 无符号char类型整型提升 00000000 00000000 00000000 11001000

unsigned char b = 100;
//原码00000000 00000000 00000000 01100100
//无符号char类型 只能在内存里存储 01100100
//运算时 无符号char类型整型提升 00000000 00000000 00000000 01100100

unsigned char c = 0;

c = a + b;
//a+b 整型提升后进行运算 1 0010 1100 转换成原码之后 得到300
//只能在C中存储 0010 1100 整型提升后 得44


printf("%d %d", c,a+b);
return 0;
}

[C语言] 例题_C语言


杨辉三角

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main()
{
int arr[10][10] = { 0 };
int i = 0;
int j = 0;
for (i = 0; i < 10; i++)
{

for (j = 0; j <= i; j++)
{
if (j == 0)
{
arr[i][j] = 1;
}
if (i == j)
{
arr[i][j] = 1;
}
if (i >= 2 && j >= 1)
{
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
}

}


}
for (i = 0; i < 10; i++)
{
for (j = 0; j <= i; j++)
{
printf("%d ", arr[i][j]);
}
printf("\n");
}



return 0;
}



找凶手

[C语言] 例题_C语言_02


#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main()
{
char killer = 'A';
for (killer = 'A'; killer < 'D'; killer++)
{
if ((killer != 'A') + (killer == 'C') + (killer == "D") + (killer != 'D') == 3)
{
printf("%c\n",killer);
}
}
return 0;
}