#include<stdio.h>#include<math.h>#include<stdlib.h>intmain(){
int m,n,max,min;printf("请输入两个正整数:");scanf("%d,%d",&m,&n);//求最大公约数int i;for( i=1; i <= m && i <= n ;++i ){
if( m % i ==0&& n % i ==0)
max = i;}//求最小公倍数int j;if( m > n )
j = m;else
j = n;for(; j % m !=0|| j % n !=0;++j );
min = j;printf("两个数的最大公约数为:%d\n两个数的最小公倍数为:%d\n",max,min);system("pause");return0;}
4. 输入一行字符,分别统计出其英文字母、空格、数字和其他字符个数。
#include<stdio.h>#include<math.h>#include<stdlib.h>intmain(){
char c;int letter =0, space =0, digit =0, others =0;printf("请输入一行字符:");while(( c =getchar())!='\n'){
if( c >='A'&& c <='Z'|| c >='a'&& c <='z')// 要考虑大小写字母情况
letter++;elseif( c >='0'&& c <='9')
digit++;elseif( c ==' ')
space++;else
others++;}printf("其中英文字母有:%d个\n数字有:%d个\n空格有:%d个\n其他字符有:%d个\n",letter,digit,space,others);system("pause");return0;}
#include<stdio.h>#include<math.h>#include<stdlib.h>intmain(){
int a,n,i,j,temp;printf("请输入a和n的值:");scanf("%d,%d",&a,&n);
temp = a;
j = a;if(n>1){
for( i =2; i <= n ;++i )