C - Use for loop to process array

Description

Use for loop to process array

Demo

#include <stdio.h> 

int main() //from   w  ww. ja  va  2s . c  om
{ 
   int highscore[4]; 
   int x; 

   for(x=0;x<4;x++) 
   { 
       printf("Your #%d score: ",x+1); 
       scanf("%d",&highscore[x]); 
   } 

   puts("Here are your high scores"); 
   for(x=0;x<4;x++) 
       printf("#%d %d\n",x+1,highscore[x]); 

   return(0); 
}

Result

The x+1 arguments in the printf() statements allow you to use the x variable in the loop but display its value starting with 1 instead of 0.

Related Topic