求c语言简单程序,代码一百行以上

mr空蓝 2011-12-26 02:34:06
rt,小女子水平比较低,请大家不要见笑~~(ps:最重要是简单易懂)
...全文
1427 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
tauke_wang 2011-12-31
  • 打赏
  • 举报
回复
百度一下
yayafu 2011-12-31
  • 打赏
  • 举报
回复
#include <stdio.h>

void main()
{
printf("1\n");
printf("2\n");
printf("3\n");
printf("4\n");
printf("5\n");
printf("6\n");
printf("7\n");
printf("8\n");
....
printf("100\n");
}
pany100 2011-12-31
  • 打赏
  • 举报
回复
楼上的,人家要C语言的,你给C++的干吗?
Binzo 2011-12-29
  • 打赏
  • 举报
回复
254行。
Binzo 2011-12-29
  • 打赏
  • 举报
回复
// Tic-Tac-Toe
// Plays the game of tic-tac-toe against a human opponent
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
// global constants
const char X = 'X';
const char O = 'O';
const char EMPTY = ' ';
const char TIE = 'T';
const char NO_ONE = 'N';
// function prototypes
void instructions();
char askYesNo(string question);
int askNumber(string question, int high, int low = 0);
char humanPiece();
char opponent(char piece);
void displayBoard(const vector<char>& board);
char winner(const vector<char>& board);
bool isLegal(const vector<char>& board, int move);
int humanMove(const vector<char>& board, char human);
int computerMove(vector<char> board, char computer);
void announceWinner(char winner, char computer, char human);
// main function
int main()
{
int move;
const int NUM_SQUARES = 9;
vector<char> board(NUM_SQUARES, EMPTY);
instructions();
char human = humanPiece();
char computer = opponent(human);
char turn = X;
displayBoard(board);
while (winner(board) == NO_ONE)
{
if (turn == human)
{
move = humanMove(board, human);
board[move] = human;
}
else
{
move = computerMove(board, computer);
board[move] = computer;
}
displayBoard(board);
turn = opponent(turn);
}
announceWinner(winner(board), computer, human);
system("pause");
return 0;
}
void instructions()
{
cout << "Welcome to the ultimate man-machine showdown: Tic-Tac-Toe.\n";
cout << "--where human brain is pit against silicon processor\n\n";
cout << "Make your move known by entering a number, 0 - 8. The number\n";
cout << "corresponds to the desired board position, as illustrated:\n\n";
cout << " 0 | 1 | 2\n";
cout << " ——————— \n";
cout << " 3 | 4 | 5\n";
cout << " ——————— \n";
cout << " 6 | 7 | 8\n\n";
cout << "Prepare yourself, human. The battle is about to begin.\n\n";
}
char askYesNo(string question)
{
char response;
do
{
cout << question << " (y/n): ";
cin >> response;
} while (response != 'y' && response != 'n');
return response;
}

int askNumber(string question, int high, int low)
{
int number;
do
{
cout << question << " (" << low << " - " << high << "): ";
cin >> number;
} while (number > high || number < low);
return number;
}

char humanPiece()
{
char go_first = askYesNo("Do you require the first move?");
if (go_first == 'y')
{
cout << "\nThen take the first move. You will need it.\n";
return X;
}
else
{
cout << "\nYour bravery will be your undoing. . . I will go first.\n";
return O;
}
}

char opponent(char piece)
{
if (piece == X)
{
return O;
}
else
{
return X;
}
}

void displayBoard(const vector<char>& board)
{
cout << "\n\t" << board[0] << " | " << board[1] << " | " << board[2];
cout << "\n\t" << "———————";
cout << "\n\t" << board[3] << " | " << board[4] << " | " << board[5];
cout << "\n\t" << "———————";
cout << "\n\t" << board[6] << " | " << board[7] << " | " << board[8];
cout << "\n\n";
}

char winner(const vector<char>& board)
{
// all possible winning rows
const int WINNING_ROWS[8][3] = { {0, 1, 2},
{3, 4, 5},
{6, 7, 8},
{0, 3, 6},
{1, 4, 7},
{2, 5, 8},
{0, 4, 8},
{2, 4, 6} };

const int TOTAL_ROWS = 8;
// if any winning row has three values that are the same (and not EMPTY),
// then we have a winner
for(int row = 0; row < TOTAL_ROWS; ++row)
{
if ( (board[WINNING_ROWS[row][0]] != EMPTY) &&
(board[WINNING_ROWS[row][0]] == board[WINNING_ROWS[row][1]]) &&
(board[WINNING_ROWS[row][1]] == board[WINNING_ROWS[row][2]]) )
{
return board[WINNING_ROWS[row][0]];
}
}
// since nobody has won, check for a tie (no empty squares left)
if (count(board.begin(), board.end(), EMPTY) == 0)
return TIE;
// since nobody has won and it isn’t a tie, the game ain’t over
return NO_ONE;
}

inline bool isLegal(int move, const vector<char>& board)
{
return (board[move] == EMPTY);
}

int humanMove(const vector<char>& board, char human)
{
int move = askNumber("Where will you move?", (board.size() - 1));
while (!isLegal(move, board))
{
cout << "\nThat square is already occupied, foolish human.\n";
move = askNumber("Where will you move?", (board.size() - 1));
}
cout << "Fine. . .\n";
return move;
}

int computerMove(vector<char> board, char computer)
{
unsigned int move = 0;
bool found = false;
//if computer can win on next move, that’s the move to make
while (!found && move < board.size())
{
if (isLegal(move, board))
{
board[move] = computer;
found = winner(board) == computer;
board[move] = EMPTY;
}
if (!found)
{
++move;
}
}
//otherwise, if human can win on next move, that’s the move to make
if (!found)
{
move = 0;
char human = opponent(computer);
while (!found && move < board.size())
{
if (isLegal(move, board))
{
board[move] = human;
found = winner(board) == human;
board[move] = EMPTY;
}
if (!found)
{
++move;
}
}
}
//otherwise, moving to the best open square is the move to make
if (!found)
{
move = 0;
unsigned int i = 0;
const int BEST_MOVES[] = {4, 0, 2, 6, 8, 1, 3, 5, 7};
//pick best open square
while (!found && i < board.size())
{
move = BEST_MOVES[i];
if (isLegal(move, board))
{
found = true;
}
++i;
}
}
cout << "I shall take square number " << move << endl;
return move;
}

void announceWinner(char winner, char computer, char human)
{
if (winner == computer)
{
cout << winner << "’s won!\n";
cout << "As I predicted, human, I am triumphant once more -- proof\n";
cout << "that computers are superior to humans in all regards.\n";
}
else if (winner == human)
{
cout << winner << "’s won!\n";
cout << "No, no! It cannot be! Somehow you tricked me, human.\n";
cout << "But never again! I, the computer, so swear it!\n";
}
else
{
cout << "It’s a tie.\n";
cout << "You were most lucky, human, and somehow managed to tie me.\n";
cout << "Celebrate. . . for this is the best you will ever achieve.\n";
}
}
dream0411 2011-12-27
  • 打赏
  • 举报
回复
推荐这个,经典百例,小问题、例子
http://www.kuqin.com/tiku/c100/
jiuzhoulh 2011-12-27
  • 打赏
  • 举报
回复
楼主到下载页面去搜索一下,很多的
dahaiI0 2011-12-27
  • 打赏
  • 举报
回复
多么质朴的一个姑娘,为啥用这个风尘味十足的头像,保护色?
  • 打赏
  • 举报
回复
网上很多的
a5131950 2011-12-26
  • 打赏
  • 举报
回复
给你了看不懂啊,
mayudong1 2011-12-26
  • 打赏
  • 举报
回复
#include <stdio.h>

void main()
{
printf("1\n");
printf("2\n");
printf("3\n");
printf("4\n");
...
printf("100\n");
}


应该没有比它更简单的了吧,哈哈
shen_wei 2011-12-26
  • 打赏
  • 举报
回复
C 语言100例,CSDN下载资源里面多了的。。
战在春秋 2011-12-26
  • 打赏
  • 举报
回复
可下载http://download.csdn.net/detail/rattles/1762238
内有100个实例。
C语言是一门广泛应用于系统编程、嵌入式软件和高性能应用开发的高级编程语言。本课程旨在向你介绍C语言的基本概念、语法和编程技巧,使你能够掌握C语言的核心知识,并能够用C语言编写简单到中等复杂程度的程序。课程针对0基础初学者,所以课程会由浅入深,由表及里的探索C语言知识框架,慢慢触及C语言本质,课程结构先由简单程序引入,然后拆分程序各个细节,让你逐渐掌握C语言编程的精髓。也会讲解C语言编译过程,怎样将人类描述的语言让计算机能够识别并按我们的意愿运C语言程序怎样运也会详细介绍,了解程序由静到动的过程。课程注重基础理论与实践结合,在重点关注C语言的基础理论知识的同时,我们会结合大量的实际编程练习,对每个重要的知识点和易错的地方都有代码演示并查看程序结果,深入理解C语言的运作原理。课程中一半内容是理论知识的讲解,另外一半是代码实操。课程由本人全部从0开始编写,从课程架构思考,内容组织,难易程度,章节划分,都融入了本人对C语言的思考,几乎全是干货,如果你渴望成为一名优秀的C语言编程者,那么不要犹豫!欢迎报名参加我们的课程,让我们一起踏上编程的旅程,共同学习和进步!课程源码:https://gitee.com/sliaowalker/c-language-programming

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧