您的位置:首页 > 其它

P51T7,8,9,10,11,12,13

2015-03-27 20:52 253 查看
/*P51T7:输出两个字符,若两字符之差为偶数,则输出他们的前趋字符,否者输出他们的后继字符*/

# include<stdio.h>

int main()

{

char a,b;

scanf("%c%c",&a,&b);

if((b-a)%2==0)

printf("%c%c\n",a+1,b+1);

else

printf("%c%c\n",a-1,b-1);

}





/*P51T8:输出整数a,b,若a能被b整除,输出算式和商,否则输出算式和商和余数*/

#include<stdio.h>

int main()

{

int a,b,c,d;

scanf("%d,%d",&a,&b);

c=a/b;d=a%b;

if (d==0)

printf("%d/%d=%d\n",a,b,c);

else

printf("%d/%d=%d余%d\n",a,b,c,d);

}





/*P51T9:*/

#include<stdio.h>

int main()

{

int x,y;

printf("(x,y)\n");

scanf("%d%d",&x,&y);

if(((x-2)*(x-2)+(y-2)*(y-2))<1)

{

printf("A点在圆内\n");

}

else if(((x-2)*(x-2)+(y-2)*(y-2))>1)

{

printf("A点在圆外\n");

}

else

{

printf("A点在圆上\n");

}

}







/*P51T10:输出年号月份,输出该年该月的天数*/

#include <stdio.h>

int leapYear(int year)

{

if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)

return 1;

else

return 0;

}

int main()

{

int year, month;

int m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

printf ("请输入日期(格式:年 月):");

scanf ("%d%d", &year, &month);

if (leapYear(year)) m[1] += 1;

printf ("%d年%d月共有%d天\n", year, month, m[month - 1]);

}





// P51T11: 输入9*9乘法表//

#include"stdafx.h"

int main()

{

int i,j;

for(i =1;i<10;++i)

{

for(j =1;j<=i;++j)

printf("%2d*%d=%d",i,j,i*j);

printf("\n");

}

}



// P51T12: 求爱因斯坦数学题(求阶梯问题)//

#include "stdafx.h"

int main()

{

int i=1;

while(!((i%2==1)&&(i%3==2)&&(i%5==4)&&(i%6==5)&&(i%7==0)))

++i;

printf("阶梯的数目=%d ",i);

}



// P51T13:输入一串字符直到输入*号结束,统计所输入字母和数字的字符的个数。//

#include "stdafx.h"

int main()

{

char ch;

int let = 0;

int num = 0;

while ((ch = getchar()) != '*')

{

if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))

{

let++;

}

else if (ch >= '0' && ch <= '9') +

{

num++;

}

}

printf("字母:%d\n", let);

printf("数字:%d\n", num);

return 0;

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐