[go: up one dir, main page]

0% found this document useful (0 votes)
40 views3 pages

Program Using Looping Statement and Array

The document contains three C++ programs. The first program prints even numbers from 100 to 0 using while, do-while, and for loops. The second and third programs calculate and print the sum and count of positive and negative numbers from a user-provided list of integers.

Uploaded by

ur mom
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views3 pages

Program Using Looping Statement and Array

The document contains three C++ programs. The first program prints even numbers from 100 to 0 using while, do-while, and for loops. The second and third programs calculate and print the sum and count of positive and negative numbers from a user-provided list of integers.

Uploaded by

ur mom
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Write a program that prints 100, 98, 96, 94, 92, …, 0

(i) While

#include<iostream>

using namespace std;

int main()

int num=100;

while(num>=0)

cout<<num<<endl;

num=num-2;

return 0;

(ii) Do While

#include<iostream>

using namespace std;

int main()

int a=100;

do

cout<<a<<endl;

a=a-2;

}while(a>=0);

return 0;

}
(iii) For Loop
#include<iostream>
using namespace std;
int main()
{
for(int num=100; num>=0;num=num-2)
{
cout<<num<<endl;
}
return 0;
}

2. Write a program to print sum of negative numbers and sum of positive number from a list of
numbers entered by the user.

#include<iostream>
using namespace std;
int main()
{
int n[10],pos=0,neg=0;
cout<<"Enter the numbers";
for(int i=0; i<5;i++)
{
cin>>n[i];
}
for(int i=0;i<5;i++)
{
if(n[i]>0)
pos=pos+n[i];
else if(n[i]<0)
neg=neg+n[i];
else
cout<<n[i]<<"is zero";
}
cout<<"Positve sum="<<pos<<endl;
cout<<"Negative sum="<<neg<<endl;
return 0;
}

3.Write a program to print count of negative numbers and count of positive number from a list of
numbers entered by the user.
#include<iostream>
using namespace std;
int main()
{
int n[10],pos=0,neg=0;
cout<<"Enter the numbers";
for(int i=0; i<5;i++)
{
cin>>n[i];
}
for(int i=0;i<5;i++)
{
if(n[i]>0)
pos=pos+1;
else if(n[i]<0)
neg=neg+1;
else
cout<<n[i]<<"is zero";
}
cout<<"Positive count="<<pos<<endl;
cout<<"Negative count="<<neg<<endl;
return 0;
}

You might also like