【晨哥的C语言之旅】经典C语言程序100例(1--5)
2012-12-07 19:11
260 查看
题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去
掉不满足条件的排列。
3. 题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
程序分析:在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,如果开方后
的结果满足如下条件,即是结果。
4.题目:输入某年某月某日,判断这一天是这一年的第几天?
1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去
掉不满足条件的排列。
//题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? #include <stdio.h> void result(); main(){ result(); } void result(){ int i, j, k; int count,result; count = 0; for(i=1; i <= 4; i++){ for(j=1; j <= 4; j++){ for(k =1; k <=4; k++){ if(i != j && i != k && j != k){ result = i*100 + j*10 + k; count++; printf("%d\n", result); } } } } printf("The number of the results is %d\n",count ); }
3. 题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
程序分析:在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,如果开方后
的结果满足如下条件,即是结果。
/*一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数, 请问该数是多少? */ #include <stdio.h> #include <math.h> main(){ int i ; for(i = 0;i<100000; i++){ float a1,b1; int a2,b2; a1 = sqrt(i+100); b1 = sqrt(i+268); a2 = (int)a1; b2 = (int)b1; while((a1 - a2 == 0) && (b1 -b2 == 0)){ printf("The number is %d\n",i); break; } } }
4.题目:输入某年某月某日,判断这一天是这一年的第几天?
/*输入某年某月某日,判断这一天是这一年的第几天? */ #include <stdio.h> main(){ int year = 2012; int month = 12; int day = 7; int month1[] = {31,28,31,30,31,30,31,31,30,31,30,31}; int month2[] = {31,29,31,30,31,30,31,31,30,31,30,31}; int result = 0; if((year % 4 == 0 && year % 100 !=0) || (year % 400 == 0)){ for(int i = 0; i < month - 1; i++){ result += month1[i]; } result += day; }else { for(int i = 0; i < month - 1; i++){ result += month2[i]; } result += day; } printf("It is the %dth day of the year.", result); }
相关文章推荐
- C语言经典案例100例 源码51-100
- 经典C语言编程100例(61-75)
- 经典C语言编程100例(76-100)
- 经典C语言程序100例(1-10)----------------转自C语言经典论坛
- C语言经典100例
- 经典C语言程序100例(11-20)---------------------转自C语言经典论坛
- C语言 - 经典程序设计100例
- C语言经典例程100例(经典c程序100例)
- 经典C语言程序100例(21-30)-----------------转自C语言经典论坛
- 经典C语言程序100例(31-40)---------------------转自C语言经典论坛
- C语言经典例程100例
- 经典C语言程序100例(41-50)------------------转自C语言经典论坛
- C语言经典编程100例(20)-猴子吃桃
- C语言经典100例
- 经典C语言编程100例(1~30)
- 经典C语言程序100例(51-60)------------------转自C语言经典论坛
- 经典C语言编程100例(31~60)
- 经典C语言程序100例(61-70)--------------------转自C语言经典论坛
- 经典C语言程序100例(71-80)---------------转自C语言经典论坛
- C语言经典100例