Need some help :- I have got a very easy question :- Write - TopicsExpress



          

Need some help :- I have got a very easy question :- Write a program that reads numbers which are in the range 0 to 100, till it encounters -1. Print the sum of all the integers that you have read before you encountered -1 INPUT: A sequence of integers separated by whitespace. There may be other integers following -1. OUTPUT: Sum of all integers in the sequence before you encounter -1. Any integer that is input after -1 in the sequence should be ignored. Test cases :- Sample Test Cases Input Output Test Case 1 2 -1 2 3 2 Test Case 2 -1 4 5 0 Test Case 3 10 3 4 -1 17 Test Case 4 2 3 4 5 6 -1 7 20 Now I have to submit the the code in an online compiler that uses Sphere online judge engine (probably) Now you see the question is very easy and can be done in several ways like ;- command line args, or in a loop take input and do the sum and then as soon as you encounter -1 just break out and print the sum. But here since its an online platform so they are giving the parameters by themselves. Now since the number of parameters they give are not fixed and hence it isnt possible to use a variable to use store them. Also maybe there are some other mechanisms to get all the inputs just using the scanf only but I dont know what are they if you know then please share it with us. So I wrote the following to do the job : - pastebin/pgtQ1Ftr I have run the above code on Linux and it works perfectly but I get a warning :- warning: assignment makes pointer from integer without a cast [enabled by default] But the code works and you can see the working in the following link (I have given the input myself here for now) :- codepad.org/tf4TASB2 Now unless I remove the warning I wont be able to submit my code even if it works. I require some assistance. Thank you.
Posted on: Tue, 04 Mar 2014 06:38:59 +0000

Trending Topics



Recently Viewed Topics




© 2015