//有1,2,3,4个数字,能组成多少个互不相同的且没有重复数字的三位数
#include <stdio.h>
int main(){
int i ,j ,k;
int count = 0;
for(i = 1;i < 5;i++){
for(j = 1;j < 5;j++){
for (k = 1; k < 5; k++){
if(i != j && i != k && j != k){
printf("%d %d %d",i,j,k);
printf("\n");
count++;
printf("%d",count);
}
}
}
}
}
/*
定义一个100000以内的整数; 这个数+100,+268 是一个完全平方数
*/
#include <stdio.h>
#include "math.h"
int main(){
long int i,x ,y;
for (i = 0; i < 100000; i++)
{
x = sqrt(i + 100);
y = sqrt(i + 268);
if(x * x == (i + 100) && y * y == (i + 268)){
printf("%d\n",i);
}
}
return 0;
}
/*
*/
#include <stdio.h>
//输出九九乘法表
int main(){
int i,j,result; // i * j = result
for(i = 1;i < 10;i++){
for(j = i;j < 10;j++){
result = i * j;
printf("%d * %d = %-3d",i,j,result);
}
printf("\n");
}
return 0;
}
//分别统计输入的字符中字母、空格、数字、其他字符的个数
#include <stdio.h>
int main(){
char c;
int letters = 0, spaces = 0,digits = 0,others = 0;//字母、空格、数字、其他
printf("请从控制台输入字母:\n");
while((c = getchar()) != '\n'){
if((c >= 'a' && c <='z') || (c >= 'A' && c <='Z'))
letters++;
else if(c >= '0' && c <= '9')
digits++;
else if(c == ' ')
spaces++;
else
others++;
}
printf("%d %d %d %d",letters,spaces,digits,others);
}
//求100以内的勾股数
#include <stdio.h>
#include <math.h>
int main(){
int a, b, c,count = 0;
printf("100以内的勾股数有:\n");
printf(" a b c a b c a b c a b c\n");
for (a = 1; a <= 100; a++)
{
for (b = 1; b <= 100; b++)
{
c = sqrt(a * a - b * b);
if(c * c == a * a - b * b && c > 0){
printf("%4d%4d%4d", a, b, c);
count++;
if(count % 4 == 0){
printf("\n");
}
}
}
}
printf("\n");
return 0;
}
//要求:从小到大输出
#include <stdio.h>
int main(){
int x , y ,z ,t;
scanf("%d%d%d",&x,&y,&z);// 5 3 1
if(x > y){
t = x; //t = 5
x = y; //x = 3
y = t; //y = t
}
if(y > z){
t = y; //t = 5
y = z; //x = 3
z = t; //y = t
}
if(x > z){
t = x; //t = 5
x = z; //x = 3
z = t; //y = t
}
printf("从小到大排序结果是:%d%d%d",x,y,z);
}
循环结构练习
最新推荐文章于 2023-03-15 00:09:00 发布