אתחול מערך 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*/

Slides:



Advertisements
Similar presentations
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Advertisements

Recursion Prog #include <stdio.h> #include<conio.h> main()
Programming In C++ Spring Semester 2013 Practice 2 Programming In C++, Practice By Umer Rana.
DS:Lab-1 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
What is shape function ? shape function is a function that will give the displacements inside an element if its displacement at all the node locations.
Sort the given string, without using string handling functions.
C Intro.
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
PSEUDOCODE & FLOW CHART
For loops For loops are controlled by a counter variable. for( c =init_value;c
Nested Loops. Problem Print The only printfs you can use are: –printf(“*”); –printf(“\n”); *****
C workshop #3 flow control / strings.
1 CSE1301 Computer Programming Lecture 10: Iteration (Part 1)
CMPUT 101 Lab #6 October 29, :00 – 17:00. Array in C/C++ Array is a structure type variable. One dimension of array int: int num[3]; There are.
פוינטרים ומבנים. אתחול והדפסת מערך #include int * readArray(int size){ int *a, i; a= (int *) malloc (size* sizeof(int)); if (!a) return NULL; for (i=0;i
GE 211 Programming in C Matrix Dr. Ahmed Telba. Example Write function to take coefficients of quadratic equation a, b and c as input parameter and return.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
Programming Arrays. Example 1 Write a program that reads 3 numbers from the user and print them in reverse order. How many variables do we need to store.
SNPL1 GAUSS ELIMINATION & BACK SUBSTITUTION GAUSS ELIMINATION & BACK SUBSTITUTION Dayun Yu Seungmuk Ji.
CS1010E Programming Methodology Tutorial 3 Control Structures and Data Files C14,A15,D11,C08,C11,A02.
Return function Random function Recursion function Function in C 1.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
Repetitive Structures BBS514 Structured Programming (Yapısal Programlama)1.
Artificial Intelligence and Robotics By Keith Bright & John DeBovis.
1 C Programming Week 2 Variables, flow control and the Debugger.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
Functions. Why use functions? They can break your problem down into smaller sub-tasks (modularity).  easier to solve complex problems They make a program.
Computer Programming for Engineers
BY ILTAF MEHDI (MCS, MCSE, CCNA)1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI (MCS, MCSE, CCNA)2 Chapter No: 04 “Loops”
Review (before the 1 st test): while (conditions) { statements; } while loop: if/else if/else statements: if (conditions) { statements; } else if (different.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
CS 161 Introduction to Programming and Problem Solving Chapter 17 Nested Loops Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
Arrays and Matrices. One-Dimensional Arrays An array is an indexed data structure All variables stored in an array are of the same data type An element.
Engineering Problem#1 Engr201 Computer Programming for Engineers Faculty of Engineering Chiang Mai University 1.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
EXAMPLE. Dr. Soha S. Zaghloul2 Write a complete program that searches for all the elements that are multiple of 7 in array X of type int and size 100.
 Last Lecture Reminder  Array Sorts  Exam Questions Examples  Open Questions ◦ Search Engines ◦ Operating Systems ◦ Multiple Files in Projects  Additional.
Computer C programming Chapter 3. CHAPTER 3 Program Looping –The for Statement –Nested for Loops –for Loop Variants –The while Statement –The do Statement.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
1 2-d Arrays. 2 Two Dimensional Arrays We have seen that an array variable can store a list of values Many applications require us to store a table of.
Arrays float Scores[9]; ? index: element // one dimensional array 2.
Consultation Hours. Mubashir: – Tuesday from 12:30 to 1:30 with ease of Students. Zohaib – Wednesday b/w 9:30 -10:30 Location: TA Room (next to HOD Office)
 Real numbers representation - Floating Point Notation  First C Program  Variables Declaration  Data Types in C ◦ char, short, int, long, float, double,
The Repetition control structure using while loop.
מערכים (arrays) 02 אוקטובר אוקטובר אוקטובר 1602 אוקטובר אוקטובר אוקטובר 1602 אוקטובר אוקטובר אוקטובר 16 Department.
Introduction to Programming
Chapter 7 - A closer look at Arrays
Two Dimensional Array Mr. Jacobs.
Programming Fundamental
MULTI-DIMENSIONAL ARRAY
Array 9/8/2018.
INC 161 , CPE 100 Computer Programming
Looping.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CS1100 Computational Engineering
Nested Loop Review and Two-Dimensional Arrays
Lec 7.
מ- C++ ל- C קרן כליף.
מבני נתונים ויעילות אלגוריתמים
כתיבת מאקרו הפקודה assert מצביעים לפונקציות
Chapter 8 The Loops By: Mr. Baha Hanene.
Intro to Sorting Sorting
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Incremental operators
Relational, Logical, and Equality Operators
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays I Handling lists of data.
ECE 103 Engineering Programming Chapter 19 Nested Loops
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Presentation transcript:

אתחול מערך 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; }

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; } ?

Selection sort

#include 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]); }

Insertion sort

#include 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]); }

מערך דו מימדי #include 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]); }

שולה המוקשים: הגדרות משתנים #include #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((unsigned int)time(NULL));

שולה המוקשים: אתחול הלוח 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; }

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]++; }

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