SlideShare una empresa de Scribd logo
1 de 85
Descargar para leer sin conexión
Team Emertxe
Advanced Pointers,
Arrays and Functions
Assignment 4
Assignment 4
Assignment 4
WAP to generate a n*n magic square.
Assignment 4
WAP to generate a n*n magic square.
Input:
Assignment 4
WAP to generate a n*n magic square.
Input: Read an integer ‘n’.
Assignment 4
WAP to generate a n*n magic square.
Input: Read an integer ‘n’.
Output:
Assignment 4
WAP to generate a n*n magic square.
Input: Read an integer ‘n’.
Output: Print magic square based on ‘n’ no.of rows and columns.
Assignment 4
What is magic square?
Assignment 4
What is magic square?
 It is an arrangement of numbers in a square grid.
Assignment 4
What is magic square?
 It is an arrangement of numbers in a square grid.
 Sum of each elements in row wise, column wise and diagonal
wise should be equal.
Assignment 4
Example :-
8 1 6
3 5 7
4 9 2
8 + 3 + 4 = 15
Assignment 4
Example :-
8 1 6
3 5 7
4 9 2
1 + 5 + 9 = 15
Assignment 4
Example :-
8 1 6
3 5 7
4 9 2
6 + 7 + 2 = 15
Assignment 4
Example :-
8 1 6
3 5 7
4 9 2
8 + 1 + 6 = 15
Assignment 4
Example :-
8 1 6
3 5 7
4 9 2
3 + 5 + 7 = 15
Assignment 4
Example :-
8 1 6
3 5 7
4 9 2
4 + 9 + 2 = 15
Assignment 4
Example :-
8 1 6
3 5 7
4 9 2
4 + 5 + 6 = 15
Assignment 4
Example :-
8 1 6
3 5 7
4 9 2
8 + 5 + 2 = 15
Assignment 4
Example :-
 Read ‘n’ from the user.
Assignment 4
Example :-
 Read ‘n’ from the user.
Lets say, ‘n’ = 3
Assignment 4
Example :-
 Read ‘n’ from the user.
Lets say, ‘n’ = 3
 Check ‘n’ is positive odd or not.
Assignment 4
Example :-
 Read ‘n’ from the user.
Lets say, ‘n’ = 3
 Check ‘n’ is positive odd or not.
 Allocate memory dynamically for ‘n’ x ‘n’ matrix.
Assignment 4
Example :-
Step1 : Start storing number from 0th row middle column.
Assignment 4
Example :-
Step1 : Start storing number from 0th row middle column.
1
0 1 2
0
1
2
row
col
Assignment 4
Example :-
Step2 : Move one row up and one column towards right.
n
0 1 2
0
1
2
row
col
Assignment 4
Example :-
Step2 : Move one row up and one column towards right.
n+1
n
0 1 2
0
1
2
row
col
Assignment 4
Example :-
Step2 : Move one row up and one column towards right.
2.1 : If you are in topmost row, jump to bottom.
n
0 1 2
0
1
2
row
col
Assignment 4
Example :-
Step2 : Move one row up and one column towards right.
2.1 : If you are in topmost row, jump to bottom.
n
n+1
0 1 2
0
1
2
row
col
Assignment 4
Example :-
Step2 : Move one row up and one column towards right
2.1 : If you are in topmost row, jump to bottom
2.2 : If you are in rightmost column, jump to 0th column
n
0 1 2
0
1
2
row
col
Assignment 4
Example :-
Step2 : Move one row up and one column towards right
2.1 : If you are in topmost row, jump to bottom
2.2 : If you are in rightmost column, jump to 0th column
n+1
n
0 1 2
0
1
2
row
col
Assignment 4
Example :-
Step2 : Move one row up and one column towards right.
1
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
1 n
n+1
Step 2.1
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
1
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
1
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
1
2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
1
2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here exceeds the limit so move to 0th column in the same
row
1
2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here exceeds the limit so move to 0th column in the same
row
1
2
n+1
n
Step 2.2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here exceeds the limit so move to 0th column in the same
row
1
2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here exceeds the limit so move to 0th column in the same
row
1
3
2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
1
3
2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here already value is filled. If element present move to
step3
1
3
2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
Step3 : If element already present , move one row down and insert.
Then repeat step 2
m
n
0 1 2
0
1
2
row
col
Assignment 4
Example :-
Step3 : If element already present , move one row down and insert.
Then repeat step 2
m
n
n+1
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2, move one row up and one column towards right.
1
3
2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here already value is filled. If element present move to
step3.
1
3
2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here already value is filled. If element present move to
step3.
1
3
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step2 , move one row up and one column towards right.
Here already value is filled. If element present move to
step3.
1
3
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 3 ,move one row down and insert. Then repeat step2.
1
3
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 3 ,move one row down and insert. Then repeat step2.
1
3
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 3 ,move one row down and insert. Then repeat step2.
1
3 5
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 3 ,move one row down and insert. Then repeat step2.
1
3 5
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
1
3 5
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
1
3 5
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
1 6
3 5
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
1 6
3 5
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
1 6
3 5
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
1 6
3 5
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
1 6
3 5
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here already value is filled. If element present move to
step3.
1 6
3 5
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here already value is filled. If element present move to
step3.
1 6
3 5 7
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here already value is filled. If element present move to
step3.
1 6
3 5 7
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here exceeds the limit so move to 0th column in the same
row
1 6
3 5 7
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here exceeds the limit so move to 0th column in the same
row
1 6
3 5 7
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
1 6
3 5 7
4 2
0 1 2
0
1
2
row
col
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
8 1 6
3 5 7
4 2
0 1 2
col
0
1
2
row
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
8 1 6
3 5 7
4 2
0 1 2
col
0
1
2
row
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
8 1 6
3 5 7
4 2
0 1 2
col
0
1
2
row
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
8 1 6
3 5 7
4 2
0 1 2
col
0
1
2
row
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
8 1 6
3 5 7
4 2
0 1 2
col
0
1
2
row
Assignment 4
Example :-
 Follow step 2 , move one row up and one column towards right.
Here if move up then it exceeds the limit. So move to last
row and 1 column towards right
8 1 6
3 5 7
4 9 2
0 1 2
col
0
1
2
row
Assignment 4
Example :-
Step4 : Print the magic square array.
8 1 6
3 5 7
4 9 2
0 1 2
col
0
1
2
row
Sample execution:-
Assignment 4
Sample execution:-
Assignment 4
Sample execution:-
Assignment 4
Assignment 4
Pre-requisites:-
Assignment 4
Pre-requisites:-
 Loops
Assignment 4
Pre-requisites:-
 Loops
 Arrays
Assignment 4
Pre-requisites:-
 Loops
 Arrays
 Pointers
Assignment 4
Pre-requisites:-
 Loops
 Arrays
 Pointers
 Functions
Assignment 4
Pre-requisites:-
 Loops
 Arrays
 Pointers
 Functions
 Dynamic memory allocation
Assignment 4
Pre-requisites:-
 Loops
 Arrays
 Pointers
 Functions
 Dynamic memory allocation
Objective:-
Assignment 4
Pre-requisites:-
 Loops
 Arrays
 Pointers
 Functions
 Dynamic memory allocation
Objective:-
 To understand the concept of Pointers and 2D array.
Team Emertxe
Thank you

Más contenido relacionado

Más de Emertxe Information Technologies Pvt Ltd

Más de Emertxe Information Technologies Pvt Ltd (20)

premium post (1).pdf
premium post (1).pdfpremium post (1).pdf
premium post (1).pdf
 
Career Transition (1).pdf
Career Transition (1).pdfCareer Transition (1).pdf
Career Transition (1).pdf
 
10_isxdigit.pdf
10_isxdigit.pdf10_isxdigit.pdf
10_isxdigit.pdf
 
01_student_record.pdf
01_student_record.pdf01_student_record.pdf
01_student_record.pdf
 
02_swap.pdf
02_swap.pdf02_swap.pdf
02_swap.pdf
 
01_sizeof.pdf
01_sizeof.pdf01_sizeof.pdf
01_sizeof.pdf
 
07_product_matrix.pdf
07_product_matrix.pdf07_product_matrix.pdf
07_product_matrix.pdf
 
06_sort_names.pdf
06_sort_names.pdf06_sort_names.pdf
06_sort_names.pdf
 
05_fragments.pdf
05_fragments.pdf05_fragments.pdf
05_fragments.pdf
 
03_endianess.pdf
03_endianess.pdf03_endianess.pdf
03_endianess.pdf
 
02_variance.pdf
02_variance.pdf02_variance.pdf
02_variance.pdf
 
01_memory_manager.pdf
01_memory_manager.pdf01_memory_manager.pdf
01_memory_manager.pdf
 
09_nrps.pdf
09_nrps.pdf09_nrps.pdf
09_nrps.pdf
 
11_pangram.pdf
11_pangram.pdf11_pangram.pdf
11_pangram.pdf
 
10_combinations.pdf
10_combinations.pdf10_combinations.pdf
10_combinations.pdf
 
08_squeeze.pdf
08_squeeze.pdf08_squeeze.pdf
08_squeeze.pdf
 
07_strtok.pdf
07_strtok.pdf07_strtok.pdf
07_strtok.pdf
 
06_reverserec.pdf
06_reverserec.pdf06_reverserec.pdf
06_reverserec.pdf
 
05_reverseiter.pdf
05_reverseiter.pdf05_reverseiter.pdf
05_reverseiter.pdf
 
04_itoa.pdf
04_itoa.pdf04_itoa.pdf
04_itoa.pdf
 

Último

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Último (20)

SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

04_magic_square.pdf