Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript Site
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

US Job listings




   Misc

   Amazon

   Links

    


Array counting
 

 

 

Description

This example is used to count how many passes there are in the array . A pass is 70 or over but it can be changed by changing the value parameter in the count_passes function.

Code

/**************************************
count occurrences of values in an array
***************************************/
#include <stdio.h>

void print_arr(int grades[], int elements);
int count_passes(int grades[], int elements,int value);

int main(void)
{
int grades[10] = {70,80,95,65,35,85,54,78,45,68};
int result;
print_arr(grades,10);
result = count_passes(grades,10,70);
if(result == 1)
printf("There was %d pass.\n",result);
else
printf("There were %d passes.\n",result);
return 0;
}

void print_arr(int grades[], int elements)
{
int i;

for(i = 0;i < elements;i++)
{
printf("%d ",grades[i]);
}
printf("\n");
}

int count_passes(int grades[], int elements,int value)
{
int i ,passes = 0 ;
for(i = 0;i < elements;i++)
{
if(grades[i] >= value)
passes++;
}
return(passes);
}

Information

tested using Visual C++

 

 

 

 

Download

countarray.txt


 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
File exists with PHP and Java(PHP)
an explode function example(php)
Earth years to other planets(C)
area of rectangle function(Javascript)
Sending an e-mail attachment(ASP)
Bubblesort routine(PHP)
radians to degrees conversion(C Sharp)
space between text(CSS)

    




Copyright © 2003 by programmershelp.co.uk