[Solved] Convert a `while` loop to a `for` loop

I think it should be something like this : for(;a<b–;){ for(d += a++ ; a != c ; ) { d += a++; } c+= a&b } The above logic works ! I ran both programs as below and they output the same result : Program1:[derived from your program 1] #include<stdio.h> int main(){ int a=10,b=10,c=10,d=10; … Read more

[Solved] Looping javascript multi array

Three loops for each array. Just loop through every array, and append to new array. var size = [‘s’,’m’]; var color = [‘red’,’blue’,’black’]; var material = [‘cotton’,’linen’]; var arrayMaterials = [] for (var i = 0; i < size.length; i++) { for (var j = 0; j < color.length; j++) { for (var k = … Read more

[Solved] How can I save the id of a div tag to a database when clicked and without refresh? [closed]

jQuery, or javascript in general, can’t really connect directly to a database like you are describing. If you have an endpoint to hit, then jQuery (or vanilla javascript, really) could just fire a request to that endpoint with the specific data: $(‘input:file’).on(‘change’, function(event) { $.ajax({ url: ‘/path/to/endpoint’, type: ‘post’, data: { filename: $(this).val() } }); … Read more

[Solved] How can I increment array with loop?

You mean to do: while iterations < itemsInListOne: listOne[iterations] = float(listOne[iterations]) + 1 Note that you needed to convert it to a float before adding to it. Also note that this could be done more easily with a list comprehension: listOne = [float(x) + 1 for x in listOne] solved How can I increment array … Read more

[Solved] While loop won’t continue

I don’t understand what the purpose of cin is here, but if you want the output you requested in the question: // Example program #include <iostream> #include <string> using std::cout; using std::endl; int main() { int Day = 20; while (Day >= 1) { cout << Day << ” “; Day /= 2; } } … Read more

[Solved] Print numbers in columns c++

I want to print a string array containing numbers organized in columns. The array contains {“2″,”1″,”3″,”16″,”8″,”3″,”4″,”1″,”2”} I want to print them in this form 2 16 4 1 8 1 3 3 2 For the the given code of yours, you can do following changes to achieve the result. Find the array length using sizeof(arr)/sizeof(*arr);. … Read more

[Solved] How do i multiply values of an array

You are not reconstructing an array in your foreach loop. So your $od variable does just get overridden each time you loop. Your code should be foreach($_POST[‘gm’] as $key => $answer) { if($answer != ”) { $odd = explode(” “,$answer); $od[] = trim($odd[0]); } } $total = array_product($od); echo $total; 0 solved How do i … Read more

[Solved] sorting in the order of lowercase first then uppercase then digits and sorting the digits to with the odd no first [closed]

I’m assuming this is homework or something and you are supposed to do this a certain way or something? What are the specifications? I shortened your code anyway if that helps in any way p = “Sorting1234” upper_case = sorted([i for i in p if i.isupper()]) lower_case = sorted([i for i in p if i.islower()]) … Read more