1 / 11

אתחול מערך

אתחול מערך. void main() { int i; int ar1[5]={7,3,4,5,2}; int ar2[]={9,3,3,4,6}; /*the size is 5*/ int ar3[5]={3,2}; /*the other nums are 0*/ int ar4[3]; /*garbage*/ int ar5[100]; /*garbage*/ ar4[0]=12; ar4[1]=2; ar4[2]=9; for (i=0;i<100;i++) ar5[i]=i+5; }.

eyal
Download Presentation

אתחול מערך

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. אתחול מערך void main() { int i; int ar1[5]={7,3,4,5,2}; int ar2[]={9,3,3,4,6};/*the size is 5*/ int ar3[5]={3,2};/*the other nums are 0*/ int ar4[3];/*garbage*/ int ar5[100];/*garbage*/ ar4[0]=12; ar4[1]=2; ar4[2]=9; for (i=0;i<100;i++) ar5[i]=i+5; }

  2. 0 1 2 3 4 5 void main() { int nums[6]; int a=8,b=3; nums[0]=5; nums[2]=a; nums[5]=a+b; nums[b]=nums[2]; nums[4]=nums[a-b]; nums[a+b]=9; } 5 8 8 11 11 ?

  3. Selection sort 5 1 2 7 3 3 5 5 1 1 9 7 2 2 7 7 9

  4. #include <stdio.h> void main() { int i, j, min, temp, nums[10]; for (i=0; i<10; i++){ /*input*/ printf ("enter number\n"); scanf ("%d",&nums[i]); } for (i=0; i<9; i++){ /*main loop*/ min = i; for (j=i+1; j<10; j++) /*finding minimum index*/ if (nums[j]<nums[min]) min = j; temp = nums[i]; /*swaping*/ nums[i] = nums[min]; nums[min] = temp; } for (i=0; i<10; i++) /*printing*/ printf ("%d\n",nums[i]); }

  5. Insertion sort 7 3 5 1 9 2

  6. #include <stdio.h> void main() { int i, j, temp, nums[10]; for (i=0; i<10; i++){ /*input*/ printf ("enter number\n"); scanf ("%d",&nums[i]); } for (i=0; i<10; i++){ /*main loop*/ /*finding location of nums[j]*/ for (j=i; j>0 && nums[j]<nums[j-1]; j--){ temp = nums[j]; /*swaping*/ nums[j] = nums[j-1]; nums[j-1] = temp; } } for (i=0; i<10; i++) /*printing*/ printf ("%d\n",nums[i]); }

  7. מערך דו מימדי #include <stdio.h> void main() { int i,j; int ar1[3][2]={{1,2},{9,4},{14,6}}; int ar2[][2]={{5,6},{7,4},{14,3}}; int ar3[4][3]={{2},{1,1,1},{1,4,6}}; int ar4[3][5]; for (i=0;i<3;i++) for (j=0;j<5;j++) scanf("%d",&ar4[i][j]); }

  8. שולה המוקשים: הגדרות משתנים #include <stdlib.h> #include <time.h> #include <stdio.h> #define ROWS 10 #define COLS 10 void main() { int i,j,number,mines=0,i1,j1, revealed=0; int board[ROWS][COLS]; int playerBoard[ROWS][COLS]; srand((unsignedint)time(NULL));

  9. שולה המוקשים: אתחול הלוח for (i=0;i<ROWS;i++){ for (j=0;j<COLS;j++){ number=(int)((double)rand()/(RAND_MAX+1)*10); if (number<1){ board[i][j]=1; mines++; } else board[i][j]=0; playerBoard[i][j]=9; } }

  10. while (revealed <ROWS*COLS - mines){ for (i=0;i<ROWS;i++){ for (j=0;j<COLS;j++) printf ("%d",playerBoard[i][j]); printf("\n"); } printf ("enter row and column number\n"); scanf("%d%d",&i1,&j1); if (board[i1][j1]==1) break; if (playerBoard[i1][j1]!=9) continue; revealed++; playerBoard[i1][j1]=0; for (i=max(0,i1-1); i<=min(i1+1,ROWS-1); i++) for (j=max(0,j1-1);j<=min(COLS-1,j1+1); j++) if (board[i][j]) playerBoard[i1][j1]++; }

  11. שולה המוקשים: תוצאת המשחק if (revealed<ROWS*COLS - mines) printf("KABOOM!!!\n"); else printf("You won!!!\n"); }

More Related