C初级阶段练习题目(二)

原创 2016年05月30日 17:58:12

//***********11、有1,2,3,4排成三位数,无重复且互不相同**************

intmain()
{
                inti = 0;
                intj = 0;
                intk = 0;
                intcount = 0;
                for(i = 1; i < 5; ++i)
                {
                                for(j = 1; j < 5; ++j)
                                {
                                                for(k = 1; k < 5; ++k)
                                                {
                                                                if(i != j&&j != k&&i != k)
                                                                {
                                                                                printf("%d%d%d   ", i, j, k);
                                                                                count++;
                                                                                if(count % 4 == 0)
                                                                                {
                                                                                                printf("\n");
                                                                                }
                                                                }
                                                }
                                }
                }
                return0;
}

//***********12、在屏幕上输出2000年之前的所有闰年和闰年的个数**********
intmain()
{
                intyear = 0;
                intcount = 0;
                for(year = 0; year < 2000; ++year)
                {
                                if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
                                {
                                                printf("%5d", year);
                                                count++;
                                                if(count % 15 == 0)
                                                {
                                                                printf("\n");
                                                }
                                }
                }
                printf("\n");
                printf("闰年的个数=%d", count);
                return0;
}
//********13、求2/1,3/2,5/3,8/5,13/8,21/13...前20项之和**********
intmain()
{
                inti = 0;
                floatsum = 0.0;
                floata = 2.0;
                floatb = 1.0;
                for(i = 0; i < 20; ++i)
                {
                                sum = sum + a / b;
                                a = a + b;
                                b = a - b;
                }
                printf("%f", sum);
                return0;
}
//****************14、s=a+aa+aaa+aaaa+aaaaa+aa...aaaaaa***********
intmain()
{
                inta = 0;
                intn = 0;
                inti = 0;
                intsum = 0;
                intnum = 0;
                intlastnum = 0;
                printf("请输入数据:");
                scanf("%d", &a);
                printf("请输入循环因子:");
                scanf("%d", &n);
                for(i = 0; i < n; ++i)
                {
                                num = a * pow(10, i);
                                sum = sum + num + lastnum;
                                lastnum = num;
                }
                printf("%d", sum);
                return0;
}

//****************15、一球从100米高度自由落下,每次落地后反跳原高度的一**************
//****************半再落下,求第10次落地时,共经过多少米?第10次反弹多高*************

intmain()
{
                floathigh = 100;
                inti = 0;
                floattotal_length = high;
                for(i = 2; i <= 10; i++)
                {
                                high = high / 2;
                                total_length = total_length + high*2;
                }
                printf("总长度=%f\n", total_length);
                printf("第10次反弹高度=%f\n", high);
                return0;
}

//***********16、猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个
//第二天早上将剩下的桃子吃掉了一半,又多吃了一个,以后每天早上吃前一天剩下的一半零一个
//到第10天早上想再吃时,见只剩下一个桃子,求第一天共摘了多少桃子?********************
intmain()
{
                intlastnum = 0;
                intnownum = 1;
                intday = 9;
                while(day > 0)
                {
                                lastnum = (nownum + 1) * 2;
                                nownum = lastnum;
                                day--;
                }
                printf("总数=%d", nownum);
                return0;
}

//***************17、1-1/2+1/3-1/4...+1/99-1/100*******************
intmain()
{
                inti = 0;
                floatevennum = 0.0;
                floatoddnum = 0.0;
                for(i = 2; i <= 100; i = i + 2)
                {
                                evennum = evennum - 1.0 / i;
                }
                for(i = 3; i < 100; i = i + 2)
                {
                                oddnum = oddnum + 1.0 / i;
                }
                printf("总数和=%f\n", evennum + oddnum + 1);
                return0;
}

//**************18、1+2!+3!+...+20!*******************
intmain()
{
                inti = 0;
                longsum = 1;
                longnum = 0;
                longlastnum = 1;
                for(i = 2; i <= 20; i++)
                {
                                num = i * lastnum;
                                sum = sum + num;
                                lastnum = num;
                }
                printf("sum=%d", sum);
                return0;
}

//**************19、判断一个数是否为回文数(正反序时同一个数字如12321、3443)
intmain()
{
                intnum = 0;
                intcount = 0;
                scanf("%d", &num);
                while(num > 0)
                {
                                count++;
                                num /= 10;
                }
                switch(count)
                {
                case1:
                                printf("该数不是回文数");
                                break;
                case2:
                                if(num / 1 % 10 == num / 10 % 10)
                                {
                                                printf("该数是回文数");
                                                break;
                                }
                                else
                                {
                                                printf("该数不是回文数");
                                                break;
                                }
                case3:
                                if(num / 1 % 10 == num / 100 % 10)
                                {
                                                printf("该数是回文数");
                                                break;
                                }
                                else
                                {
                                                printf("该数不是回文数");
                                                break;
                                }
                case4:
                                if((num / 1 % 10 == num / 1000 % 10) && (num / 10 % 10 == num / 100 % 10))
                                {
                                                printf("该数是回文数");
                                                break;
                                }
                                else
                                {
                                                printf("该数不是回文数");
                                                break;
                                }
                case5:
                                if((num / 1 % 10 == num / 10000 % 10) && (num / 10 % 10 == num / 1000 % 10))
                                {
                                                printf("该数是回文数");
                                                break;
                                }
                                else
                                {
                                                printf("该数不是回文数");
                                                break;
                                }
                default:
                                break;
                }
                return0;
}

   
  

//****************20、判断一个字符串是否为回文字符串********************
#include<string.h>
int  IsPalindrome(char*a)
{
                char*p =a;
                while(*p)
                {
                                p++;  //找到\0的位置
                }
                p--; //找到最后一个字符的位置
                while(a< p)   //a为数组首元素地址,p为最后一个字符的位置
                {
                                if(*a!= *p)
                                {
                                                return-1;
                                }
                                a++;
                                p--;
                }
                return1;
}


intmain()
{
                chararr[] ="abcddcbb";
                intret = IsPalindrome(arr);
                if(ret == 1)
                 {
                                 printf("该字符串是回文字符串");
                 }
                else
                                printf("该字符串不是回文字符串");
                return0;
}


版权声明:本文为博主原创文章,转载请声明原博文地址

C初级阶段练习题目(一)

以下是最近整理了一下C语言初级阶段写过的题,最近又做了一遍,开始学C语言的童鞋可以看看哈 后续一些C语言的题我复习完了也会陆续发上来 //*****************1、在屏幕上输出“hel...
  • asd7486
  • asd7486
  • 2016年05月28日 17:27
  • 124

C初级阶段练习题目(三)

//***********************21、求一个3*3矩阵对角线元素之和********************** int main() {                  ...
  • asd7486
  • asd7486
  • 2016年06月09日 20:04
  • 162

Java初级阶段 必做的题目 第二次

  • 2011年11月01日 20:17
  • 20KB
  • 下载

G共享之J2EE初级阶段

  • 2013年06月07日 12:44
  • 38.09MB
  • 下载

持续集成 编年史 之 持续集成初级阶段---家庭作坊

持续集成

论坛短消息初级阶段源代码

  • 2008年11月21日 10:47
  • 449KB
  • 下载

android初级阶段总结

第八个月的最后,终于干完了真正意义上的第一个活,虽然有数不尽的lei

Java软件工程师初级阶段测试题

  • 2015年04月10日 18:12
  • 58KB
  • 下载

Java反射初级阶段

反射初级阶段: 一.总共三个特点:getConstructors()获取构造函数 getMethods()获取普通自己写的方法 getField(“id”)获取属性 二.获取字节码对象(即cl...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:C初级阶段练习题目(二)
举报原因:
原因补充:

(最多只允许输入30个字)