Calculate Sum and Average of N Numbers using Arrays: C Program

preview_player
Показать описание

Lets write a C program to calculate Sum and Average of N numbers using Arrays and using macros and for loop.

Formula To Calculate Sum and Average
int a[5] = {2, 4, 6, 5, 9};

sum = 2 + 4 + 6 + 5 + 9;
average = sum / 5.0;

Typecasting
int N = 5;

sum = 2 + 4 + 6 + 5 + 9;
average = sum / (float)N;

Since N is integer type variable, dividing any number by N would give us integer data. For some input it’ll result in wrong result. To fix it, we make use of typecasting and cast the type of N to float using above syntax.

C Programming Interview / Viva Q&A List

C Programming: Beginner To Advance To Expert
Рекомендации по теме
Комментарии
Автор

Cleared up my doubts ..too good explanation

nidhidhyani
Автор

Sir thank-you for a great tutorial, very informative and helpful.

frankbarker
Автор

Thank you sir I like your step-by-step teaching process as it is very useful to me...

okcraft
Автор

Sir very helpful
keep going
I just clicked bell icon

manushapaudel
Автор

Which sofware do you use for program, ming

aryanvanjare
Автор

to find sum of series up to n number, 2+5+8+…………………+n. Can you make a program on this

harshmadhur
Автор

can you teach me how can i make a program enter integer numbers .. without Specify 'N'

AbdElrahmanAmirMohamed
Автор

thanks for telling how to get decimal part

arghyaroy