-->

Write a program to show initialization of element in an array

using turbo c++
--------------------------------------------------------------------------------------------------
//Write a program to show initialization of element in an array
#include<stdio.h>
#include<conio.h>
void main()
{
float arr[4]={1,2,3,4},k;                                                                        // array declaration with 4 elements
                                                                                                         // can also be written as arr[]
printf("elements are\n");
for(k=0;k<=3;k++)
{
   printf(" element for location=%d is\n",k);                               // for elements in particular location
   printf("%f",arr[k]);
}
getch();
}

------------------------------------------------------------------------------------------------------------------------------------------

using codeblocks or dev c++/online compiler
---------------------------------------------------------------------------------------------------------------------------------------
//Write a program to show initialization of element in an array

#include<stdio.h>
int main()
{
float arr[4]={1,2,3,4},k;                                                                        // array declaration with 4 elements
                                                                                                         // can also be written as arr[]
printf("elements are\n");
for(k=0;k<=3;k++)
{
   printf(" element for location=%d is\n",k);                               // for elements in particular location
   printf("%f",arr[k]);
}
return 0;
}

No comments:

Post a Comment