//#include <stdio.h>
// 1. 求n,!末尾有多少個(gè)零;遍歷數(shù)中有多少類(lèi)型的條件,;
//int main(int argc, const char *argv[])
//{
//int n,i;
//int g=0;
//int tmp;
//scanf("%d",&n);
//for (i =1;i<=n;i )
//{
//tmp=i;
//while ((tmp%5)==0)
//{
//tmp/=5;
//g ;
//}
//}
//printf("%d\n",g);
//return 0;
//}
2.從鍵盤(pán)輸入兩個(gè)整數(shù),求兩個(gè)數(shù)的最大公約數(shù)
求最大公約數(shù)即:在兩個(gè)數(shù)中取最小的一個(gè)數(shù),,完后的從最小的一個(gè)數(shù)開(kāi)始向下求找除數(shù),求能同時(shí)被兩個(gè)數(shù)取余都為零的數(shù)
#include <stdio.h>
int main(int argc, const char *argv[])
{
int m, n;
scanf("%d %d", &m, &n);
int i;
for(i = m > n ? n : m; i >= 1; i--)
{
if((m % i == 0) && (n % i == 0))
{
printf("%d is the greatest devisor!\n", i);
break;
}
}
return 0;
}
//3.用for循環(huán)打印乘法口絕表
//
#include <stdio.h>
int main(int argc, const char *argv[])
{
int i,j;
for (i = 1; i <= 9; i )
{
for (j = 1; j <=9; j )
{
// if(j > i)
// continue;
if(i>=j)
printf("%dx%d=%d\t",i,j,i*j);
}
printf("\n");
}
return 0;
}
4.
打印出一個(gè)菱形,,如輸入5(只能輸入奇數(shù)),則打印出:
*
***
*****
***
*
#include <stdio.h>
int main(int argc, const char *argv[])
{
int i,j,n;
scanf("%d",&n);
for (i = 0; i <=n/2; i )
{
for (j=0; j<n/2-i; j )
printf(" ");
for(j=0;j<2*i 1;j )
printf("*");
printf("\n");
}
for (i = 1; i <=n/2; i )
{
for (j=0; j<i; j )
putchar(' ');
for(j=0;j<n-2*i;j )
putchar('*');
putchar('\n');
}
return 0;
}
4.從鍵盤(pán)輸入一個(gè)數(shù),,打印重復(fù)的數(shù)和個(gè)數(shù)
int arr[10]={0};
int n;
scanf("%d",&n);
while(n)
{
arr[n%10] ; //利用數(shù)組下標(biāo)的方法計(jì)算重復(fù)
n/=10;
}
int i;
for(i=0;i<10;i )
{
if(arr[i]>1)
printf("%d apper %d times \n",i,arr[i]);
}
//1.向數(shù)組中寫(xiě) 隨級(jí)數(shù),算,,基數(shù)和偶數(shù)的個(gè)數(shù)
//srand(time(NULL)); //定義隨機(jī)數(shù)的種子
//for (i = 0; i < sizeof(arrg)/sizeof(arrg[0]); i )
//{
//arrg[i]=rand()%100; //在產(chǎn)生的隨機(jī)數(shù)中自己選定條件
//}
//for (i = 0; i <10 ; i )
//{
//if(arrg[i]%2==0)
//{
//numo ;
//}
//else
//numj ;
//}
//// printf("基數(shù):%d 偶數(shù):%d\n",numo,numj);
////
//2,打印最大值,,和下標(biāo)
//int tg=0;
//tmp=arrg[0];
//for (i = 0; i < 10; i )
//{
//if(arrg[i 1]>tmp)
//{
//tmp=arrg[i 1]; tg=i 1;
//}
//}
//printf("the great values is%d\n",tmp);
//printf("baio %d\n",tg);
|