import Foundation
import Glibc
//1
func count_Slength(str: String)
{
let i=str.count
print(i)
}
//count_Slength(str:"Hello World")
//2
func strcat(str1: String,str2:String)
{
print(str1+str2)
}
//strcat(str1:"Hello",str2:" World")
//3
func turn_uppercase(str:String)
{
print(str.uppercased())
}
//turn_uppercase(str:"hello")
//4
func find_replace(str1:String,str2:String)
{
print(str1.replacingOccurrences(of:str2,with:"nlhdung"))
}
//find_replace(str1:"Hello World Hello",str2:"Hello")
//5
func find_delete(str1:String,str2:String)
{
print(str1.replacingOccurrences(of:str2,with:""))
}
//find_delete(str1:"Hello World Hello",str2:"Hello")
//6
func find_insert_Start(str1:String)
{
var str2=str1
str2.insert(contentsOf:"nlhdung",at:str2.startIndex)
print(str2)
}
//find_insert_Start(str1:"Hello")
//7
func find_insert_End(str1:String)
{
var str2=str1
str2.insert(contentsOf:"nlhdung",at:str2.endIndex)
print(str2)
}
//find_insert_End(str1:"Hello")
//8
func find_insert_x(str1:String,i:Int)
{
var str2=str1
let str3=str2.index(str2.startIndex,offsetBy:i)
str2.insert(contentsOf:"nlhdung",at:str3)
print(str2)
}
//find_insert_x(str1:"Hello World",i:3)
//9
func count_Appearance(str1:String)
{
let flag=str1.components(separatedBy:"nlhdung")
print(flag.count-1)
}
//count_Appearance(str1:"Hello nlhdung nlhdung nlhdung nlhdung")
//10
//11
func reverse_Array(array:[Int])
{
var arr=array
var j=4
for i in 0...4
{
arr[i]=array[j]
j=j-1
}
print(arr)
}
//reverse_Array(array:[1,2,3,4,5])
//12
func cal1_sum(number:Int)
{
var count=0
var sum=0
for i in 1...number
{
if(number%i==0)
{
count=count+1
sum=sum+i
}
}
let result=(countd:count,sumd:sum)
print("So luong uoc so: \(result.countd)")
print("Tong cac uoc so: \(result.sumd)")
}
//cal1_sum(number:15)
//13
func cal2(number:Int)
{
var copy=number
var count=0
var sum=0
var flag=0
while (copy>=1)
{
flag=copy%10
sum=sum + flag
copy=copy/10
count=count+1
}
let result=(countd:count,sumd:sum)
print("So luong chu so: \(result.countd)")
print("Tong cac chu so: \(result.sumd)")
}
//cal2(number:519)
//14
func cal3(number:Int)
{
var copy=number
var count1=0
var count2=0
var flag=0
while(copy>=1)
{
flag=copy%10
if(flag%2==0)
{
count1=count1+1
}
else{ count2=count2+1}
copy=copy/10
}
let result=(countd1:count1,countd2:count2)
print("So luong chu so chan: \(result.countd1)")
print("So luong chu so le: \(result.countd2)")
}
//cal3(number:2519)
//15
func cal4(number:Int)
{
var sum:Double = 0
var flag:Double=1
for _ in 1...number
{
sum=sum + pow(flag,2)
flag=flag+1
}
print("Ket qua bieu thuc: \(sum)")
}
//cal4(number:5)
//16
func Make_Array()
{
var array = Array(repeating:"n", count:100)
for i in 0...99
{
array[i]="nlhdung-\(i+1)"
}
print(array)
}
//Make_Array()
//17
func Arrange_Increase(arr:[Int])
{
var array=arr
var flag=0
for i in 0...3
{
for j in i+1...4
{
if(array[i]>array[j])
{
flag=array[i]
array[i]=array[j]
array[j]=flag
}
}
}
print("Mang da sap xep tang dan \(array)")
}
//Arrange_Increase(arr:[12,15,46,32,59])
//18
func Arrange_Decrease(arr:[Int])
{
var array=arr
var flag=0
for i in 0...3
{
for j in i+1...4
{
if(array[i]<array[j])
{
flag=array[i]
array[i]=array[j]
array[j]=flag
}
}
}
print("Mang da sap xep giam dan \(array)")
}
//Arrange_Decrease(arr:[12,15,46,32,59])
//19
func Arrange(k:Int)
{
if(k==1)
{
Arrange_Increase(arr:[12,15,46,32,59])
}
else
{
Arrange_Decrease(arr:[12,15,46,32,59])
}
}
Arrange(k:1)
//20
About Online Swift Compiler
Try our Online Swift Compiler (Version Swift v5.7.3) to Edit, Run, and Share your Swift Code directly from your browser. This online development environment provides you the latest version Swift v5.7.3.
How to use Online Swift Compiler?
Write and Execute Code
- Write your program (or, paste it) directly under the "Source Code" tab.
- If you want to save your program, go to the "Project" menu and save it.
- You can directly execute your program without saving it by clicking on on "Execute" button.
User Input
The latest version of Coding Ground allows to provide program input at run time from the termnial window exactly the same way as you run your program at your own computer. So simply run a program and provide your program input (if any) from the terminal window available in the right side.
Online Swift Compiler: Keyboard Shortcuts
The following are the keyword shortcut of this Online Swift Compiler:
Shortcut | Description |
⌘ + Enter | Run the program |
⌘ + S | Save Project (Login Required) |
⇧ + ⌘ + S | Save As Project |
⌘ + P | New Project |
⌘ + G | Share Project |
⌘ + Z | Undo Editing |
⌘ + Y | Redo Editing |
⌘ + A | Select All Text |
⌘ + X | Cut Selected Text |
⌘ + C | Copy Selected Text |
⌘ + V | Paste Copied Text |
⌘ + F | Search Text |
⌘ + ⌥ + F | Replace Text |
Shortcut | Description |
Ctrl + Enter | Run the program |
Ctrl + S | Save Project |
Shift + Ctrl + S | Save As Project |
Ctrl + G | Share Project |
Ctrl + Z | Undo Editing |
Ctrl + Y | Redo Editing |
Ctrl + A | Select All Text |
Ctrl + X | Cut Selected Text |
Ctrl + C | Copy Selected Text |
Ctrl + V | Paste Copied Text |
Ctrl + F | Search Text |
Ctrl + H | Replace Text |
Online Swift Compiler: Save and Share Swift Code (Project)
Save Swift Project Online
You can save your Swift Project with us so that you can access this project later on. To save a project you will need to create a login Id with us. So before you save a project, please create a login Id using a link given at the top right corner of this page.
Share Swift Project Online
You can use this feature to share your Swift Code with your teachers, classmates and colleagues. Just click Share Button and it will create a short link, which can be shared through Email, WhatsApp or even through Social Media. A shared link will be deleted if it has been passive for almost 3 months.
More Features of Online Swift Compiler
- Theme – You can change the current editor's theme from the "Editor Theme" option under "Settings" menu.
- Font Size – You can change the font size of the editor /compiler from from the "Font Size" option under "Settings" menu.
- Tab Size – You can change the tab size from the "Tab Size" option under "Settings" Menu.
- Show/Hide Line Numbers – You can show/hide the line number with the code from the "Show Line Numbers" or "Hide Line Numbers" option under "Settings" Menu.
- And, many more.
Benefits of Using Online Swift Compiler
There are several benefits of using the Online Swift Compiler to run your Swift code:
- Platform independence: You can run your code from any device without taking care of operating systems.
- Convenience: You don't need to install anything for using this.
- No setup required: There is no need for additional setup to run your code.
- Updated version: Our online compiler/editors/terminals are the latest up-to-date.