What is a C++ program to print the sum and count of negative numbers out of a list of 26 numbers. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is a C++ program to print the sum and count of negative numbers out of a list of 26 numbers.

https://code.sololearn.com/cv8AA37fUWnK/?ref=app

25th Nov 2019, 3:25 PM
malk Al-Maamari
malk Al-Maamari - avatar
26 Answers
+ 5
malk Al-Maamari Check this code. for(int j = 0; j < 26; j++) { if(list1[j] < 0) { cout << list1[j] << endl; negativeCount++; Sum += list1[j]; } } https://code.sololearn.com/csWlem8TE5La/?ref=app
25th Nov 2019, 9:05 PM
A͢J
A͢J - avatar
+ 9
Hawker Miner please don't spam irrelevant and unknown links and things in the q/a section or any other section of the app. Delete all your answers and comments which include this survey things it's not the right place to send it here continuing this thing may lead to your account deactivation so please follow the guidelines and remove all your posted answer which include the links and comments in code and feed post
27th Nov 2019, 11:34 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 5
No it's not right because you are not adding and counting negative numbers.
25th Nov 2019, 3:41 PM
A͢J
A͢J - avatar
+ 4
Try it yourself. Use <0 and if statements to test for negative numbers.
26th Nov 2019, 3:56 AM
Sonic
Sonic - avatar
+ 4
You might want to do the C++ tutorial here.
26th Nov 2019, 3:56 AM
Sonic
Sonic - avatar
+ 3
malk Al-Maamari Now it's correct but you can write all logic in a single loop. You are adding all number but according to your question only negative numbers should be add.
25th Nov 2019, 8:58 PM
A͢J
A͢J - avatar
+ 3
Hawker Miner How we can check our coding skills through survey? And please don't share that types of links on this plateform. This is learning plateform.
27th Nov 2019, 11:42 AM
A͢J
A͢J - avatar
+ 1
You are taking 27 inputs (0 to 26) and displaying negative numbers. If you want sum of all inputs , then where are you calculating sum. And count for negatives. Try for that also.. edit: malk Al-Maamari when you specify i<=25 it includes 25 also, so total becomes 26 (0 to 25). but you initialized 25 only so it may rise error. so take it as i<25. As a beginner, you are in good track, do experiment a lot like this but first try with digits like 4 or 5 inputs after that go for numbers above 10.. keep going.. happy coding....
25th Nov 2019, 3:44 PM
Jayakrishna 🇮🇳
+ 1
malk Al-Maamari why don't you do it with small set of numbers to check whether you are getting the answer or not and then increase the entries later. Edit: Because I can see you struggling with the code. You have created an array of size 25 but trying to store 27 elements in it. Also just like 🅰🅹 - ɪ'ᴍ ᴄʀɪᴍɪɴᴀʟʟʏ ɢᴏᴏᴅ! and Jaya krishna said, there is no adding or counting happening in your code. Kindly revisit the course.
25th Nov 2019, 5:02 PM
Avinesh
Avinesh - avatar
25th Nov 2019, 9:21 PM
malk Al-Maamari
malk Al-Maamari - avatar
25th Nov 2019, 9:27 PM
malk Al-Maamari
malk Al-Maamari - avatar
+ 1
What is c ++ program to print the sum and count of negativity number Out of the lis H¡¡5
26th Nov 2019, 4:35 AM
Nayem Bithe
+ 1
Nayem Bithe This is not right place to ask another question.
26th Nov 2019, 5:01 AM
A͢J
A͢J - avatar
0
I s my program correct?
25th Nov 2019, 3:27 PM
malk Al-Maamari
malk Al-Maamari - avatar
0
Okay.
25th Nov 2019, 3:55 PM
malk Al-Maamari
malk Al-Maamari - avatar
0
Good, I am new in programming
25th Nov 2019, 5:33 PM
malk Al-Maamari
malk Al-Maamari - avatar
0
while(i < 26) { if number is positive add(num) else count(negative) i++ }
25th Nov 2019, 6:49 PM
Rohit Kh
Rohit Kh - avatar
25th Nov 2019, 8:18 PM
malk Al-Maamari
malk Al-Maamari - avatar
25th Nov 2019, 8:42 PM
malk Al-Maamari
malk Al-Maamari - avatar
0
#include <iostream> using namespace std; int main() { int arr[5]={-2,-1,0,1,2}; int sum=0,negcount=0; for(int i=0;i<5;i++) { if (arr[i]<0) negcount++; else sum+=arr[i]; } cout << "sum is:" << sum; cout << "neg nums: " << negcount; }
25th Nov 2019, 8:42 PM
Rashad Malikov
Rashad Malikov - avatar