0 votes 0 votes suppose i have declared array int a[5] = { 1,2,3,4,5} ; and i want to print output as : a[0] = 1 a[1] = 2 a[2] = 3 a[3] = 4 a[4] =5 can anyone write program in c displaying this output . sumit goyal 1 asked Mar 15, 2018 sumit goyal 1 526 views answer comment Share Follow See all 7 Comments See all 7 7 Comments reply rahul sharma 5 commented Mar 15, 2018 reply Follow Share This should be simple. Are you getting any error in your program? 0 votes 0 votes saxena0612 commented Mar 15, 2018 reply Follow Share //program for : custom print in cpp #include<bits/stdc++.h> using namespace std; //function used to print the values void customPrint(int form_array[],int form_size){ for(int i=0;i<form_size;++i){ cout<<"array["<<i<<"]="<<form_array[i]<<endl; } } int main(void){ //statically inputting the size though //can use other DS in order to make this //dynamic. int sizeOfArray; cout<<"Enter the total numbers to be stored : \t"; cin>>sizeOfArray; int array[sizeOfArray]; for(int i=0;i<sizeOfArray;++i){ cout<<"Enter the "<<i+1<<" Element value :\t"; cin>>array[i]; } //functio calling customPrint(array,sizeOfArray); system("pause"); return 0; } 0 votes 0 votes sumit goyal 1 commented Mar 15, 2018 reply Follow Share rahul iam getting output as 1 = 1 2 =2 3 = 3 4 =4 5 =5 you write your program thanks advance 0 votes 0 votes Sukannya commented Mar 15, 2018 reply Follow Share #include <stdio.h> int main(){ int a[5]={1,2,3,4,5}; int i; for(i=0;i<5;i++) { printf("a[%d]=%d\n",i,a[i]); } return 0; } Is this what you wanted? 3 votes 3 votes sumit goyal 1 commented Mar 15, 2018 reply Follow Share Sukannya thank you ( a[%d]=%d\n",i,a[i] ) explain this in little please 0 votes 0 votes Sukannya commented Mar 15, 2018 reply Follow Share %d in the index of a takes the value of i which is 0 and the next %d is taking a[i] which is 1. 1 votes 1 votes sumit goyal 1 commented Mar 15, 2018 reply Follow Share thanks Sukannya 1 votes 1 votes Please log in or register to add a comment.