简单代码效率的提升
来源:互联网 发布:网络会议设备 编辑:程序博客网 时间:2024/05/22 07:48
1、求100到200之间的素数
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
inti = 0;
intj = 0;
intk = 0;
for(i = 101; i < 200; i=i+2)
{
k= sqrt(i);
for(j = 2; j <= k; j++)
{
if(i%j == 0)
break;
}
if(j > k)
printf("%d ", i);
}
system("pause");
return0;
}#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
inti = 0;
intj = 0;
intcount = 0;
for(i = 100; i <=200 ; i++)
{
for(j = 2; j <= i/2; j++)
{
if(i%j == 0)
break;
}
if(j > i/2)
{
printf("% d ", i);
count++;
}
}
printf("\n素数的个数=%d\n",count);
system("pause");
return0;
}
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
inti = 0;
intj = 0;
intcount = 0;
for(i = 101; i <=200; i += 2)
{
for(j = 2; j <=sqrt(i); j++)
{
if(i%j == 0)
break;
}
if(j > sqrt(i))
{
printf("% d", i);
count++;
}
}
printf("\n素数的个数=%d", count);
system("pause");
return0;
}
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
inti = 0;
intj = 0;
intcount = 0;
for(i = 100; i <=200; i++)
{
for(j = 2; j <i; j++)
{
if(i%j == 0)
break;
}
if(j ==i)
{
printf("% d", i);
count++;
}
}
printf("\n素数的个数=%d", count);
system("pause");
return0;
}
2、输出乘法口诀表
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
inti = 0;
intj = 0;
for(i = 1; i < 10; i++)
{
for(j = 1; j <= i; j++)
{
printf("%d* %d=%-4d", j, i, i*j);
}
printf("\n");
}
system("pause");
return0;
}
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
inti = 0;
intj = 0;
for(i = 1; i <= 9; i++)
{
for(j = 1; j <= i; j++)
{
i*j;
printf("%d*%d=%-3d", i, j, i*j);
}
printf("\n");
}
system("pause");
return0;
}
3、判断1000年到2000年之间的闰年
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
intyear = 0;
intcount = 0;
for(year = 1000; year<=2000; year++)
{
if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
{
printf("%-6d", year);
count++;
}
}
printf("\n");
printf("闰年的个数%d\n",count);
system("pause");
return0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
intyear = 0;
intcount = 0;
for(year = 1000; year <= 2000; year++)
{
if(year % 4 == 0)
{
if(year % 100 != 0)
{
printf("%d ", year);
count++;
}
}
if(year % 400 == 0)
{
printf("%d", year);
count++;
}
}
printf("\n %d", count);
system("pause");
return0;
}
- 简单代码效率的提升
- [CSAPP]提升代码的效率
- 提升代码的效率--复用
- paip.提升效率--僵尸代码的迷思
- 如何提升php代码的运行效率
- 提升输入效率代码
- C++代码效率提升工具
- Web开发人员必知的提升效率的jQuery代码
- 简单几步,提升.Net Core的开发效率
- 简单几步,提升.Net Core的开发效率
- 关于代码版本管理提升开发效率的一些想法
- 关于代码版本管理提升开发效率的一些想法
- 利用ctags提升看、写代码的效率
- 提升R代码运算效率的11中方法
- java 性能优化:提升 java 代码的运行效率
- 提升你的效率
- 效率为王 分享几个提升php运行效率的代码规范写法详解
- 提升R代码运算效率的11个实用方法——并行、效率
- Oracle数据库连接C#
- 从一个DataTable导出至另一个DataTable
- 利用Opencv提供的imencode和imdecode进行图像视频传输(发送端支持Linux和Windows双系统)
- 【一、Android Studio工具的使用】#171216
- Dept(entity)
- 简单代码效率的提升
- Unity游戏开发优化事项
- 如何在viewDidAppear之前使用view的frame正确布局
- MHA实现MySQL主从自动在线切换功能
- java中的异常
- VB与数据库连接小知识
- Hadoop3.0.0伪分布式、完全分布式安装及其新特性介绍
- leetcode习题解答:39. Combination Sum
- Python 深入浅出