高中信息竞赛-顺序程序的设计.pptVIP

  • 2
  • 0
  • 约8.41千字
  • 约 41页
  • 2018-09-14 发布于湖北
  • 举报
【例题题目】:交换两个变量的值。由键盘输入两个正整数a和b,编写程序完成两个数的互换。 #include iostream using namespace std; int main() { long a,b,c; cinab; c= a; {等价于步骤1} a = b; {等价于步骤2} b = c; {等价于步骤3} couta“ ”bendl; system(“pause”); } 【例题题目】:倒序 【问题描述】:从键盘输入一个三位数,将其各位数字倒序输出。 【文件输入】:输入一个三位数 【文件输出】:倒序输出此三位数 【样例输入】:123 【样例输出】:321 方法一: #include iostream using namespace std; int main() { long a,b,c,x,y; cinx; a=x/100; b=x/10%10; c=x%10; y=c*100+b*10+a; coutyendl; system(“pause”); } 方法二: #include iostream using namespace std; int main() { char a,b,c,d; cinabc; coutcbaend

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档