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
play a wav file(C Sharp)
list files in a folder in a text file(VBScript)
send an email with minimal code(VB)
Date/Time examples(PHP)
Create a random file(C Sharp)
Sending an HTML email(ASP)
flickering form effect(VB)
While loop example(Javascript)

    




Copyright © 2003 by programmershelp.co.uk