1.写一个代码打印1 - 100之间所有3的倍数的数字
#include<stdio.h>
int main()
{
int i = 0;
for (i = 3; i <= 100; i+=3)
{
printf("%d ", i);
}
return 0;
}
2.写一个代码:打印100~200之间的素数,并且打印素数的个数。
素数(质数)-是只能被1和它本身整除的
关于素数:除了1和自身都不能被整除,因此偶数没有素数,偶数都能除2,像7 11这种都是素数
比如说判断16是不是素数 可以分解成4*4 或者2 *8 数字<=4 即 根号16 判断到4就行
#include<stdio.h>
#include <math.h>
int main()
{
int i = 0;
int count = 0;
for (i = 101; i <= 200; i+=2)
{
//判断i是否是素数
//2~i-1之间的数字去试除i
int j = 0;
int flag = 1;//假设是素数
for (j = 2; j <= sqrt(i); j++)
{
if (i % j == 0)
{
flag = 0;//不是素数
break;
}
}
if (flag == 1)
{
count++;
printf("%d ", i);
}
}
printf("\ncount = %d\n", count);
return 0;
}
3.有库函数可以判断大写字母 - isupper
有库函数可以判断小写字母 - islower
大写转小写 - tolower
小写转大写 - toupper
#include <stdio.h>
#include <ctype.h>
int main() {
char ch = 0;
while (scanf("%c", &ch) == 1)
{
if (islower(ch))
{
printf("%c\n", toupper(ch));
}
else if (isupper(ch))
{
printf("%c\n", tolower(ch));
}
}
return 0;
}
4.while((ch = getchar()) != EOF)循环输入字符
while((scanf("%d",&a))!=EOF) 循环输入数字