// Fig. 10.3: fig10_03.c
// Card shuffling and dealing program using structures
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define CARDS 52
#define FACES 13
struct card {const char *face,*suit;};
typedef struct card Card; // new type name for struct card
// prototypes
void fillDeck(Card * const wDeck, const char * wFace[],
const char * wSuit[]);
void shuffle(Card * const wDeck);
void deal(const Card * const wDeck);
int main(void)
{
Card deck[CARDS]; // define array of Cards
// initialize array of pointers
const char *face[] = {"Ace", "Deuce", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King"};
// initialize array of pointers
const char *suit[] = {"Hearts", "Diamonds", "Clubs", "Spades"};
srand(time(NULL)); // randomize
fillDeck(deck, face, suit); // load the deck with Cards
shuffle(deck); // put Cards in random order
deal(deck); // deal all 52 Cards
}
// place strings into Card structures
void fillDeck(Card * const wDeck, const char * wFace[],
const char * wSuit[])
{
// loop through wDeck
for (size_t i = 0; i < CARDS; ++i) {
wDeck[i].face = wFace[i % FACES];
wDeck[i].suit = wSuit[i / FACES];
}
}
// shuffle cards
void shuffle(Card * const wDeck)
{
// loop through wDeck randomly swapping Cards
for (size_t i = 0; i < CARDS; ++i) {
size_t j = rand() % CARDS;
Card temp = wDeck[i];
wDeck[i] = wDeck[j];
wDeck[j] = temp;
}
}
// deal cards
void deal(const Card * const wDeck)
{
// loop through wDeck
for (size_t i = 0; i < CARDS; ++i) {
printf("%5s of %-8s%s", wDeck[i].face, wDeck[i].suit,
(i + 1) % 4 ? " " : "\n");
}
}
請撰寫一程式,讓使用者輸入三個正整數,分別為西元年、月、日,請計算此日期為當年的第幾天,需注意閏年;若輸入的日期有誤,請輸出「error」。 閏年: 西元年份除以4不可整除,為平年。 西元年份除以4可整除,且除以100不可整除,為閏年。 西元年份除以100可整除,且除以400不可整除,為平年。 西元年份除以400可整除,為閏年。 輸入說明 三個正整數,分別為西元年、月、日 輸出說明 此日期為當年的第幾天
Jul 14, 2023https://web.ntnu.edu.tw/~algo/Prime.html #include <stdio.h> //4 #include <math.h> #define N 100 //20000000 int sieve[N]={1,1}; // 1代表不是質數, 0代表是質數 void main() //eratosthenes { // 只需要刪掉sqrt(N)以下的質數的倍數。 for (int i=2; i<=sqrt(N); i++) if (!sieve[i])
Jun 20, 2023#TQC-Python 1 #8月2日 https://www.facebook.com/buddin5678/posts/pfbid025PJyB7QKfv7nSyK7ZARHmBFYJ2FwJiR2kx5e13ydgmBPmTXt4z18hojs55vk9poTl #PYA102.py 格式化輸出 #23.12 395.3 100.4617 564.329 ''' a = float(input()) b = float(input()) c = float(input()) d = float(input())
Jun 8, 2023//https://liuxiaozhu.github.io/algorithm-test/AlgorithmGossip/KnightTour.htm #include <stdio.h> #define N 8 int travel(int x, int y); int board[N][N] = {0}; int main(void) { travel(5, 6); //起始點 for(int i=0; i<N; i++) { for(int j=0; j<N; j++) printf("%3d", board[i][j]);
Apr 2, 2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up