March 11th, 2013, 09:57 AM
#1
help me with c++
I need to find S and please explain how did you find S in N is 4
#include <iostream>
int main ()
{
int n,i,s;
cout<<"Put the number of n"<<endl;
cin>>n;
s=0
for (i=1;i<=n;i++)
s=s+i
cout<<"S is<<s<<endl;
return 0
}
March 11th, 2013, 10:27 AM
#2
March 11th, 2013, 10:30 AM
#3
Re: help me with c++
I need to find S if N is 4...
March 11th, 2013, 10:41 AM
#4
Re: help me with c++
So what's your question? Run the program and input 4.
March 11th, 2013, 11:05 AM
#5
Re: help me with c++
#include <iostream.h>
#include <stdlib.h>
int main()
{
int n,i,s;
cout<<"Insert number of n"<<endl;
cin>>n;
s=o;
for(i=1;<=n;i++)
s=s+i;
cout<<"S is"<<s<<endl;
system("PAUSE");
return 0;
I have 3 erors can anyone fix them?
March 11th, 2013, 11:07 AM
#6
Re: help me with c++
But before you can run it, you will need to fix the compile errors - particularly relating to missing ;
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
March 11th, 2013, 11:18 AM
#7
Re: help me with c++
I fixed all missing ; but still 3 errors left....
Anyone has idea where am i wrong?
#include <iostream.h>
#include <stdlib.h>
int main()
{
int n,i,s;
cout<<"Insert number of n"<<endl;
cin>>n;
s=o;
for(i=1;<=n;i++)
s=s+i;
cout<<"S is"<<s<<endl;
system("PAUSE");
return 0;
March 11th, 2013, 11:23 AM
#8
Re: help me with c++
Code:
#include <iostream.h >
This is not standard ANSI c++. For standard ANSI c++ your headers should be
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
March 11th, 2013, 11:24 PM
#9
Re: help me with c++
Originally Posted by
lopce
I fixed all missing ; but still 3 errors left....
Anyone has idea where am i wrong?
Code:
#include <iostream.h>
#include <stdlib.h>
int main()
{
int n,i,s;
cout<<"Insert number of n"<<endl;
cin>>n;
s=0 ;
for(i=1;i <=n;i++)
s=s+i;
cout<<"S is"<<s<<endl;
system("PAUSE");
return 0;
}
If you want to learn C++, you need to understand the syntax of the language. These are simple errors that even a beginner should be able to find and fix easily.
By the way, the answer is 10.
S = (N * (N + 1)) / 2;
Now write a program to find 12 + 22 + 32 + 42 .
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks