Skip to content

Instantly share code, notes, and snippets.

@mendess
Created June 24, 2019 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mendess/cc5642ee21aef9c98535215699d13e58 to your computer and use it in GitHub Desktop.
Save mendess/cc5642ee21aef9c98535215699d13e58 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#define kElements 1250000
const char *progress = "-\\|/";
void initArray(int *p, int num){
int i;
for (i = 0; i < num; ++i)
{
p[i]=i;
}
}
int sumArray(int *p, int num)
{
int sum = 0, i;
for(i = 0 ; i < num; i++)
{
sum = sum + p[i];
}
return sum;
}
int main(int argc, char const *argv[])
{
int i;
printf("Initializing array [-]");
int a[kElements];
/* Generate random numbers <100 */
for(i = 0; i < kElements; i++)
{
if(i % 100 == 0)
{
//printf("%d\n",i);
printf("%c%c%c]",'\b','\b',progress[(i/100) % 4]);
fflush(stdout);
}
initArray(a,kElements);
}
printf("\n\nSUM: %d \n\nDONE!\n\n",sumArray(a,kElements));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment