SlideShare a Scribd company logo
1 of 2
Download to read offline
Practice problems on functions
1. Write a Swift program to compute the sum of the two integers. If the values are equal return the
triple their sum.
2. Write a Swift program to compute and return the absolute difference of n and 51, if n is over 51
return double the absolute difference
3. Write a Swift program that accept two integer values and return true if one of them is 20 or if
their sum is 20.
4. Write a Swift program to accept two integer values and return true if one is negative and one is
positive. Return true only if both are negative.
5. Write a Swift program to add "Is" to the front of a given string. However, if the string already
begins with "Is", return the given string.
6. Write a Swift program to remove a character at specified index of a given non-empty string. The
value of the specified index will be in the range 0..str.length()-1 inclusive
7. Write a Swift program to change the first and last character of a given string.
8. Write a Swift program to add the last character (given string) at the front and back of a given
string. The length of the given string must be 1 or more.
9. Write a Swift program to check if a given non-negative number is a multiple of 3 or a multiple of 5.
10. Write a Swift program to take the first two characters from a given string and create a new string
with the two characters added at both the front and back.
11. Write a Swift program to test a given string whether it starts with "Is". Return true or false.
12. Write a Swift program that return true if either of two given integers is in the range 10..30
inclusive.
13. Write a Swift program to check if a given string begins with "fix", except the 'f' can be any
character or number.
14. Write a Swift program to find the largest number among three given integers.
15. Write a Swift program that accept two integer values and to test which value is nearest to the
value 10, or return 0 if both integers have same distance from 10.
16. Write a Swift program that accept two integer values and test if they are both in the range 20..30
inclusive, or they are both in the range 30..40 inclusive.
17. Write a Swift program that accept two positive integer values and test whether the larger value
is in the range 20..30 inclusive, or return 0 if neither is in that range.
18. Write a Swift program to test whether the last digit of the two given non-negative integer values
are same or not.
19. Write a Swift program to convert the last three characters in upper case. If the string has less
than 3 chars, lowercase whatever is there.
20. Write a Swift program to check if the first instance of "a" in a given string is immediately
followed by another "a".
21. Write a Swift program to create a string made of every other char starting with the first from a
given string. So "Python" will return "Pto"
22. Write a Swift program to count the number of 7's in a given array of integers.
23. Write a Swift program to check if one of the first 4 elements in a given array of integers is a 7.
The length of the array may be less than 4.
24. Write a Swift program to test if the sequence of numbers 0, 1, 2 appears in a given array of
integers somewhere.
25. Write a Swift program to create a new string where all the character "a" have been removed
except the first and last positions.
26. Write a Swift program to create a string taking characters at indexes 0, 2, 4, 6, 8, .. from a given
string
27. Write a Swift program to count the number of times that two 7's are next to each other in a
given array of integers.
28. Write a Swift program to test whether a value presents sequentially three times in an array of
integers or not.

More Related Content

What's hot

Applications of algebra and calculus
Applications of algebra and calculusApplications of algebra and calculus
Applications of algebra and calculusabdulqadir ezzy
 
03 mathematical anaylsis
03 mathematical anaylsis03 mathematical anaylsis
03 mathematical anaylsisHira Gul
 
P3 แบบทดสอบคิดคำนวณคล่อง
P3 แบบทดสอบคิดคำนวณคล่องP3 แบบทดสอบคิดคำนวณคล่อง
P3 แบบทดสอบคิดคำนวณคล่องKhunnawang Khunnawang
 
Quick sort algorithn
Quick sort algorithnQuick sort algorithn
Quick sort algorithnKumar
 
BASICS OF MATRICES WITH APPLICATION IN ENGINEERING
BASICS OF MATRICES WITH APPLICATION IN ENGINEERINGBASICS OF MATRICES WITH APPLICATION IN ENGINEERING
BASICS OF MATRICES WITH APPLICATION IN ENGINEERINGRoshan Bhagat
 
เรื่อง การใช้ความรู้เกี่ยวกับ ห
เรื่อง  การใช้ความรู้เกี่ยวกับ  หเรื่อง  การใช้ความรู้เกี่ยวกับ  ห
เรื่อง การใช้ความรู้เกี่ยวกับ หนวพร ฆ้องเดช
 
รวมข้อสอบ Pat1 stat-52-59+key
รวมข้อสอบ Pat1 stat-52-59+keyรวมข้อสอบ Pat1 stat-52-59+key
รวมข้อสอบ Pat1 stat-52-59+keySutthi Kunwatananon
 
การคูณและการหาร
การคูณและการหารการคูณและการหาร
การคูณและการหารtheandewxx
 
บทที่ 1 อัตราส่วนตรีโกณมิติ ม.ต้น
บทที่ 1 อัตราส่วนตรีโกณมิติ ม.ต้นบทที่ 1 อัตราส่วนตรีโกณมิติ ม.ต้น
บทที่ 1 อัตราส่วนตรีโกณมิติ ม.ต้นsawed kodnara
 
เวทคณิตน่ารู้(The Vedic mathematics Ver.Thai)
เวทคณิตน่ารู้(The Vedic mathematics Ver.Thai)เวทคณิตน่ารู้(The Vedic mathematics Ver.Thai)
เวทคณิตน่ารู้(The Vedic mathematics Ver.Thai)Supachok Pongkathin
 
E0b89ae0b897e0b897e0b8b5e0b988 3-e0b980e0b8a7e0b881e0b980e0b895e0b8ade0b8a3e0...
E0b89ae0b897e0b897e0b8b5e0b988 3-e0b980e0b8a7e0b881e0b980e0b895e0b8ade0b8a3e0...E0b89ae0b897e0b897e0b8b5e0b988 3-e0b980e0b8a7e0b881e0b980e0b895e0b8ade0b8a3e0...
E0b89ae0b897e0b897e0b8b5e0b988 3-e0b980e0b8a7e0b881e0b980e0b895e0b8ade0b8a3e0...Akimoto Akira
 
Permutation and Combination Maths
Permutation and Combination MathsPermutation and Combination Maths
Permutation and Combination MathsVardhan Jain
 
ปริภูมิเวกเตอร์ในR ตอนที่ 1
ปริภูมิเวกเตอร์ในR ตอนที่ 1ปริภูมิเวกเตอร์ในR ตอนที่ 1
ปริภูมิเวกเตอร์ในR ตอนที่ 1kroojaja
 
Divide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic ProgrammingDivide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic ProgrammingGuillaume Guérard
 
Rabin karp string matching algorithm
Rabin karp string matching algorithmRabin karp string matching algorithm
Rabin karp string matching algorithmGajanand Sharma
 

What's hot (20)

Linear Algebra
Linear AlgebraLinear Algebra
Linear Algebra
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptx
 
Applications of algebra and calculus
Applications of algebra and calculusApplications of algebra and calculus
Applications of algebra and calculus
 
03 mathematical anaylsis
03 mathematical anaylsis03 mathematical anaylsis
03 mathematical anaylsis
 
แบบทดสอบ เรื่อง จำนวนจริง
แบบทดสอบ เรื่อง จำนวนจริงแบบทดสอบ เรื่อง จำนวนจริง
แบบทดสอบ เรื่อง จำนวนจริง
 
P3 แบบทดสอบคิดคำนวณคล่อง
P3 แบบทดสอบคิดคำนวณคล่องP3 แบบทดสอบคิดคำนวณคล่อง
P3 แบบทดสอบคิดคำนวณคล่อง
 
Quick sort algorithn
Quick sort algorithnQuick sort algorithn
Quick sort algorithn
 
BASICS OF MATRICES WITH APPLICATION IN ENGINEERING
BASICS OF MATRICES WITH APPLICATION IN ENGINEERINGBASICS OF MATRICES WITH APPLICATION IN ENGINEERING
BASICS OF MATRICES WITH APPLICATION IN ENGINEERING
 
Hash tables
Hash tablesHash tables
Hash tables
 
เรื่อง การใช้ความรู้เกี่ยวกับ ห
เรื่อง  การใช้ความรู้เกี่ยวกับ  หเรื่อง  การใช้ความรู้เกี่ยวกับ  ห
เรื่อง การใช้ความรู้เกี่ยวกับ ห
 
รวมข้อสอบ Pat1 stat-52-59+key
รวมข้อสอบ Pat1 stat-52-59+keyรวมข้อสอบ Pat1 stat-52-59+key
รวมข้อสอบ Pat1 stat-52-59+key
 
การคูณและการหาร
การคูณและการหารการคูณและการหาร
การคูณและการหาร
 
บทที่ 1 อัตราส่วนตรีโกณมิติ ม.ต้น
บทที่ 1 อัตราส่วนตรีโกณมิติ ม.ต้นบทที่ 1 อัตราส่วนตรีโกณมิติ ม.ต้น
บทที่ 1 อัตราส่วนตรีโกณมิติ ม.ต้น
 
เวทคณิตน่ารู้(The Vedic mathematics Ver.Thai)
เวทคณิตน่ารู้(The Vedic mathematics Ver.Thai)เวทคณิตน่ารู้(The Vedic mathematics Ver.Thai)
เวทคณิตน่ารู้(The Vedic mathematics Ver.Thai)
 
E0b89ae0b897e0b897e0b8b5e0b988 3-e0b980e0b8a7e0b881e0b980e0b895e0b8ade0b8a3e0...
E0b89ae0b897e0b897e0b8b5e0b988 3-e0b980e0b8a7e0b881e0b980e0b895e0b8ade0b8a3e0...E0b89ae0b897e0b897e0b8b5e0b988 3-e0b980e0b8a7e0b881e0b980e0b895e0b8ade0b8a3e0...
E0b89ae0b897e0b897e0b8b5e0b988 3-e0b980e0b8a7e0b881e0b980e0b895e0b8ade0b8a3e0...
 
Permutation and Combination Maths
Permutation and Combination MathsPermutation and Combination Maths
Permutation and Combination Maths
 
ปริภูมิเวกเตอร์ในR ตอนที่ 1
ปริภูมิเวกเตอร์ในR ตอนที่ 1ปริภูมิเวกเตอร์ในR ตอนที่ 1
ปริภูมิเวกเตอร์ในR ตอนที่ 1
 
queue.pptx
queue.pptxqueue.pptx
queue.pptx
 
Divide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic ProgrammingDivide&Conquer & Dynamic Programming
Divide&Conquer & Dynamic Programming
 
Rabin karp string matching algorithm
Rabin karp string matching algorithmRabin karp string matching algorithm
Rabin karp string matching algorithm
 

Similar to practice problems on functions IN SWIFT

Similar to practice problems on functions IN SWIFT (20)

practice problems on array IN SWIFT
practice problems on array IN SWIFTpractice problems on array IN SWIFT
practice problems on array IN SWIFT
 
practice problems on array IN SWIFT
practice problems on array  IN SWIFTpractice problems on array  IN SWIFT
practice problems on array IN SWIFT
 
practice problems on array IN SWIFT
practice problems on array IN SWIFTpractice problems on array IN SWIFT
practice problems on array IN SWIFT
 
Tutorial 04 (revised) (1)
Tutorial 04 (revised) (1)Tutorial 04 (revised) (1)
Tutorial 04 (revised) (1)
 
Java programlist (1)
Java programlist (1)Java programlist (1)
Java programlist (1)
 
Python assignment 4
Python assignment 4Python assignment 4
Python assignment 4
 
Programming qns
Programming qnsProgramming qns
Programming qns
 
If switch structure
If switch structureIf switch structure
If switch structure
 
A10
A10A10
A10
 
PYTHON PROGRAMS
PYTHON PROGRAMSPYTHON PROGRAMS
PYTHON PROGRAMS
 
Master Python in 15 Days.pdf
Master Python in 15 Days.pdfMaster Python in 15 Days.pdf
Master Python in 15 Days.pdf
 
C code examples
C code examplesC code examples
C code examples
 
C programming part4
C programming part4C programming part4
C programming part4
 
C programming part4
C programming part4C programming part4
C programming part4
 
Practical java
Practical javaPractical java
Practical java
 
1
11
1
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL
 
Java Programming - Conditional Statements (Switch).pdf
Java Programming - Conditional Statements (Switch).pdfJava Programming - Conditional Statements (Switch).pdf
Java Programming - Conditional Statements (Switch).pdf
 
C_Lab Manual_Part A.docx
C_Lab Manual_Part A.docxC_Lab Manual_Part A.docx
C_Lab Manual_Part A.docx
 

More from LOVELY PROFESSIONAL UNIVERSITY (16)

Enumerations, structure and class IN SWIFT
Enumerations, structure and class IN SWIFTEnumerations, structure and class IN SWIFT
Enumerations, structure and class IN SWIFT
 
Dictionaries IN SWIFT
Dictionaries IN SWIFTDictionaries IN SWIFT
Dictionaries IN SWIFT
 
Control structures IN SWIFT
Control structures IN SWIFTControl structures IN SWIFT
Control structures IN SWIFT
 
Arrays and its properties IN SWIFT
Arrays and its properties IN SWIFTArrays and its properties IN SWIFT
Arrays and its properties IN SWIFT
 
Array and its functionsI SWIFT
Array and its functionsI SWIFTArray and its functionsI SWIFT
Array and its functionsI SWIFT
 
10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING
 
Variables and data types IN SWIFT
 Variables and data types IN SWIFT Variables and data types IN SWIFT
Variables and data types IN SWIFT
 
Soft skills. pptx
Soft skills. pptxSoft skills. pptx
Soft skills. pptx
 
JAVA
JAVAJAVA
JAVA
 
Unit 5
Unit 5Unit 5
Unit 5
 
Unit 4
Unit 4Unit 4
Unit 4
 
Unit 3
Unit 3Unit 3
Unit 3
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Unit 1
Unit 1Unit 1
Unit 1
 
COMPLETE CORE JAVA
COMPLETE CORE JAVACOMPLETE CORE JAVA
COMPLETE CORE JAVA
 
Data wrangling IN R LANGUAGE
Data wrangling IN R LANGUAGEData wrangling IN R LANGUAGE
Data wrangling IN R LANGUAGE
 

Recently uploaded

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
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.pdfAdmir Softic
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
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.pptxDenish Jangid
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 

Recently uploaded (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
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
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
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
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 

practice problems on functions IN SWIFT

  • 1. Practice problems on functions 1. Write a Swift program to compute the sum of the two integers. If the values are equal return the triple their sum. 2. Write a Swift program to compute and return the absolute difference of n and 51, if n is over 51 return double the absolute difference 3. Write a Swift program that accept two integer values and return true if one of them is 20 or if their sum is 20. 4. Write a Swift program to accept two integer values and return true if one is negative and one is positive. Return true only if both are negative. 5. Write a Swift program to add "Is" to the front of a given string. However, if the string already begins with "Is", return the given string. 6. Write a Swift program to remove a character at specified index of a given non-empty string. The value of the specified index will be in the range 0..str.length()-1 inclusive 7. Write a Swift program to change the first and last character of a given string. 8. Write a Swift program to add the last character (given string) at the front and back of a given string. The length of the given string must be 1 or more. 9. Write a Swift program to check if a given non-negative number is a multiple of 3 or a multiple of 5. 10. Write a Swift program to take the first two characters from a given string and create a new string with the two characters added at both the front and back. 11. Write a Swift program to test a given string whether it starts with "Is". Return true or false. 12. Write a Swift program that return true if either of two given integers is in the range 10..30 inclusive. 13. Write a Swift program to check if a given string begins with "fix", except the 'f' can be any character or number. 14. Write a Swift program to find the largest number among three given integers. 15. Write a Swift program that accept two integer values and to test which value is nearest to the value 10, or return 0 if both integers have same distance from 10. 16. Write a Swift program that accept two integer values and test if they are both in the range 20..30 inclusive, or they are both in the range 30..40 inclusive. 17. Write a Swift program that accept two positive integer values and test whether the larger value is in the range 20..30 inclusive, or return 0 if neither is in that range. 18. Write a Swift program to test whether the last digit of the two given non-negative integer values are same or not. 19. Write a Swift program to convert the last three characters in upper case. If the string has less than 3 chars, lowercase whatever is there. 20. Write a Swift program to check if the first instance of "a" in a given string is immediately followed by another "a".
  • 2. 21. Write a Swift program to create a string made of every other char starting with the first from a given string. So "Python" will return "Pto" 22. Write a Swift program to count the number of 7's in a given array of integers. 23. Write a Swift program to check if one of the first 4 elements in a given array of integers is a 7. The length of the array may be less than 4. 24. Write a Swift program to test if the sequence of numbers 0, 1, 2 appears in a given array of integers somewhere. 25. Write a Swift program to create a new string where all the character "a" have been removed except the first and last positions. 26. Write a Swift program to create a string taking characters at indexes 0, 2, 4, 6, 8, .. from a given string 27. Write a Swift program to count the number of times that two 7's are next to each other in a given array of integers. 28. Write a Swift program to test whether a value presents sequentially three times in an array of integers or not.