提交 68743c90 创建 作者: 赵鹏翀's avatar 赵鹏翀

init template

上级
/Debug
/Release
\ No newline at end of file
<?xml version="1.0" encoding="gb2312"?>
<ASMProject Version="1.00" Name="Demo010" TemplatePath="console(c)\Project" ProjectID="7dec11fc-fead-408b-a450-20152551f903" IsSubmitWork="0">
<Configurations>
<Configuration Name="Debug" DebuggerFlavor="0">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="_DEBUG" GenerateDebugInformation="-1" LanguageStandard="c99"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool"/>
<Tool Name="PostBuildEventTool"/>
</Configuration>
<Configuration Name="Release" DebuggerFlavor="0">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="NDEBUG" LanguageStandard="c99"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool" StripDebugInfo="-1"/>
<Tool Name="PostBuildEventTool"/>
</Configuration>
</Configurations>
<Files>
<Filter Name="ͷļ" Filter="h;hpp;hxx">
<File RelativePath=".\console.h">
</File>
</Filter>
<Filter Name="Դļ" Filter="cpp;c;cc;cxx">
<File RelativePath=".\console.c">
</File>
</Filter>
</Files>
</ASMProject>
添加文件
#include "console.h"
#include "windows.h"
// 求x和y的平均值
int average(int x, int y)
{
return (x&y) + ((x^y)>>1);
}
// 判断x是不是2的幂
BOOL power2(int x)
{
return ((x&(x-1)) == 0)&&(x!=0);
}
// 不用temp互换x和y
void swap(int x, int y)
{
x ^= y;
y ^= x;
x ^= y;
printf("转换后x和与分别为%d %d\n", x, y);
}
// 计算绝对值
int absValue(int x)
{
int y;
y = x >> 31;
return (x^y)-y;
}
int main()
{
// 求平均值
int result = 0;
result = average(2, 6);
printf("2和6的平均值是:%d\n", result);
// 判断一个数是不是2的幂
BOOL Ispower2 = power2(8);
if(Ispower2)
{
printf("8是2的幂\n");
}
else
{
printf("8不是2的幂\n");
}
// 不使用temp互换x和y的值
int x, y;
x = 5;
y = 15;
printf("转换前x和与分别为%d %d\n", x, y);
swap(5, 15);
// 求绝对值
result = absValue(-123);
printf("-123的绝对值是:%d\n", result);
}
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
#include <stdio.h>
/* TODO: 在此处引用程序需要的其他头文件 */
#endif /* _CONSOLE_H_ */
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论