//C++语言的if/else判断语句 #include#include using namespace std; int main() { char user_ans; cout << "现在正在下雨吗Y/N?" << endl; cin >> user_ans; if ('Y' == user_ans || 'y' == user_ans) { cout << "现在正在下雨" << endl; } else { cout << "现在没有下雨" << endl; cout << "今天会有太阳吗?" << endl; cin >> user_ans; if ('Y' == user_ans || 'y' == user_ans) { cout << "今天是晴天" << endl; } else cout << "今天是阴天" << endl; } system("pause"); }
#include#include #include #include using namespace std; int main() { vector numb;//使用vector bool u_agg = true; int cnt = 1; int buffer; float avg; char u_ans; while (u_agg) { cout << "第" << cnt << "个数字:\n"; cin >> buffer; numb.push_back(buffer);//vector的push_back() cout << "完成没有?Y/N\n"; cin >> u_ans; if ('N' == u_ans || 'n' == u_ans) { cnt++; continue; } else { u_agg = false; } } for (int i = 0; i < numb.size() - 2; i++)//size() //这段目的可看出来,输入相邻的两个数相加除以3 { int sum = 0; for (int j = i; j < i + 2; j++) sum = sum + numb[j]; avg = float(sum) / 3; cout << setiosflags(ios::fixed) << setprecision(2) << avg << " \n"; } system("pause"); }
#includeusing namespace std; unsigned long int cnt(int n)//计算n的从0和n的每个数的 阶乘之和 { unsigned long int sum = 0; for (int i = 1; i<=n; i++) { unsigned long int mul = 1; for (int j = 1; j <= i; j++) mul *= j; sum += mul; } return sum; } bool pass(int n)//判断输入的n是否在0和25之间 { if (n >= 0 && n <= 25) return true; else { cout << "n must between 0 and 25!\n"; return false; } } int main() { int n; unsigned long int sum; cout << "enter the number n:"; cin >> n; while (pass(n)) { sum = cnt(n); cout << sum; break; } system("pause"); }
#include成都创新互联公司是一家专业提供象山企业网站建设,专注与成都网站建设、网站制作、HTML5、小程序制作等业务。10年已为象山众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。//第一种图形 using namespace std; int main() { int j = 0; for (int i = 1; i <= 9; i++) { for (int k = 1; k <= i; k++) if ((k + j) % 9) cout << (k + j) % 9 << " "; else cout << 9 << " "; cout << endl; j = j + i; } system("pause"); } #include //第二种图形 using namespace std; int main() { int j = 0; for (int i = 1; i <= 9; i++) { for (int m = 0; m < 9 - i; m++) cout << " "; for (int k = 0; k <= i; k++) { if ((k + j) % 9) cout << (k + j) % 9 << " "; else cout << 9 << " "; } cout << endl; j = j + i; } system("pause"); } #include //第三种图 using namespace std; int main() { int j = 0; for (int i = 1; i <= 9; i++) { for (int k = 1; k <= 8; k++) if ((k + j) % 9) cout << (k + j) % 9 << " "; else cout << 9 << " "; cout << endl; j = j + 8; } system("pause"); }
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。