标签:语句 控制 int 流程 number while 循环 printf count1
顺序结构,分支结构,循环结构
分支结构:if,switch
表达式只能是字符或者整数,case后面的值不能重复,break结束switch语句,default所有case都不匹配情况
case穿透规则:执行对应语句直到遇到break结束,case穿透只会往下穿透
循环结构:for,while,do...while...
for(;;){
}
while(){
}
do{
}while();
无限循环:
for(;;){ }
while(1){ }
do{ }while(1);
break,continue:break结束当前整个循环,continue结束本次循环
goto:跳转循环,不建议使用
循环嵌套:循环套循环
#include <stdio.h>
int main(){
int i,j;
for(i = 1;i <= 9;i++){
for(j = 1;j <= i;j++){
printf("%d * %d = %d\t",j,i,i * j);
}
printf("\n");
}
} //九九乘法表
\t:制表符会根据前面字符串长度补齐到8字节或8的倍数
//统计范围内质数个数
#include <stdio.h>
int main(){
int num;
scanf("%d",&num);
int i,j,count1 = 0,count2 = 0;
for(i = 2;i <= num;i++){
for(j = 1;j <= i;j++){
if(i % j == 0){
count1++;
}
}
if(count1 == 2){
count2++;
}
count1 = 0;
}
printf("%d",count2);
}
//---------------------//
#include <stdio.h>
int main(){
int count = 0,i,j,number;
printf("Input a Number:");
scanf("%d",&number);
for(i = 2;i <= number;i++){
int count1 = 0;
for(j = 1;j <= i;j++){
if(i % j == 0){
count1++;
}
}
if(count1 == 2){
printf("%d是质数\n",i);
count++;
}
}
printf("在%d范围内,有%d个质数",number,count);
}
//求幂和
#include <stdio.h>
int main(){
long long sum = 0;
int i,j,number;
printf("Input a number:");
scanf("%d",&number);
for(i = 1;i <= number;i++){
long long pow = 1;
for(j = 1;j <= i;j++){
pow *= i;
}
sum += pow;
}
printf("%d",sum);
}
标签:语句,
控制,
int,
流程,
number,
while,
循环,
printf,
count1
From: https://www.cnblogs.com/izxw/p/18362251