//题目:输出9*9口诀。#include<stdio.h>#include<stdlib.h>//int i, j,num;// int m = 0;// for (i = 1; i <= 9; i++) {// for (j = 1; j < m; j++) {// num = i * j;// printf("%d*%d=%d", i, j, num);// m++;// }// printf("\n");// }intmain(){printf("9*9乘法表打印如下:\n");//优化界面int i, j, num;int m =1,n=1;//决定变量for(i =1; i <= n; i++){//建立第一个循环,用于控制行数for(j =1; j <= m; j++){//建立第二个循环.用于控制列数
num = i * j;//得出两数乘积printf("%5d*%d=%d", j, i, num);//逐条打印}printf("\n");
m++;
n++;if(n >9)break;}system("pause");}
在这里插入代码片
//题目:打印楼梯,同时在楼梯上方打印两个笑脸//printf("%c%c", '\xA1', '\xF6');#include<stdio.h>#include<stdlib.h>intmain(){int i, j, n=1;printf(" :) :)\n");for(i =0; i <10; i++){for(j =0; j <= n; j++){printf(" ");if(i = j)printf("%c%c",'\xA1','\xF6');}
n++;printf("\n");}system("pause");}
```c
//题目:要求输出国际象棋棋盘。//白格,printf("%c%c", '\xA1', '\xF6');//黑格,printf(" ");#include<stdio.h>#include<stdlib.h>intmain(){int i, j;int n =0, m =0;printf("国际棋盘打印如下:\n");printf("\n");printf("\n");printf("\n");for(i =1; i <=8; i++){for(j =1; j <=8; j++){if((i+j)%2==0)printf("%c%c",'\xA1','\xF6');elseprintf(" ");}printf("\n");}printf("\n");printf("\n");printf("\n");system("pause");}
``
```c
//题目:将一个正整数分解质因数//例如:输入90,打印出90=2*3*3*5。#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>voidfactoring(int a){int i;for(i =2; i <= a; i++){while(a%i ==0){printf("%d", i);
a /= i;if(i !=1)printf("*");}}printf("1");printf("\n");}intmain(){int num;printf("请输入要因式分解的数:\n");scanf("%d",&num);printf("%d=", num);factoring(num);system("pause");}
//题目:利用条件运算符的嵌套来完成此题://学习成绩 >= 90分的同学用A表示,//60 - 89分之间的用B表示,60分以下的用C表示。#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>//char level(int a){// char word[] = { 0 };// if (a >= 90)// strcpy(word, "A");// if (a <= 89 && a >= 60)// strcpy(word, "B");// if (a < 60)// strcpy(word, "C");// return word;//}intmain(){int score;printf("请输入您的成绩:\n");scanf("%d",&score);char word[]={0};if(score >=90)strcpy(word,"A");if(score <=89&& score >=60)strcpy(word,"B");if(score <60)strcpy(word,"C");printf("%s", word);system("pause");}
//题目:输入一行字符,分别统计出其中英文字母、//空格、数字和其它字符的个数。//程序分析:利用while语句,条件为输入的字符不为'\n'.#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>#include<stdlib.h>voidreadline(char s[]){//读行函数是将字符串放入一个字符数组中 for(int i =0;;i++){char c =getchar();//先将读取的字符储存下来,仅用getchar()会丢失掉读到的字符if( c =='\n'|| c ==EOF){//意味着换行或者结束了
s[i]=0;//字符串结尾以零结尾break;}
s[i]= c;//如果没有结束(上面判断不成立),那这个c储存进来}}//另外,字符数组每一个单元储存一个字符,并且一段字符串以零结尾,//当直接调用字符数组名时,就相当于调用了一个字符串,&s[i]表示从i开始intmain(){char s[10000];readline(s);int length =strlen(s);int number =0;int space =0;int word =0;int other =0;for(int i =0;
i < length;i ++){if(s[i]>='0'&& s[i]<='9')
number ++;elseif(s[i]==' ')
space ++;elseif(s[i]>='A'&& s[i]<='Z'|| s[i]>='a'&& s[i]<='z')
word ++;else
other ++;}printf("数字个数为:%d\n空格字数为:%d\n字母个数为:%d\n其他字符个数为:%d\n", number,space,word,other);system("pause");}
//题目:输出9*9口诀。#include<stdio.h>#include<stdlib.h>//int i, j,num;// int m = 0;// for (i = 1; i <= 9; i++) {// for (j = 1; j < m; j++) {// num = i * j;// printf("%d*%d=%d",...