View Single Post
  #5  
Old 10-31-2006, 01:38 AM
Lurker4 Lurker4 is offline
Senior Member
 
Join Date: Oct 2004
Location: Urbana, IL
Posts: 762
Default Re: C Programming Noob - Need Help Plz.

[ QUOTE ]
I can give it to you in c++. This is pretty basic programming you should really learn it.
#include <iostream>
using namespace std;

int main()
{
int num1;
double num2;
double sum;
double product;
cout << "Enter an int: ";
cin >> num1;
cout << "Enter a double (decimal): ";
cin >> num2;
product = num1 * num2;
sum = num1 + num2;
cout << "Sum of the nums is: " << sum << endl;
cout << "Product of the nums is: " << product << endl;
return 0;
}

[/ QUOTE ]

This just prints the sum and product of two numbers, not the sequence of numbers that he needs. This should be the answer in C, although there might be a few syntax errors:

int n;
double product = 1;
double sum = 0;
double a;

printf("Enter int n:");
scanf("%d", &n);
printf("\n");

for (int i = 1; i <= n; i++)
{
printf("Enter double %d:", i)
scanf("%f", &a);
printf("/n");
sum = sum + a;
product = product * a;
}

printf("Sum is: %d\n", sum);
printf("Product is: %d\n", product);


I don't want to sound like a jerk but this is really basic stuff. If you're going to do more C/C++ programming in this class, I'd either carefully go through the examples in your book, or go through some online tutorial. Also, if you understand the above code, then the next question is similar but using a while loop and an if statement.
Reply With Quote