20、21、22
来源:互联网 发布:林明樟 知乎 编辑:程序博客网 时间:2024/06/16 13:48
60分以下的用C表示。
1.程序分析:(a>b)?a:b这是条件运算符的基本例子。
2.程序源代码:
#include "stdio.h"
#include "conio.h"
main()
{
int score;
char grade;
printf("please input a score\n");
scanf("%d",&score);
grade=score>=90?'A':(score>=60?'B':'C');
printf("%d belongs to %c",score,grade);
getch();
}
题目:输入两个正整数m和n,求其最大公约数和最小公倍数。
1.程序分析:利用辗除法。
2.程序源代码:
#include "stdio.h"
#include "conio.h"
main()
{
int a,b,num1,num2,temp;
printf("please input two numbers:\n");
scanf("%d,%d",&num1,&num2);
if(num1<num2)/*交换两个数,使大数放在num1上*/
{
temp=num1;
num1=num2;
num2=temp;
}
a=num1;b=num2;
while(b!=0)/*利用辗除法,直到b为0为止*/
{
temp=a%b;
a=b;
b=temp;
}
printf("gongyueshu:%d\n",a);
printf("gongbeishu:%d\n",num1*num2/a);
getch();
}
题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
1.程序分析:利用while语句,条件为输入的字符不为'\n'.
#include "stdio.h"
#include "conio.h"
main()
{
char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
getch();
}
- 20、21、22
- update fedora 20-21/22
- MIT differential equations 19,20,21,22
- 安装 Fedora 20/21/22 后要做的
- 20() 21() 22()程序练习。暂未写
- DHC log 2009-4-20 21 22 23
- 北大青鸟oracle学习笔记19 20 21 22
- Jquery李炎恢——20,21,22高级事件
- 20,21,22-Hibernate容器映射技术(Set、List、Map) -mldn学习笔记 -hxzon
- fedora 18 19 20 21 22 23 怎么安装中文语言包
- 嵌入式开发第20、21、22、23天(触摸屏电子相册)
- thingking in java test5.9练习(19)(20)(21)(22)
- 创投日报:10月20至22日日收录投融资项目21起
- 21和22端口
- 10/21/22作业
- 如何在Fedora 17 18 19 20 21 22 23 系统中安装 openjdk 1.6 与 1.7 1.8 共存
- 【Java并发编程】之十一=十二-13-14-15-16-17--18-19-20-21-22-二十三
- 213中国跳棋(19)216(20)217(21)218(22)219(23)220(24)223(1)229(25)231(26)
- UE4将武器绑定到手上
- PendingIntent类api
- CSS3动画Animation的八大属性
- 【Java摸底自测】10道题目,测测你对Java基础知识掌握了多少
- 编程题汇总3
- 20、21、22
- [svn] 解决SVN冲突攻略(手册)
- iOS错误日志收集及分析
- 收藏HuKai关于Android性能优化的文章
- Spring源码分析
- maven部署项目到远程tomcat
- Mybatis源码学习笔记(三) 配置详解(properties 和environment)
- Cookie会话技术分析
- nyoj129 树的判定