C Program to Find Total of Even Integers

C Arrays with Examples

C Arrays are convenient way of grouping lot of variables under single variable name. Arrays they can be one dimensional, two dimensional or more dimensional! An array is defined using square brackets []. For example: an array of three integers called “triplet” would be declared like this:

int triplet[3];

The number in the square brackets of the declaration is referred to as the ‘index’ (plural: indicies) or ‘subscript’ of the array and it must be an integer number between 0 and (in this case) 2. The three integers are called elements of the array and they are referred to in a program by writing:

triplet[0]
triplet[1]
triplet[2]

An C arrays are fixed number of data items that are all of the same type. The data items in an array are referred to as elements. The elements in an array are all of type int, or of type long, or all of any type you choose. The following array declaration is similar to a declaration for a normal variable that contains a single value, except that you’ve placed number between square brackets [] following the name:

long numbers[10];

The number between square brackets defines how many elements the array contains and is called the array dimension. An array has a type, which is a combination of the element type and the number of elements in the array. Thus two arrays are of the same type if they have the same number of elements of the same type.


Every one want to know Why use C arrays?

C Arrays are most useful when they have a large number of elements: that is, in cases where it would be completely impractical to have a different name for every storage space in the memory. It is then highly beneficial to move over to arrays for storing information for two reasons:

  • The storage spaces in arrays have indicies. These numbers can often berelated to variables in a problem and so there is a logical connection to be made between an array program.
  • In C arrays can be initialized very easily indeed. It is far easier to initialize an array than it is to initialize twenty or so variables. The first of these reasons is probably the most important one

C Arrays with Examples

Here can see the example, how  to do and design Averaging ten grades – storing the values the easy way.

#include <stdio.h>
int main(void)
{
int grades[10]; // Array storing 10 values
unsigned int count = 10; // Number of values to be read
long sum = 0L; // Sum of the numbers
float average = 0.0f; // Average of the numbers
printf("\nEnter the 10 grades:\n"); // Prompt for the input
// Read the ten numbers to be averaged
for(unsigned int i = 0 ; i < count ; ++i)
{
printf("%2u> ",i + 1);
scanf("%d", &grades[i]); // Read a grade
sum += grades[i]; // Add it to sum
}
average = (float)sum/count; // Calculate the average
printf("\nAverage of the ten grades entered is: %.2f\n", average);
return 0;
}

You start off the program with the ubiquitous #include directive for stdio.h because you want to use printf() and scanf(). At the beginning of main(), you declare an array of ten integers and then the other variables that you’ll need for calculation:

The above Example output looks

Enter the ten grades:
1> 450
2> 765
3> 562
4> 700
5> 598
6> 635
7> 501
8> 720
9> 689
10> 527
Average of the ten grades entered is: 614.70

You’ve calculated the average by dividing sum by count, the number of grades. Notice how you convert sum (which is type long) to type float in the call to printf().

Online Training Tutorials

  • C Program to Find Total of Even IntegersC Tutorial – Learn C Programming Language TutorialLearn C programming is very easy if you follow our popular C tutorial which will take you from the beginning of C programming. This C tutorial is mainly designed for beginners and […]
  • SAP functional locationSAP functional location an OverviewSAP Functional Location are elements of a technical structure (for example, functional units within a system). The business object functional location is an organizational unit within […]
  • Ruby Interview QuestionsRuby Interview Questions and AnswersProgramming Ruby is known to Rubyists. It is a tutorial and reference for the Ruby programming language. Before we start talking about the Ruby language, it’d be useful if we helped you […]
  • R3 ArchitectureMain Components of R/3 ArchitectureComponents of R3 Architecture Database Server The database server is the most powerful server in an R/3 system. R/3 uses the database management system as central storage for all R/3 […]
  • Make Faster Business Decisions With SAP HANAMake Faster Business Decisions With SAP HANAAnyone familiar with SAP’s solutions for the Intelligence Enterprise understands that intelligent enterprises effectively use their data assets to achieve their desired outcomes faster and […]
  • Clearing in SAPWhat is Clearing in SAP?Clearing in SAP refers to squaring-off open debit entries with that of open credit entries. Clearing is allowed in GL accounts maintained on an ‘open item’ basis and in all customer/vendor […]
  • Flagging Material Master RecordsFlagging Material Master Records for Deletion SAP PPFlagging Material Master Records for Deletion: For a material master record to be deleted by the archive and delete program, it must be flagged for deletion. You can set deletion flags at […]
  • SAP PM Interview QuestionsSAP PM (Plant Maintenance) Interview Questions and AnswersSAP Plant maintenance is an often-overlooked department of a plant or company where substantial savings and even earnings can be gained. We have listed of SAP PM Interview Questions and […]