*Array:- Array is a collection of similar data elements.it is also known as Homogeneous data type.
-> The syntax of Array declaration is as follows:
datatype variable name[SIZE]
int a[10]
*your size is the maximum number of values required to be stored in the Array and index starts from 0 to SIZE-1.
* Initialization an Array:-
In c language an Array can be initialized in these ways:-
int a[8]={11,22,33,34,35,36,37,38};
if we initialize Array in this Array then mentioning size is optional.
* Character - Array:- In C language we can also store the collection of characters into a character Array.
-> collection of characters also known as "STRING".
-> The format specifier for string is "%s".
-> character Array can be initialized as follows:-
char name[20]= {"Raju"};
* Another way is:-
char name[20]={'R','A','J','U'};
-> In the above initialization we have to specify null character, which is denoted by '\0'. This indicates end of string.
for example: char name[20]={'R','A','J','U','\0'};
printf("%s",name);
-> we can also print the name using loop character by char. as follows:-
for(i=0; name[i]!='\0'; i++)
{
printf("%c",name[i]);
}
/* C Program to search a no. in an array */
http://codevidyalay.blogspot.com
#include<stdio.h>
int main()
{
int a[100],i,n,s;
printf("Enter a value:");
scanf("%d",&n);
printf("Enter %d no.s",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter a no. to search:");
scanf("%d",&s);
for(i=0;i<n;i++)
{
if(a[i]==s)
{
printf("Number Found");
return 0;
}
}
printf("Number not found");
return 0;
}
INPUT/OUTPUT:
Enter a value:5
Enter 5 no.s1 2 8 9 6
Enter a no. to search:100
Number not found