SlideShare a Scribd company logo
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

Similar to practice problems on functions IN SWIFT (20)

DOC
Programming qns
Dr.Subha Krishna
 
DOCX
If switch structure
M Sagheer Malik
 
PDF
A10
lksoo
 
DOCX
PYTHON PROGRAMS
Alvino rock
 
PDF
Master Python in 15 Days.pdf
JorgeTorres560505
 
PDF
C programming part4
Keroles karam khalil
 
PDF
C programming part4
Keroles karam khalil
 
DOC
Practical java
nirmit
 
PDF
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
Mark Simon
 
DOCX
CBSE Class 12 Computer practical Python Programs and MYSQL
Rishabh-Rawat
 
PDF
Java Programming - Conditional Statements (Switch).pdf
ROWELL MARQUINA
 
DOCX
C_Lab Manual_Part A.docx
Pandiya Rajan
 
PPTX
C programming assignment presentation file
santoshkumarhpu
 
PDF
50_coding_challengesfffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
SanthoshKumarChandra7
 
PDF
Lab7: More Arrays, Strings, Vectors, and Pointers
enidcruz
 
PDF
The swift programming language
Pardeep Chaudhary
 
DOCX
Oop lab assignment 01
Drjilesh
 
DOCX
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
ABDULAHAD507571
 
Programming qns
Dr.Subha Krishna
 
If switch structure
M Sagheer Malik
 
A10
lksoo
 
PYTHON PROGRAMS
Alvino rock
 
Master Python in 15 Days.pdf
JorgeTorres560505
 
C programming part4
Keroles karam khalil
 
C programming part4
Keroles karam khalil
 
Practical java
nirmit
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
Mark Simon
 
CBSE Class 12 Computer practical Python Programs and MYSQL
Rishabh-Rawat
 
Java Programming - Conditional Statements (Switch).pdf
ROWELL MARQUINA
 
C_Lab Manual_Part A.docx
Pandiya Rajan
 
C programming assignment presentation file
santoshkumarhpu
 
50_coding_challengesfffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
SanthoshKumarChandra7
 
Lab7: More Arrays, Strings, Vectors, and Pointers
enidcruz
 
The swift programming language
Pardeep Chaudhary
 
Oop lab assignment 01
Drjilesh
 
Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx
ABDULAHAD507571
 

More from LOVELY PROFESSIONAL UNIVERSITY (16)

PPTX
Enumerations, structure and class IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
PDF
Dictionaries IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
PDF
Control structures IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
PDF
Arrays and its properties IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
PDF
Array and its functionsI SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
PDF
10. funtions and closures IN SWIFT PROGRAMMING
LOVELY PROFESSIONAL UNIVERSITY
 
PDF
Variables and data types IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
PPTX
Soft skills. pptx
LOVELY PROFESSIONAL UNIVERSITY
 
PPT
STRINGS IN JAVA
LOVELY PROFESSIONAL UNIVERSITY
 
PPT
COMPLETE CORE JAVA
LOVELY PROFESSIONAL UNIVERSITY
 
PPT
Data wrangling IN R LANGUAGE
LOVELY PROFESSIONAL UNIVERSITY
 
Enumerations, structure and class IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
Dictionaries IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
Control structures IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
Arrays and its properties IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
Array and its functionsI SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
10. funtions and closures IN SWIFT PROGRAMMING
LOVELY PROFESSIONAL UNIVERSITY
 
Variables and data types IN SWIFT
LOVELY PROFESSIONAL UNIVERSITY
 
COMPLETE CORE JAVA
LOVELY PROFESSIONAL UNIVERSITY
 
Data wrangling IN R LANGUAGE
LOVELY PROFESSIONAL UNIVERSITY
 
Ad

Recently uploaded (20)

PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Horarios de distribución de agua en julio
pegazohn1978
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
Ad

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.