C PROGRAMMING#4 :ARRAYS

Array is a fine oredered collection of finite homogenous data.

DECLARATION OF ARRAY

dataType arrayName[arraysize];

for example

float mark[5];

here we declared array size as 5 meaning it can store 5 different float values.

the compiler will initialize it as

marks[0],marks[1],marks[2] and so on.Compiler always starts from the value 0 and not 1 irrespective of the language.

Lets create a program to print Fibonacci numbers using arrays

#include <stdio.h>

#include<conio.h>

void main()

{

int n,k;

int arr[40];

printf(“Enter ending value”);

scanf(“%d”,&n);

arr[0]=0;

arr[1]=1;

for(i=2;i<n;i++)
arr[i]=arr[i-1]+[i-2];
printf("%d",arr[i]);
}

GIVE ME A CUP OF COFFEE

Give me a cup of coffee so i can publish free articles in shorter time span.

$2.00

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.