i m new in c++ my Question is that)
Write a program that reads n numbers (n<1000) from the file “example.txt” (attached) and store it in an array. Ask the user to input n using keyboard at runtime. Then:
a. Compute the sum of the numbers read using any of the loop constructors you have
b. Compute the sum of the numbers read using a recursive function.
learned (for, while or do-while).
I JUST WRITE THIS...
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
int a,b;
int arr[1000];
cout<<"Enter value of n: "<<endl;
cin>>a;
ifstream infile("example.txt")
infile>>a;
.
.
.
I NEED HELP TO COMPLETE MY PROGRAM...
ANYONE COMPLETE MY PROGRAM PLEASE....??
unsignedlong fact(unsignedlong i)
{
if (i < 2)
return 1;
return i * fact(i - 1);
}
You have to pass pointer to first element of the array and array size to your function, and add that element to result of calling same function but with incremented pointer and decremented size.
Now, when you are not in danger of not receiving credit, open your books and start learning from the beginning. Also I would suggest dropping C++ if you are not interested in learning it.
Another good tutorials: http://www.cplusplus.com/doc/tutorial/ http://www.learncpp.com/