C語言-常用函式


Posted by pei_______ on 2022-04-26

// 大樂透

# include <stdio.h>
# include <stdlib.h>
# include <time.h>
# include <windows.h>
int main()
{
srand(time(0));
int sp = rand()%49 +1 ;
int balls[6];
int i,j;
for (i = 0; i < 6 ; i++ ){ 
    balls[i] = rand()%49 +1;

    // 過濾重複 
    for(j = 0; j < i; j++){     
        if(balls[j] ==balls[i]){
        i--; 
        }
    }    
} 

//泡沫排序法
for(i = 0; i < 6 ; i++){
    for(j = 0; j < (6 - 1 - i); j++){
        if (balls[j] > balls[j+1]){
            int cup = balls[j];
            balls[j] = balls[j+1];
            balls[j+1] = cup;
        }
    }
} 

printf("開獎號碼: \t\n");

for (i = 0; i < 6 ; i++ ){
    // 延遲印出 (間隔一秒)
    sleep(1);
    printf("%d\t",balls[i]);
} 
// 延遲印出 (間隔兩秒)
sleep(2);

printf("\n\n特別號: \n%d\n",sp);
return 0;
}
// 密碼輸入 

# include <stdio.h>
# include <conio.h> 
int main(){
char passwd[8];
printf("請輸入密碼: ");

int i = 0;
while ((passwd[i] = getch()) != '\r'){
    printf("*");
    i++;
}
passwd[i] = '\0';
printf("\n你輸入的密碼是: %s",passwd);

return 0;
}
// 大小寫轉換

# include <stdio.h>
# include <conio.h> 
# include <ctype.h> 
int main(){
printf("請輸入小寫字元1: ");
char ch1;
ch1 = getche();
printf("\n轉大寫是: %c\n",toupper(ch1));
printf("請輸入大寫字元1: ");
char ch2;
ch2 = getche();
printf("\n轉小寫是: %c\n",toupper(ch2));
return 0;
}

#C語言 #課堂筆記







Related Posts

React 入門 1 - Element, Function Component, & props

React 入門 1 - Element, Function Component, & props

關於 Fetch API

關於 Fetch API

Python Type Annotations for a Generator

Python Type Annotations for a Generator


Comments