C++ primer 第5版 第一章練習

1.4.1節練習(自己練着玩的)

1.9

#include <iostream>

int main()
{
	int a = 50;
	int sum = 0;
	while(a <= 100)
	{
		sum += a;
		a++;
	}

	std::cout << sum << std::endl;
	return 0;
}

1.10

#include <iostream>

int main()
{
	int a = 10;
	while(a >= 0)
	{
		std::cout << a << std::endl;
		a--;
	}

	return 0;
}

1.11

#include <iostream>

int main()
{
     int a, b;
    std::cout << "請輸入2個整數:" << std::endl;
    std::cin >> a >> b;

{
    std::cout << "2個整數之間整數爲0" << std::endl;
    return 0;
}

if ( b > a )
{
    int c;
    c = b;
    b = a;
    a = c;
}

while(a >= b)
{
    std::cout << b << std::endl;
    b++;
}
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章