Thursday, May 21, 2020

Arrays in C++


  • Program :

#include <iostream>
#include <string>
using namespace std;
int main(){
   cout <<"\n----------------ARRAYS----------------\n";
   cout <<"\n----------------Access the Elements of an Array----------------\n";
   string fruits[4] = {"Apple", "Orange", "Bannana", "Grapes"};
   cout << fruits[3];
 
   cout <<"\n----------------Change an Array Element----------------\n";
   string juice[4] = {"Mazza", "Bovanto", "Mango", "Fanta"};
   juice[1] = "Slice";
   cout << juice[1];
 
   cout <<"\n----------------Loop Through an Array----------------\n";
   string subject[4] = {"Tamil", "English", "Maths", "Science"};
  for(int i = 0; i < 4; i++)
  {
    cout << subject[i] << "\n";
  }
 
  cout <<"\n----------------Add Element----------------\n";
  string district[5] = {"Coimbatore", "Chennai", "Erode"};
  district[3] = "Bangalore";
  district[4] = "Madurai";
  for(int i = 0; i < 5; i++)
  {
  cout << district[i] << "\n";
  }
 
  cout <<"\n----------------Omit Elements on Declaration----------------\n";
  string Phone[5];
  Phone[0] = "Vivo";
  Phone[1] = "Samsung";
  Phone[2] = "Iphone";
  Phone[3] = "Lava";
  Phone[4] = "Nokia";
  for(int i = 0; i < 5; i++)
  {
    cout << Phone[i] << "\n";
  }
  return 0;
}




  • Output :


No comments:

Post a Comment

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...