2019年6月26日 星期三

C語言(online c) (列印出3個 圖形)


C語言(online c) (列印出3個 圖形)



#include<stdio.h>
#include<math.h>

int main()
{
    printf("\t\t印出 3個圖形\n");
    for (int i=1;i<=5;i++)
    {
        for(int j=1;j<=i;j++)
        {
            printf("●");
        }
        printf("\n");
    } 
   
    printf("\n");
    for (int i=1;i<=5;i++)
    {
        for(int j=1;j<=5-i;j++)
            printf(" ");
        for (int j=1;j<=i;j++)
            printf("●");
        printf("\n");
    } 
   
    printf("\n");
    for (int i=1;i<=5;i=i+2)
    {
        for(int j=1;j<=5-i;j=j+2)
            printf(" ");
        for (int j=1;j<=i;j++)
            printf("●");
        printf("\n");
    } 
   
   
   
   
    return 0;
}       


C語言(online c) 寫簡單的 程式 (印出99乘法表 )

C語言(online c) 寫簡單的 程式 (印出99乘法表 )

#include<stdio.h>
#include<math.h>

int main()
{
    printf("\t\t印出99乘法表\n");
    for (int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            printf("%2d*%2d=%2d\t",i,j,i*j);
        }
        printf("\n");
    }   
    return 0;
}       


印出99乘法表
 1* 1= 1 1* 2= 2 1* 3= 3 1* 4= 4 1* 5= 5 1* 6= 6 1* 7= 7 1* 8= 8 1* 9= 9
 2* 1= 2 2* 2= 4 2* 3= 6 2* 4= 8 2* 5=10 2* 6=12 2* 7=14 2* 8=16 2* 9=18
 3* 1= 3 3* 2= 6 3* 3= 9 3* 4=12 3* 5=15 3* 6=18 3* 7=21 3* 8=24 3* 9=27
 4* 1= 4 4* 2= 8 4* 3=12 4* 4=16 4* 5=20 4* 6=24 4* 7=28 4* 8=32 4* 9=36
 5* 1= 5 5* 2=10 5* 3=15 5* 4=20 5* 5=25 5* 6=30 5* 7=35 5* 8=40 5* 9=45
 6* 1= 6 6* 2=12 6* 3=18 6* 4=24 6* 5=30 6* 6=36 6* 7=42 6* 8=48 6* 9=54
 7* 1= 7 7* 2=14 7* 3=21 7* 4=28 7* 5=35 7* 6=42 7* 7=49 7* 8=56 7* 9=63
 8* 1= 8 8* 2=16 8* 3=24 8* 4=32 8* 5=40 8* 6=48 8* 7=56 8* 8=64 8* 9=72
 9* 1= 9 9* 2=18 9* 3=27 9* 4=36 9* 5=45 9* 6=54 9* 7=63 9* 8=72 9* 9=81

C語言(online c) 寫簡單的 程式 ( 輸入2個數值 印出2個數值間的質數及質數的個數 )

C語言(online c) 寫簡單的 程式 ( 輸入2個數值 印出2個數值間的質數及質數的個數 )

#include<stdio.h>
#include<math.h>

int main()
{
    int x,y,i,j ,cnt=0 ,cnt2=0;
    printf("輸入2個數值 由小到大\n");
    scanf("%d %d", &x,&y);
    printf("你輸入的2個數值=%d %d\n", x,y);
   
    for (i=x;i<=y;i++)
    {
        cnt=0;
        for (j=2;j<=i-1;j++)
        {
            if (i%j==0)
                cnt++;
        }
        if (cnt==0)       
        {
            printf("%d\t",i);
            cnt2++;
        }   
    }
   
    printf("\n\n%d到%d的質數共有%d",x,y,cnt2);
    return 0;
}       


Stdin Inputs...
5 37

輸入2個數值 由小到大
你輸入的2個數值=5 37
5 7 11 13 17 19 23 29 31 37

5到37的質數共有10

C語言(online c) 寫簡單的 程式 ( 輸入n個位數的數值並計算 (1)總和 (2)平均值 (3)最大值 (4)最小值 (5)第2大的數 )

C語言(online c) 寫簡單的 程式 ( 輸入n個位數的數值並計算  (1)總和 (2)平均值 (3)最大值  (4)最小值 (5)第2大的數 )

輸入n個位數的數值並計算
(1)總和 (2)平均值 (3)最大值  (4)最小值 (5)第2大的數

#include<stdio.h>
#include<math.h>
#define max(x,y) (x > y?x:y)
#define min(x,y) (x < y?x:y)

int bubble_sort(int A[50], int n){
  int i, j, flag ,temp;
  for(i = 0; i<n-1; i++){ //n個數字排序,只用 n-1 回
    int flag = 0; //表示有無發生交換
    for(j = 0; j < n-i; j++){ //從第一個數字開始比較,直到最後一個數字
      if(A[j]>A[j+1]){
        temp=A[j];
        A[j]=A[j+1];
        A[j+1]=temp;
        flag = 1;
      }
    }
    if(flag == 0) break; //此回合沒有發生交換
  }
}

int main()
{
    int n,i,x[50] ,maxnum ,minnum ;
    float sum , avg ;
    printf("輸入n個位數的數值 並計算(1)總和 (2)平均值 (3)最大值  (4)最小值 (5)第2大的數請\n");
    printf("請輸入n個數字 n:\n");
    scanf("%d ", &n);
    for (i=0;i<=n-1;i++)
        scanf("%d ", &x[i]);

    printf("你輸入的 n=%d\n\n", n);
    printf("你輸入的數值= ");
    for (i=0;i<=n-1;i++)
        printf("%d ", x[i]);
   
    //======================
    maxnum=max(x[0],x[1]);
    for (i=2;i<=n-1;i++)
        maxnum=max(maxnum,x[i]);
    printf("\n最大值=%d",maxnum);
   
    //======================
    minnum=min(x[0],x[1]);
    for (i=2;i<=n-1;i++)
        minnum=min(minnum,x[i]);
    printf("\n最小值=%d",minnum);   

    //======================       
    for (i=0;i<=n-1;i++)
        sum=sum+x[i];
    avg=sum/n;   
    printf("\n總和=%0.0f",sum); 
    printf("\n平均值=%0.2f",avg); 
   
    printf("\n");
    printf("\n排序後的輸入數值為"); 
   
    bubble_sort(x,n-1);
    for (i=0;i<=n-1;i++)
        printf("%d ", x[i]);
    printf("\n第2大數值=%d",x[1]);

    return 0;
}       
輸入n個位數的數值 並計算(1)總和 (2)平均值 (3)最大值  (4)最小值 (5)第2大的數請
請輸入n個數字 n:
你輸入的 n=5

你輸入的數值= 12 23 45 54 15
最大值=54
最小值=12
總和=149
平均值=29.80

排序後的輸入數值為12 15 23 45 54
第2大數值=15

C語言(online c) (起點座標為0 每一間格1,2,3,4,5.... 請利用迴圈印出a1....a8的座標值)

C語言(online c) (起點座標為0   每一間格1,2,3,4,5....  請利用迴圈印出a1....a8的座標值)

起點座標為0
每一間格1,2,3,4,5....
請利用迴圈印出a1....a8的座標值
a(1,0),a(3,0).a(6,10)....

起點座標為10
每一間格1,2,3,4,5....
請利用迴圈印出a1....a8的座標值
a(11,0),a(13,0).a(16,0)....

#include<stdio.h>
#include<math.h>
int main()
{
    int i=1 , s=0 , sum=0 , j=8 ;
    printf("請利用迴圈印出a1....a8的座標值\n");
    printf("\n起點座標為%d,每一間格1,2,3,4,5....\n",s);
    for(i=1;i<=j;i++)
    {   
        sum=sum+i;
        printf("\na(%d,%d)",sum,s);
    }

    s=10;
    sum=s;
    printf("\n\n起點座標為%d,每一間格1,2,3,4,5....\n",s);
    for(i=1;i<=j;i++)
    {   
        sum=sum+i;
        printf("\na(%d,%d)",sum,s);
    }
   
    return 0;
}       




請利用迴圈印出a1....a8的座標值

起點座標為0,每一間格1,2,3,4,5....

a(1,0)
a(3,0)
a(6,0)
a(10,0)
a(15,0)
a(21,0)
a(28,0)
a(36,0)

起點座標為10,每一間格1,2,3,4,5....

a(11,10)
a(13,10)
a(16,10)
a(20,10)
a(25,10)
a(31,10)
a(38,10)
a(46,10)

C語言(online c) (請算 2+5+8+...32的總和 使用do , for , while)

C語言(online c) (請算 2+5+8+...32的總和 使用do , for , while)

#include<stdio.h>
#include<math.h>
int main()
{
    int i,s=0 ,n=32;
    printf("請印出2+5+8+..%d的總和\n",n);

    for(i=2;i<=n;i=i+3)
        s=s+i;
    printf("\nfor...... 2+5+8....+%d的總和=%d\n\n",n,s);

    //===========================
    s=0;
    i=2;
    do
    {
        s=s+i;
        i=i+3;
    }   
    while (i<=n) ; 
    printf("\ndo...loop 2+5+8....+%d的總和=%d\n\n",n,s);
   
    //===========================
    s=0;
    i=2;
    while(i<=n)
    {
        s=s+i;
        i=i+3;
    }   
    printf("\nwhile.... 2+5+8....+%d的總和=%d\n\n",n,s);

    //===========================
    return 0;
}       


請印出2+5+8+..32的總和

for...... 2+5+8....+32的總和=187


do...loop 2+5+8....+32的總和=187


while.... 2+5+8....+32的總和=187

C語言(online c) (請計算1+4+7+...31的總和 使用do , for , while)

C語言(online c) (請計算1+4+7+...31的總和 使用do , for , while)

#include<stdio.h>
#include<math.h>
int main()
{
    int i,s=0 ,n=31;
    printf("請印出1+4+7+..%d的總和\n",n);

    for(i=1;i<=n;i=i+3)
        s=s+i;
    printf("\nfor...... 1+2+....+%d的總和=%d\n\n",n,s);

    //===========================
    s=0;
    i=1;
    do
    {
        s=s+i;
        i=i+3;
    }   
    while (i<=n) ; 
    printf("\ndo...loop 1+2+....+%d的總和=%d\n\n",n,s);
   
    //===========================
    s=0;
    i=1;
    while(i<=n)
    {
        s=s+i;
        i=i+3;
    }   
    printf("\nwhile.... 1+2+....+%d的總和=%d\n\n",n,s);

    //===========================
    return 0;
}       


請印出1+4+7+..31的總和

for...... 1+2+....+31的總和=176

do...loop 1+2+....+31的總和=176

while.... 1+2+....+31的總和=176

C語言(online c) (請輸入數字n 並計算1+2+...n的總和 使用do , for , while)

C語言(online c) (請輸入數字n 並計算1+2+...n的總和 使用do  , for  , while)

#include<stdio.h>
#include<math.h>
int main()
{
    int n,i;
    printf("請印出1..n的總和\n");
    printf("請輸入1個數字 n:\n");
    scanf("%d ", &n);
    printf("你輸入的 n=%d\n\n", n);
   
    int s=0 ;
    for(int i=1;i<=n;i++)
        s=s+i;
    printf("\nfor...... 1+2+....+%d的總和=%d\n\n",n,s);

    //===========================
    s=0;
    i=1;
    do
    {
        s=s+i;
        i++;
    }   
    while (i<=n) ; 
    printf("\ndo...loop 1+2+....+%d的總和=%d\n\n",n,s);
   
    //===========================
    s=0;
    i=1;
    while(i<=n)
    {
        s=s+i;
        i++;
    }   
    printf("\nwhile.... 1+2+....+%d的總和=%d\n\n",n,s);

    //===========================
    return 0;

}       

Stdin Inputs...
100

請印出1..n的總和
請輸入1個數字 n:
你輸入的 n=100

for...... 1+2+....+100的總和=5050

do...loop 1+2+....+100的總和=5050


while.... 1+2+....+100的總和=5050

C語言(online c) (請輸入二個數字 並印出二個數字的因數及因數的個數)

C語言(online c)  (請輸入二個數字 並印出二個數字的因數及因數的個數)

#include<stdio.h>
#include<math.h>
int main()
{
    int m,n;
    printf("請輸入2個數字 m , n:\n");
    scanf("%d %d", &m ,&n);
    printf("你輸入的 m=%d n=%d\n\n",m , n);
    int s1=0 , s2=0;
    for(int i=1;i<=m;i++)
    {
        if(m%i==0)
        {
            printf("%d\t",i);
            s1++;
        } 
    }
    printf("\n%d的因數有%d個\n\n",m,s1);
 
    for(int i=1;i<=n;i++)
    {
        if(n%i==0)
        { 
            printf("%d\t",i);
            s2++;
        } 
    }
    printf("\n%d的因數有%d個\n",n,s2);
 
 
    return 0;
}     


Stdin Inputs...
120 7

請印出1..m之間 n的倍數的數
請輸入2個數字 m , n:
你輸入的 m=120 n=7

1 2 3 4 5 6 8 10 12 15 20 24 30 40 60 120
120的因數有16個

1 7
7的因數有2個

C語言(online c) ( 請輸入2個數字 印出1....m間 n的倍數的數 )

C語言(online c) ( 請輸入2個數字 印出1....m間 n的倍數的數 )

#include<stdio.h>
#include<math.h>
int main()
{
    int m,n;
    printf("請印出1..m之間 n的倍數的數\n");
    printf("請輸入2個數字 m , n:\n");
    scanf("%d %d", &m ,&n);
    printf("你輸入的 m=%d n=%d\n",m , n);
 
    for(int i=1;i<=m;i++)
    {
        if(i%n==0)
            printf("%d\t",i);
    }
   
    return 0;
}       

stdin Inputs...
120 7

請印出1..m之間 n的倍數的數
請輸入2個數字 m , n:
你輸入的 m=120 n=7
7 14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119

C語言(online c) (寫簡單的 程式 印出1..100 之間 6的倍數的數值)

C語言(online c) (寫簡單的 程式 印出1..100 之間 6的倍數的數值)

#include<stdio.h>
#include<math.h>
int main()
{
    printf("請印出1..100之間6的倍數的數\n");
    for(int i=1;i<=100;i++)
    {
        if(i%6==0)
            printf("%d\t",i);
    }
   
    return 0;
}       

請印出1..100之間6的倍數的數
6 12 18 24 30 36 42 48 54 60 66 72 78 84 90 96

C語言(online c) (寫簡單的程式 請輸入一個數字印出1....n 利用 for , do..loop while )

C語言(online c) (寫簡單的程式 請輸入一個數字印出1....n 利用 for , do..loop  while )

#include<stdio.h>
#include<math.h>
int main()
{
    int x;
 
    printf("請輸入一個數字:\n");
    scanf("%d", &x);
    printf("你輸入的 N=%d\n",x);
   
     
    for(int i=1;i<=x;i++)
        printf("%d\t",i);
    printf("\n"); 
   
    //===============
    int j=1;
    while(j<=x)
    {
        printf("%d\t",j);
        j++;
    }   
    printf("\n"); 
   
    //===============
    int k=1;
    do{
        printf("%d\t",k);
        k++;
    }while (k<=x);
   
   
    return 0;
}       



Stdin Inputs...
12

請輸入一個數字:
你輸入的 N=12
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12

C語言(online c) (寫簡單的 程式 印出1..20 for do while 三種方式)

C語言(online c) (寫簡單的 程式 印出1..20 for do while 三種方式)

#include<stdio.h>
#include<math.h>
int main()
{
    for(int i=1;i<=20;i++)
        printf("%d\t",i);
    printf("\n"); 
   
    //===============
    int j=1;
    while(j<=20)
    {
        printf("%d\t",j);
        j++;
    }   
    printf("\n"); 
   
    //===============
    int k=1;
    do{
        printf("%d\t",k);
        k++;
    }while (k<=20);
   
   
    return 0;
}       


輸出畫面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

C語言(online c) (寫簡單的 程式 計算個人綜合所得稅)

C語言(online c) (寫簡單的 程式 計算個人綜合所得稅)

個人綜合所得稅採用累進稅率
1) 個人綜合所得54萬以下                  課5%
2) 個人綜合所得54萬到121萬以下    課12%
3) 個人綜合所得121萬到242萬以下  課20%
4) 個人綜合所得242萬到453萬以下  課30%
5) 個人綜合所得453萬以上                課40%


課稅級距
5%
TWD 0~540,000
12%
TWD 540,0011,210,000
20%
TWD 1,210,0012,420,000
30%
TWD 2,420,0014,530,000
40%
TWD 4,530,001以上


#include<stdio.h>
#include<math.h>
int main()
{
    int x;
 
    printf("請輸入個人綜合所得數字:\n");
    scanf("%d", &x);
    printf("你輸入的 N=%d\n",x);
 
    //=============================
    printf("\n14. 需繳交所得稅為:");
    if (x<=540000)
        printf("5% --> %5.2f\n",x*0.05);
    else if (x>540000 && x<=1210000)
        printf("12% --> %5.2f\n",x*0.12);
    else if (x>1210000 && x<=2420000)
        printf("20% --> %5.2f\n",x*0.2);
    else if (x>2420000 && x<=4530000)
        printf("30% --> %5.2f\n",x*0.3);
    else
        printf("40% --> %5.2f\n",x*0.4);

     
    return 0;
}     


Stdin Inputs...
32530008

請輸入個人綜合所得數字:
你輸入的 N=32530008

14. 需繳交所得稅為:40% -> 13012003.20

C語言(online c) 寫簡單的 程式 ( 請輸入1或2或3等數字輸入1出現剪刀 輸入2出現石頭 輸入3出現布 )

C語言(online c) 寫簡單的 程式 ( 請輸入1或2或3等數字輸入1出現剪刀  輸入2出現石頭  輸入3出現布 )

#include<stdio.h>
#include<math.h>

int main()
{
    int x;
 
    printf("請輸入1或2或3等數字(1/2/3):\n");
    scanf("%d", &x);
    printf("你輸入的 N=%3d\n",x);
 
    //=============================
    printf("\n13.出現的是:");
    if (x== 1)
        printf("剪刀\n",x);
    else
        if (x==2)
            printf("石頭\n",x);
        else
            if (x==3)
                printf("布\n",x);
            else
                printf("輸入錯誤\n",x);
             
     
    return 0;
}     


Stdin Inputs...
3
請輸入1或2或3等數字(1/2/3):
你輸入的 N=  3

13.出現的是:布

2019年6月25日 星期二

C語言(online c) 寫簡單的 程式 ( 輸入一個數值判斷數 一位數顯示■ 二位數顯示● 三位數顯示★ 其他位數 ■ ● ★ )

C語言(online c) 寫簡單的 程式 ( 輸入一個數值判斷數 一位數顯示■  二位數顯示●   三位數顯示★   其他位數 ■ ● ★ )

#include<stdio.h>
#include<math.h>

int main()
{
    int x;
 
    printf("請輸入1個整數數字(1~2000):\n");
    scanf("%d ", &x);
    printf("你輸入的 N=%3d\n",x);
 
    //=============================
    printf("\n12.出現的是:");
    if (x>= 0 & x<10)
        printf("一位數%3d ■\n",x);
    else
        if (x>=10 & x<100)
            printf("二位數%3d ● \n",x);
        else
            if (x>=100 & x<1000)
                printf("三位數%3d ★ \n",x);
            else
                printf("%3d ■ ● ★ \n",x);
             
     
    return 0;
}     


Stdin Inputs...
2335

請輸入1個整數數字(1~2000):
你輸入的 N=2335

12.出現的是:2335 ■ ● ★ 

C語言(online c) 寫簡單的 程式 ( 輸入2個數值 判斷二者的大小關係 :大於 小於 相等 )

C語言(online c) 寫簡單的 程式 ( 輸入2個數值 判斷二者的大小關係 :大於 小於 相等 )

#include<stdio.h>
#include<math.h>
#define max(x,y)         (x > y?x:y)
int main()
{
    int x1 ,x2;
 
    printf("請輸入2個整數數字(1~200):\n");
    scanf("%d %d ", &x1,&x2);
    printf("你輸入的 N=%3d, %3d\n",x1,x2);
 
    //=============================
    printf("\n11. 2個整數的關係是:");
    if (x1>x2)
        printf("%3d大於%3d\n",x1,x2);
    else
        if (x1==x2)
            printf("%3d等於%3d\n",x1,x2);
        else
            printf("%3d小於%3d\n",x1,x2);
     
     
    return 0;
}     


Stdin Inputs...
23 12


請輸入2個整數數字(1~200):
你輸入的 N= 23,  12

11. 2個整數的關係是: 23大於 12

C語言(online c) 寫簡單的 程式 ( 輸入3個數值 找出其最大值 )

C語言(online c) 寫簡單的 程式 ( 輸入3個數值 找出其最大值 )

#include<stdio.h>
#include<math.h>
#define max(x,y)         (x > y?x:y)
int main()
{
    int x1 ,x2,x3 ,a ,b;
   
    printf("請輸入3個整數數字(1~200):\n");
    scanf("%d %d %d ", &x1,&x2,&x3);
    printf("你輸入的 N=%3d, %3d, %3d\n", x1,x2,x3);
   
    //=============================
    printf("\n10. 最大的數字是:");
    a=max(x1,x2);
    b=max(a,x3);
    printf("%3d\n",b);

    return 0;
}       




Stdin Inputs...

請輸入3個整數數字(1~200):
你輸入的 N= 23,  45,  12

10. 最大的數字是: 45

C語言(online c) 寫簡單的 程式 ( 輸入一個數值 並判斷數值為......)

C語言(online c) 寫簡單的 程式 ( 輸入一個數值 並判斷數值為......)
1)輸入一個數值 並判斷數值是否為 正數或負數 ?
2)輸入一個數值 並判斷數值是否為 奇數或偶數 ?
3)輸入一個數值 並判斷數值是否為 3的倍數 ?
4)輸入一個數值 並判斷數值是否為 200的因數 ?
5)輸入一個數值 並判斷數值是否為 介於100到200之間 ?
6)輸入一個數值 並判斷數值是否為 3位數(100-999)?
7)輸入一個數值 並判斷數值是否為 2與3的公倍數 ?
8)輸入一個數值 並判斷數值是否為 正整數?


#include<stdio.h>
#include<math.h>
int main()
{
    int x ;
   
    printf("請輸入一數字( 1~200):\n");
    scanf("%3f", &x);
    printf("你輸入的 N=%3f\n", x);
   
    //=============================
    printf("\n1. 此數字是:");
    if (x == 0)                 /* x 要小寫 */
        printf("零");
    else
        {
          if (x > 0)
                printf("正數");
          else
                printf("負數");
        }
       
    //=============================
    printf("\n2. 此數字是:");
    if (x % 2 == 0)
        printf("偶數");
    else
        printf("奇數");

    //=============================
    printf("\n3. 此數字是否為3的倍數:");
    if (x % 3 == 0)
        printf("3的倍數");
    else
        printf("不是3的倍數");

    //=============================
    printf("\n4. 此數字是否為200的因數:");
    if (200 % x == 0)
        printf("200的因數");
    else
        printf("不是200的因數");

    //=============================
    printf("\n5. 此數字是否介於100到200之間:");
    if (x<=100)
        printf("不是 , 小於100");
    else
        if (x>200)
            printf("不是 , 大於200");
        else
            printf("是 , 介於100到200間的數值");

    //=============================
    printf("\n6. 此數字是否為3位數:");
    if ((x>99) & (x<1000))
        printf("是3位數");
    else
        printf("不是3位數");
       
    //=============================
    printf("\n7. 此數字是否為2與3的公倍數:");
    if ((x %2 ==0 ) & (x %3 ==0))
        printf("是2與3的公倍數");
    else
        printf("不是2與3的公倍數");
       
    //=============================
    printf("\n8. 此數字是否為正整數:");
    if (x >0 )
        printf("是 , 正整數");
    else
        printf("不是 , 正整數");

    return 0;
}       


12
請輸入一數字( 1~200):
你輸入的 N=0.000000

1. 此數字是:正數
2. 此數字是:偶數
3. 此數字是否為3的倍數:3的倍數
4. 此數字是否為200的因數:不是200的因數
5. 此數字是否介於100到200之間:不是 , 大於200
6. 此數字是否為3位數:不是3位數
7. 此數字是否為2與3的公倍數:是2與3的公倍數
8. 此數字是否為正整數:是 , 正整數






C語言(online c) 寫簡單的 程式 ( 輸入一個數值判斷數值為偶數或奇數 )

C語言(online c) 寫簡單的 程式 ( 輸入一個數值判斷數值為偶數或奇數 )

#include<stdio.h>
#include<math.h>
int main()
{
    int x, f, a, b;
    printf("請輸入一數字( 1~200):\n");
    scanf("%d", &x);
    printf("你輸入的 N=%d\n", x);
    printf("\n1. 此數字是:");

    if (x % 2 == 0)
        printf("偶數");
    else
        printf("奇數");
 
    return 0;     
}     


C語言(online c) 寫簡單的 程式 ( 輸入一個數值判斷數值為正數或負數 )

C語言(online c) 寫簡單的 程式
( 輸入一個數值判斷數值為正數或負數 ) 

源自於 https://www.dropbox.com/s/jv3sya3cwl493kl/Q1.c?dl=0

#include<stdio.h>
int main()
{
    int x, f, a, b;
    printf("請輸入一數字( 1~200):\n");
    scanf("%d", &x);
    printf("你輸入的 N=%d\n", x);
    printf("\n1. 此數字是:");

    if (x == 0)                 /* x 要小寫 */
        {
            printf("零");
        }
        else
        {
          if (x > 0)
                printf("正數");
          else
                printf("負數");
        }
    return 0;       
}       




2019年6月23日 星期日

Node RED Programming Guide

Programming the IoT

Node-Red Tutorials

Node-Red Tutorials
源自於 http://www.steves-internet-guide.com/node-red-overview/


Node-Red and MQTT

Node Red Demo Videos

Videos General

Node-Red Nodes

Useful Tools

Summary Of Terms

Note: These are the terms and meanings used in this tutorial.
Workspace – Contains all of your flows
Flow – A collection of nodes and wires
Flow Canvas – The Flow Edit screen
Node – A packaged JavaScript function with data.
Wire– A connection between nodes.

Resources
Related Tutorials

How to Copy and Export Nodes and Flows in Node-Red


How to Copy and Export Nodes and Flows in Node-Red


There a several ways that you can copy nodes and flows between flows in the node-red Workspace.
They are:
  • Select, Copy and Paste
  • Export and Import Clipboard
  • Save To and Retrieve from the Local Library
Copy and Paste
This works just like copying text in a word processor. You simply select the nodes you want using the CTRL key to select individual nodes together into a group or CTRL+A to select all nodes in the workspace.
Then use CTRL+C to Copy.
You then move to the place on the workspace or open the workspace where you want to copy the nodes to and use CTRL+V to paste the nodes/flow into the workspace.
Note: This only works for flows in the same workspace.

Using Export and Import and The Clipboard

This method can be used for exchanging flows between systems as well as on the same system.
To do this you need to highlight each node in the flow and then click onMenu>export>clipboard.
Note: Use CTRL+A to select all nodes in the workspace.

The contents of the export file will be displayed click on export to clipboard.

You then need to open a file editor and paste the contents into the file using CTRL+V.
Give the file a name and save it.

Importing A Flow

You will need to open the flow in a text editor, and then copy its contents usingCRTL+C.
You then go to Menu>import>clipboard and paste the file into the window and click the import button to complete the import.

Import Problems

If you find that the import button doesn’t change colour and a red line appears around the text box it is probably because what you are trying to import isn’t valid JSON.
You can test it by pasting it into this online JSON checker
A confusing issue I found is that my export file verified OK using the JSON checker but failed when doing an import at a remote location.
The problem was due to smart quotes in the export file.
I pasted the file into this online smart quotes removal tool to remove them, and then sent it, and it worked OK.
智能引號清除工具
smart quotes removal tool


Using The Library

If you want to save a flow or function and reuse it in another flow  then you can save it to the local library.
To save a flow to the library highlight all nodes in the flow by using CTRL+A then use the main menu (top right) and select Export>Library.

You will need to give the flow a name and optionally you can create a folder for the flow.
For example you could store flows in the flows folder and functions in the functions folder.
All flows are stored in the lib folder under the users .node-red folder.
To save a function to the library double click on the function to edit it and click on the bookmark icon next to the function name.
A drop down menu appears to either import or save the function to the library.

You need to give the file a name and optionally a folder to store it in.

Note: The function itself should have a name as you will need this when importing the function.

If you don’t give the function a name it appears as an unnamed function when importing.

Using Library Functions and Flows

To use a library flow use the Import>Library option and select the flow, and it appears in the flow canvas
To use a library function drag a function node into the flow canvas then open it for editing.
Click on the bookmark icon next to the function name and select open library from the drop down menu.
Open folder containing functions and the functions appear by name. Select the function and click load, to load the library code into the function.

原始檔案

[{"id":"6aee26ac.b75e48","type":"inject","z":"afe7af4b.c2261","name":"","topic":"test","payload":"test message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1700,"wires":[["b73ed76d.7bd3b8"]]},{"id":"b73ed76d.7bd3b8","type":"function","z":"afe7af4b.c2261","name":"message array","func":"var m_out=[]; //rray for message objects\nvar message=msg.payload;\nfor (i=0;i<3;i++){\n    \n    message=message+i; //add count to message\n    var newmsg={payload:message,topic:msg.topic}\n    m_out.push(newmsg);\n}\nreturn[m_out];\n","outputs":1,"noerr":0,"x":340,"y":1700,"wires":[["549f2f6c.0cc2a"]]},{"id":"549f2f6c.0cc2a","type":"debug","z":"afe7af4b.c2261","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":1700,"wires":[]}]

I pasted the file into this online smart quotes removal tool to remove them, and then sent it, and it worked OK.

[{"id":"6aee26ac.b75e48","type":"inject","z":"afe7af4b.c2261","name":"","topic":"test","payload":"test message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1700,"wires":[["b73ed76d.7bd3b8"]]},{"id":"b73ed76d.7bd3b8","type":"function","z":"afe7af4b.c2261","name":"message array","func":"var m_out=[]; //rray for message objects\nvar message=msg.payload;\nfor (i=0;i<3;i++){\n    \n    message=message+i; //add count to message\n    var newmsg={payload:message,topic:msg.topic}\n    m_out.push(newmsg);\n}\nreturn[m_out];\n","outputs":1,"noerr":0,"x":340,"y":1700,"wires":[["549f2f6c.0cc2a"]]},{"id":"549f2f6c.0cc2a","type":"debug","z":"afe7af4b.c2261","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":1700,"wires":[]}]

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...