Hello
Thank you for this good forum
I am really so happy I am one of its members now..
First, I think it's important to say: The english language is not my native language. So, I am sorry if you find any spelling or grammer mistakes.
I am trying to improve my english language as much as I can and I will be gratefull if you help me.
***
I am a university student
freshmen - level 1
I am studing Computer engineering (Not in my native language. I study it in english language).
This is the first course I study programming language.
We are studying C language basic rules.
***
I faced a small problem in Arrays.
This was the question:
* Develop a complete program that will accept 5 integer numbers from the user and then print the sum of all the numbers on the screen. Use a 1-dimension array named numT to keep all the numbers. The example of interaction and output are as follows:
Please enter number 1
3
Please enter number 2
5
Please enter number 3
4
Please enter number 4
7
Please enter number 5
9
The total number of all number entered is 28
****
I wrote my code and the compiling successed
but when I run the program, the last statement (the total number entered) gives my a garbage number.
I thought there was a mistake in initializing ( sum ) but I didn't know where.
this was my code:
Code:
#include <stdio.h>
void main()
{
int a[5]={0};
int i;
int sum=0;
for(i=0;i<5;i++)
a[i]=i+1;
for(i=0;i<5;i++)
{
printf("Please enter number %d\n",i+1);
scanf("%d",&a[i]);
}
sum = sum + a[i];
printf("The total number of all number entered is %d",sum);
}
I wish some body help me..
I am waiting..
Thank you very much..