PsychicFreak
Member
- Joined
- Jun 6, 2008
- Sythe Gold
- 0
- Messages
- 53
guys how can i create a c program that will ask for 3 numbers from the user?
btw im using dev-C++
btw im using dev-C++
#include <stdio.h>
main() {
int numbers[3];
int i;
for (i = 0; i < 3; i++) {
printf("Please enter a number");
scanf("%d", &numbers[i]);
}
}

Here is a simple program
Code:#include <stdio.h> main() { int numbers[3]; int i; for (i = 0; i < 3; i++) { printf("Please enter a number"); scanf("%d", &numbers[i]); } }
In case you're wondering what the "%d" is, you can read up here on different format specifiers. http://www.mekong.net/tech/printf.htm
is this c or c++?
ohw tnx. then what should i do to calculate the total of the three numbers and the average?
im trying to learn this lessonpls help me hehe
#include <stdio.h>
main() {
int numbers[3];
int total = 0;
double average;
int i;
for (i = 0; i < 3; i++) {
printf("Please enter a number");
scanf("%d", &numbers[i]);
total += numbers[i];
}
/* sizeof returns the number of bytes in a variable, with this we can get the amount of elements */
average = total / (sizeof(numbers) / sizeof(numbers[0]));
printf("The total is %d. The average is %f.", total, average);
}
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int num[3];
// input VVVV
for (int b=0;b<3;b++)
{
cout << "Enter a number\n";
cin >> num[b];
}
// computation of total
int total = num[0]+num[1]+num[2];
// computation of average
int average = total/3;
//assuming you want printout of this information?
cout << "The total of your three numbers is " << total << ", and the average is " << average <<"\n";
system("Pause");
return 0;
}

