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;
}
# 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;
}
相关文章推荐
- 快速判断一个数能否被1、2、3、4、5、6、7、8、9、10、11、12、13、17、19、23等整除的规律总结
- java 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,
- |1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20所有这些字符串,把它的数字一个个剥离??
- 现有杂乱无序的1-20二十个数,这二十个数为:1,18,4,13,6,10,15,2,17,3,19,7,16,8,11,14,9,12,5,20,试依次求出相邻四个数之和的最大和最小值
- 传智播客Hibernate视频教程学习笔记10 11 12 13
- PAT《数据结构学习与实验指导》实验项目集 2-09 2-10 2-11 2-12 2-13
- 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8
- 数据库操作_连接SQL Server数据库示例;连接ACCESS数据库;连接到 Oracle 数据库示例;SqlCommand 执行SQL命令示例;SqlDataReader 读取数据示例;使用DataAdapter填充数据到DataSet;使用DataTable存储数据库表;将数据库数据填充到 XML 文件;10 使用带输入参数的存储过程;11 使用带输入、输出参数的存储过程示;12 获得数据库中表的数目和名称;13 保存图片到SQL Server数据库示例;14 获得插入记录标识号;Exce
- 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1、10、11、12、13因此共出现6次,但是对于后面问题他就没辙了。ACMer希望你们帮帮他,并把问题更加普遍化,可以很快的求出任意非负整数区间中1出现的次数。
- 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10.
- 有一个整数n,写一个函数f(n),返回0~n之间出现的“1”的个数,例如f(1)=1; f(13)=6(1,10,11,12,13一共6个1),最大的f(n)=n的n是多少
- 题目:扑克牌的顺子 从扑克牌中随机抽出5张牌,判断是不是一个顺子,即这五张牌是不是连续的。2——10为数字本身,A为1,J为11,Q为12,K为13,而大小王为任意数字。
- 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8
- "1,2;3,4,5/6,7;8,9,10/11,12;13,14,15"
- 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1、10、11、12、13因此共出现6次,但是对于后面问题他就没辙了,logn的算法复杂度
- 25.求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1、10、11、12、13因此共出现6次,但是对于后面问题他就没辙了。AC
- 快速判断一个数能否被1、2、3、4、5、6、7、8、9、10、11、12、13、17、19、23等整除的规律总结
- PAT《数据结构学习与实验指导》实验项目集 2-09 2-10 2-11 2-12 2-13
- 快速判断一个数能否被1、2、3、4、5、6、7、8、9、10、11、12、13、17、19、23等整除的规律总结
- 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8