首页 > 编程语言 > 详细

易错程序分析题 C++(dating)

时间:2021-06-03 00:54:45      阅读:30      评论:0      收藏:0      [点我收藏+]

本文仅整理C++中易错(不一定难)的题目,有疑问欢迎私聊。题目的答案需要使用编译器运行后自行对照,不便之处,敬请谅解。程序已经测试可以运行。

注意每题都有坑,认真分析。

#include <bits/stdc++.h>
using namespace std;
main()
{
    int a=12;
    a+=a-=a*a;
    cout<<a<<endl;
    return 0;
 } 

 

#include <bits/stdc++.h>
using namespace std;
main()
{
    int i,x=4,y=5;
    i=++x==5||++y==6;
    cout<<"x="<<x<<endl<<"y="<<y<<endl<<"i="<<i<<endl;
    return 0; 
 } 

 

#include <bits/stdc++.h>
using namespace std;
main()
{
    int i,x=4,y=5;
    i=x++==5&&y++==6;
    cout<<"x="<<x<<endl<<"y="<<y<<endl<<"i="<<i<<endl;
    return 0; 
 } 

 

#include <bits/stdc++.h>
using namespace std;
main()
{
    int x=1,y=2,z=3;
    x+=y+=z;
    cout<<(x<y?y:x)<<endl;
    cout<<(x<y?x++:y++)<<endl;
    cout<<x<<","<<y<<endl;
    cout<<(z+=x>y?x++:y++)<<endl;
    cout<<y<<","<<z<<endl;
    x=3;y=z=4;
    cout<<(z>y&&y==x?1:0)<<endl;
    cout<<(z>=y&&y>=x)<<endl;
    return 0;
 } 

 

本题输入为2473

#include <bits/stdc++.h>
using namespace std;
main()
{
    char ch;
    while(cin.get(ch)&&ch!=\n)
    switch(ch-2)
        {case 0:
         case 1:cout<<(char)(ch+4);
         case 2:cout<<(char)(ch+4);break;
         case 3:cout<<(char)(ch+3);
         default:cout<<(char)(ch+2);break;
        }
    cout<<endl;
    return 0;
 } 

 

#include <bits/stdc++.h>
using namespace std;
main()
{
    int a=10,y=0;
    do
    {
        a+=2;y+=a;
        cout<<"a="<<a<<",y="<<y<<endl;
        if(y>50) break;
    }
    while(a=14);
    return 0;
 } 

 

#include <bits/stdc++.h>
using namespace std;
main()
{
    int i;
    for (i=1;i<=5;i++)
        {
            if(i%2) cout<<"*";
            else continue;
            cout<<"#";
        }
        cout<<"$\n";
        return 0;
 } 

 

#include <bits/stdc++.h>
using namespace std;
main()
{
    int k=0;char c=A;
    do
    {switch(c++)
        {caseA:k++;break;
         caseB:k--;
         caseC:k+=2;break;
         caseD:k=k%2;continue;
         caseE:k=k*10;break;
         default:k=k/3;
         } 
    k++;
    }while(c<G);
    cout<<"k="<<k<<endl;
    return 0; 
 } 

 

#include <bits/stdc++.h>
using namespace std;
void fun (int x,int y)
{
    x=x*10;
    y=y+x;
    cout<<x<<\t<<y<<endl;
}

main()
{
    int a=2,b=3;
    fun(a+b,a*b);
    cout<<a<<\t<<b<<endl;
    return 0;
} 

 

易错程序分析题 C++(dating)

原文:https://www.cnblogs.com/Atsuhiro/p/14843402.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!