battle programminga forum for elite programmerswith extreme will powerto sharpen theire skills
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Share | 
 

 ios exercises

Go down 
AuthorMessage
Moti Barski

avatar

Posts : 246
Join date : 2011-08-02

PostSubject: ios exercises   Sun Oct 07, 2018 8:29 pm

simple grade alg with avg, sum :
swift code (run at swift online IDE : http://online.swiftplayground.run/)
Code:
import Foundation

var grades = [10, 20, 30, 40,50,60,70,80,100,100]
var students = ["one","two","three","four","five","roku","shichi","hachi","kyuu","juu"]
let fail = 55
var sum=0
var max = 0
 print(grades.count)
for idx in 0...grades.count-1
 {
    sum+=grades[idx]
    if max <= grades[idx] {max = grades[idx]}
    if grades[idx] < fail {print("\(students[idx]) has failed")}
 }
 var avg = sum/grades.count
 print("avg grade : \(sum/grades.count)")
 print("highest ranking students :")
for idx in 0...grades.count-1
{
  if max == grades[idx] {print(students[idx])}
}
print("below avg :")
for idx in 0...grades.count-1
{
  if avg > grades[idx] {print(students[idx])}
}


out put :


Code:
10
one has failed
two has failed
three has failed
four has failed
five has failed
avg grade : 56
highest ranking students :
kyuu
juu
below avg :
one
two
three
four
five
works computer rage

_________________
MB over and out _______________________     
Back to top Go down
View user profile
 
ios exercises
Back to top 
Page 1 of 1
 Similar topics
-
» Selenium Webdriver Tutorial with Practice Exercises
» Army PRT
» Somatic Treatment For Headache Relief?
» Selenium Tutorials with Practice Exercises and Complete Examples (ToolsQA.com)

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: chit chat-
Jump to: