Câu hỏi phỏng vấn Objective-C
Câu hỏi

A grandparent, parent and child problem

Câu trả lời

Here is a possible solution to the "Grandparent, Parent and Child" problem in Objective-C:

Grandparent, Parent and Child Problem

The problem is as follows:

  • There is a grandparent, parent and child
  • The grandparent has a certain amount of money
  • The grandparent gives half of their money to the parent
  • The parent gives half of their money to the child
  • The child spends all their money on candy
  • The grandparent is left with a certain amount of money
  • What is the amount of money the grandparent is left with?

Solution in Objective-C

Here is a possible solution in Objective-C:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // Initial amount of money the grandparent has
        int grandparentMoney = 100;
        
        // Grandparent gives half to parent
        int parentMoney = grandparentMoney / 2;
        grandparentMoney = grandparentMoney - parentMoney;
        
        // Parent gives half to child
        int childMoney = parentMoney / 2;
        parentMoney = parentMoney - childMoney;
        
        // Child spen...
middle

middle

Gợi ý câu hỏi phỏng vấn

senior

Why delegate is never retained?

senior

Explain the difference between interfaces, delegates, and protocols in Objective-C

junior

What are blocks and how are they used?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào