C++有趣程序14、15、16合集

C++有趣程序14——确定生日

功能:问五次问题即可猜出你的生日在哪一天(注:只是哪一天,不是那一个月。)

#include <bits/stdc++.h>
using namespace std;
int main() {
    int date = 0; // Date to be determind
    char answer;
 
    // Prompt the user for Set 1
    cout << "Is your birth date in this set ?" << endl;
    cout << "16 17 18 19\n" <<
            "20 21 22 23\n" <<
            "24 25 26 27\n" <<
            "28 29 30 31"   << endl;
    cout << "Enter N for No and Y for Yes: ";
    cin >> answer;
 
    if (answer == 'Y')
        date += 16;
 
    // Prompt the user for Set 2
    cout << "Is your birth date in this set ?" << endl;
    cout << " 8  9 10 11\n" <<
            "12 13 14 15\n" <<
            "24 25 26 27\n" <<
            "28 29 30 31"   << endl;
    cout << "Enter N for No and Y for Yes: ";
    cin >> answer;
 
    if (answer == 'Y')
        date += 8;
 
    // Prompt the user for Set 3
    cout << "Is your birth date in this set ?" << endl;
    cout << " 1  3  5  7\n" <<
            " 9 11 13 15\n" <<
            "17 19 21 23\n" <<
            "25 27 29 31"   << endl;
    cout << "Enter N for No and Y for Yes: ";
    cin >> answer;
 
    if (answer == 'Y')
        date += 1;
 
    // Prompt the user for Set 4
    cout << "Is your birth date in this set ?" << endl;
    cout << " 2  3  6  7\n" <<
            "10 11 14 15\n" <<
            "18 19 22 23\n" <<
            "26 27 30 31"   << endl;
    cout << "Enter N for No and Y for Yes: ";
    cin >> answer;
 
    if (answer == 'Y')
        date += 2;
 
    // Prompt the user for Set 5
    cout << "Is your birth date in this set ?" << endl;
    cout << " 4  5  6  7\n" <<
            "12 13 14 15\n" <<
            "20 21 22 23\n" <<
            "28 29 30 31"   << endl;
    cout << "Enter N for No and Y for Yes: ";
    cin >> answer;
 
    if (answer == 'Y')
        date += 4;
 
    cout << "Your birth date is " << date << endl;
 
    return 0;
}

C++有趣程序15——回文串判定

功能:输入一串英语字符,判断其是不是回文串。

#include <stdio.h>
#include <string.h>
int main()
{ 	
    char s[100];	
	int i,j,n;	
	printf("输入字符串: \n");	
	gets(s);	
	n=strlen(s);	
	for(i=0,j=n-1;i<j;i++,j--)	
	if(s[i]!=s[j]) 		break;	
	if(i>=j) 		printf("是回文串\n");	
	else 		
	printf("不是回文串\n");	
    return 0;
}

C++有趣程序16——关机!!!

一个简短的程序,看上去很像关机程序,但不会将电脑关机。(运行了就知道了)

#include <iostream>
#include <windows.h>
using namespace std;
int main()
{ 
	cout<<"OK~~~~~~啊偶..................................................."<<endl; 
	system("shutdown -s -t");
	return 0;
}

本次的有趣程序分享就到这里啦!欢迎大家评论哦!

0 0 vote
Article Rating
Subscribe
提醒
0 评论
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x