0
#include <iostream> using namespace std; int main() { int b[]; int i=0,sum=0; while(cin>>b[i]) {sum=sum+b[i]; i++;} cout<<sum<<endl; }//what is wrong in this code //how can I take multiple inputs into an array //I want to take unknown no. Of inputs
It's showing error in declaration,
4 Respostas
0
Add for loop for cin. And give limits how many inputs you want. Define sum=0 before that for loop.
0
#include <iostream>
using namespace std;
int main()
{
int b[];
int i=0,sum=0;
for(i=0;i<=limit;i++)
cin>>b[i] ;
for(i=0;i<=limit;i++)
{sum=sum+b[i];}
cout<<sum<<endl;
}
0
for multiple input
#include<iostream.h>
using namespace std;
void main()
{
int b[],i=0,sum=0;
cout<<"Enter value(enter 0 to exit):
while(1)
{
cin>>b[i];
if(b[i]==0)
{
break;
}
else
{
sum+=b[i];
}
i++;
}
cout<<"\nSum of array:"<<sum;
}
so this is the code,,,you can try
0
#include<iostream>
using namespace std;
int main ()
{
int sum =0;
for (int i=5; i>=0; i--){
if(i==3){
break;
sum=sum+i;
}
}
cout<<sum;
return 0;
}