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

 

/*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; 
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值