//
// main.c
//
//
// Created by Vision on 14-8-29.
//
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(int argc, const char * argv[])
{
//1.打印1——100
// int n = 0;
// while (n <= 100) {
// printf("%d\n", n++);
// }
//2.打印偶數
// int n = 0;
// while (n <= 100) {
// if (n % 2 == 0) {
// printf("%d\n", n);
// }
// n++;
// }
// 方法2
// int n = 1;
// while (n <= 100) {
// printf("%d\n", n);
// n +=2;
// }
//3.打印奇數
// int n = 0;
// while (n <= 100) {
// if (n % 2 == 1) {
// printf("%d\n", n);
// }
// n++;
// }
// 方法2
// int n = 2;
// while (n <= 100) {
// printf("%d\n", n);
// n +=2;
// }
//4.打印7的倍數
// int n = 0;
// while (n <= 100) {
// if (n % 7 == 0) {
// printf("%d\n", n);
//
// }
// n++;
// }
//5.打印個位是7
// int n = 0;
// while (n <= 100) {
// if (n % 10 == 7) {
// printf("%d\n", n);
// }
// n++;
// }
//6打印十位是7
// int n = 0;
// while (n <=100) {
// if (n / 10 == 7) {
// printf("%d\n", n);
// }
// n++;
// }
//7.打印不是7的倍速 並且不包含7 的數
// int n = 0;
// while (n <= 100) {
// if ((n % 7 != 0) && (n / 10 !=7) && (n % 10 != 7)) {
// printf("%d\n", n);
// }
//
// n++;
// }
//
//8.隨機數
// srand(time(NULL));
// int random = rand();
// printf("%d\n", random);
//打印13 - 32之間的隨機數
// unsigned int random = arc4random() % (32 - 13 + 1) + 13;
// printf("%u\n", random);
//打印10 - 20 和80 - 90 區間的隨機數
//方法1
// unsigned int random = 0, r = 0;
// r = arc4random() % 2;
// if (0 == r) {
// random = arc4random() % (20 - 10 + 1) + 10;
// } else {
// random = arc4random() % (90 - 80 + 1) + 80;
// }
// printf("random = %u\n", random);
//方法2
// unsigned int random = arc4random() % (90 - 69 + 1) + 69;
// if (random < 80) {
// random -= 59;
// }
// printf("random = %u", random);
//逼格很高的寫法
// unsigned int random = arc4random() % (20 - 10 + 1) + 10;
// random += (arc4random() % 2) * 70;
// printf("random = %u\n", random);
//隨機產生n個10 - 30 的數
// int n = 0;
// int i = 0;
// scanf("%d", &n);
// while (i < n) {
// unsigned int random = arc4random() % (30 - 10 + 1) + 10;
// printf("%d\n", random);
// i++;
// }
//隨機產生n個30 - 70 的數,並且輸出最大值
// int n = 0, i = 0, a = 0;
// scanf("%d", &n);
// while (i < n) {
// unsigned int random = arc4random() % (70 - 30 +1) + 30;
// printf("%u\n", random);
// if (random > a) {
// a = random;
// }
// i++;
// }
// printf("最大%d\n", a);
//隨機產生n個30 - 70 的數,並且輸出最小值
// int n = 0;
// unsigned min = 90;
// scanf("%d", &n);
// while (n > 0) {
// unsigned int random = arc4random() % (70 - 30 + 1) + 30;
// printf("%u\n", random);
// if (random < min) {
// min = random;
// }
// n--;
// }
// printf("%u\n", min);
//9.while循環的用法 (輸出0 - 100的數)
// int n = 0;
// while (n <= 100) {
// printf("%d\n", n);
// n++;
// }
// int n = 0;
// while (1) {
// printf("%d\n", n);
// n++;
// if (n > 100) {
// break;
// }
// }
//輸出 0 - 100 中的奇數
// int n = 0;
// while (n <= 100) {
// if (n % 2 == 0) {
// n++;
// continue;
// }
// printf("%d\n", n);
// n++;
// }
//10.do - whil用法
// int n =0;
// do {
// printf("%d\n",n);
// n++;
// } while (n <= 100);
//
//11.for循環語句的用法
// for (int i = 1; i <= 100; i++) {
// printf("%d\n", i);
// }
//7的倍數
// for ( int i = 0; i <= 100; i++) {
// if (i % 7 == 0) {
// printf("%d\n", i);
// }
// }
//個位7
// for (int i = 1; i <= 100; i++) {
// if (i % 10 == 7) {
// printf("%d\n", i);
//
// }
// }
//十位7
// for (int i = 1; i <= 100; i++) {
// if (i / 10 == 7) {
// printf("%d\n", i);
// }
// }
//不包含7
// for (int i = 1; i <= 100; i++) {
// if ((i / 10 != 7) && (i % 10 != 7) && (i % 7 != 0)) {
// printf("%d\n", i);
// }
// }
//12. 輸出:
// 1
// 1 2
// 1 2 3
//1 2 3 4
// for (int j = 1; j <= 4; j++) {
//
// for (int i = 1; i <= (4 - j) ; i++) {
// printf(" ");
// }
// for (int i = 1; i <= j; i++) {
// printf("%d ", i);
// }
// printf("\n");
// }
// 輸出:
// 1 1 1
// 1 1 1
// 1 1 1
// for (int i = 1; i <= 3; i++) {
// for (int j = 1; j <= 3; j++) {
// printf(" 1");
// }
// printf("\n");
// }
//13.輸出 乘法口訣
// for (int i = 1; i< 10; i++) {
// for (int j = 1; j <= i; j++) {
// printf("%d * %d = %2d ", j, i, i * j);
// }
// printf("\n");
// }
//14.輸出三個數相加 等於2的個數
// int n = 0;
// for (int i = 0; i < 10; i++) {
// for (int j = 0; j < 10; j++) {
// for (int k = 0; k < 10; k++) {
// if ((i + j + k) == 2) {
// n++;
//
// }
//
// }
// }
// }
// printf("%d\n",n);
return 0;
}
C語言總結3
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.