0

I am taking two arrays and i need to add them in solidity . is this the correct way ?

// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;  
contract Types {  
      
        // Declaring state variables
        // of type array
        uint[6] data1;    
          
        // Defining function to add 
        // values to an array 
        function array_example() public returns (
        int[5] memory, uint[6] memory){  
                
            int[5] memory data 
            = [int(50), -63, 77, -28, 90];  
            data1 
            = [uint(10), 20, 30, 40, 50, 60];
                
            return (data, data1);  
      }  
    function add() public {
    
        
        for (uint256 i = 0; i < 5; i++) {
             s += a[i];
        }
        
    }
1
  • Yes in common. Correctly close contract definition and declare "s" variable in function "add".
    – Mad Jackal
    Jan 14 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.