+ 1
What is a C++ program to print the sum and count of negative numbers out of a list of 26 numbers.
26 Respostas
+ 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
+ 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
+ 5
No it's not right because you are not adding and counting negative numbers.
+ 4
Try it yourself. Use <0 and if statements to test for negative numbers.
+ 4
You might want to do the C++ tutorial here.
+ 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.
+ 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.
+ 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....
+ 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.
+ 1
+ 1
🅰🅹 - ɪ'ᴍ ᴄʀɪᴍɪɴᴀʟʟʏ ɢᴏᴏᴅ! Thanks you
+ 1
What is c ++ program to print the sum and count of negativity number Out of the lis H¡¡5
+ 1
Nayem Bithe This is not right place to ask another question.
0
I s my program correct?
0
Okay.
0
Good, I am new in programming
0
while(i < 26) {
if number is positive
add(num)
else
count(negative)
i++
}
0
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;
}