Monday, December 27, 2010

scan n numbers and display them (using array)

/****************************
* Umang B Bhatt *
* bhatt.umang7@gmail.com *
*****************************/

/**
* program for scannign n numbers and displaying them
*/

#include<stdio.h>
void main()
{


int
n = 0 , i =0 ;

int
no[100];
printf("How many numbers you want to scan ? ");
scanf("%d",&n);

if
(n < 0 || n>100)
{

printf("Invalid number. It must be brtween 1 to 100");
}


else

{

// logic for scanning the numbers
for(i = 0 ; i < n ;i++)
{


printf("Enter element %d: ", i);
scanf("%d",&no[i]);
}



// the logic for displaying the numbers
for(i = 0 ; i < n ;i++)
{


printf("\nnumber at index %d is %d ", i , no[i]);
}
}

printf("\n");
}

No comments:

Post a Comment