+ 6
addition of n numbers...
#include < iostream.h > int main() { int n, sum = 0, c, value; cout<<"Enter the number of integers you want to add\n"; cin>>n; cout<<"Enter"<<n<<"integers"<<"\n"; for (c = 1; c <= n; c++) { cin>>value; sum = sum + value; /*adding each no in sum*/ } cout<<"Sum of entered integers ="<<sum<<"\n"; return 0; }
2 Antworten
+ 4
???
if you are asking for errors, you were just simply missing a
" using namespace std; "
underneath the #include....
+ 3
First of all to include standart livraries you don't need to write .h at the end:
Like that #include <iostream>
Second, is that you are using std module, so you should write std::count, std::cin,
or just use this namespace like that:
using namespace std;
With this line you will be able to simply write cout, cin.
Fixed version of you code:
#include <iostream>
using namespace std;
int main()
{
int n, sum = 0, c, value;
cout << "Enter the number of integers you want to add\n";
cin >> n;
cout<< "Enter " << n <<" integers"<<"\n"; // Add spaces to strings
for (c = 1; c <= n; c++)
{
cin >> value;
sum = sum + value;
/*adding each no in sum*/
}
cout << "Sum of entered integers = " << sum; // << "\n" is redutant
return 0;
}