C++ Questions Answers-C++ Array(PartII)


C++ Array(PartII)

1. What would be printed from the following C++ program?
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
  int arr[5]={1,3,5,7,9}; //initialize arr array
  int i;
  for(i=0;i<5;i++) //output arr array
       cout<<arr[i]*arr[i]<<"\t";
  getch();
  return 0;
}
Check answer 2. What would be printed from the following C++ program?
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
  int arr[5]={1,3,5,7,9}; //initialize arr array
  int i;
  for(i=4;i>=0;i--) //output arr array
       cout<<arr[i]<<"\t";
  getch();
  return 0;
}
Check answer 3.What would be printed from the following C++ program?
#include<iostream>
#include<conio.h>
using namespace std;

int main(){
  int list1[5]={1,3,5,7,9}; //initialize list1 array
  int list2[5];
  int i;
  for(i=0;i<5;i++)
      list2[i]=list1[i]+1; //assign values to list2
  for(i=0;i<5;i++) //output list2
      cout<<list2[i]<<"\t";
  getch();
  return 0;

}
 Check answer 4. What would be printed from the following C++ program?
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
   int list[10]={1,2,3,4,5,6,7,8,9,10}; //initialize list array
   int i;
   for(i=0;i<5;i++)
   { //switching elements
      int temp=list[i];
      list[i]=list[9-i];
      list[9-i]=temp;
   }
   for(i=0;i<10;i++) //output list
       cout<<list[i]<<"\t";
   getch();
   return 0;

} Check answer


Comments

Aashir Abbas comment

 Aashir Abbas

#include<iostream.h>
#include<conio.h>
main()
{
int arr[5][5];
int sum=0;
for(int k=0;k<5;k++)
for(int l=0;l<5;l++)
cin>>a[k][l]; //to get values in array

//sum of odd numbers
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
if(a[i][j]%2!=0)
sum=sum+a[i][j];
cout<<sum;


}


2018-01-14
Aashir Abbas comment

 Aashir Abbas

#include<iostream.h>
#include<conio.h>
main()
{
int arr[5][5];
int sum=0;
for(int k=0;k<5;k++)
for(int l=0;l<5;l++)
cin>>a[k][l]; //to get values in array

//sum of odd numbers
for(int i=0;i<10;i++){
for(int j=0;j<10;j++)
if(a[i][j]%2!=0){
sum=sum+a[i][j];
cout<<sum;
}
}
}


2018-01-14
Nashqua shamsher comment

 Nashqua shamsher

#include<iostream.h>
#include<conio.h>
Void main()
{
int a[4][4],s=0,i,j
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
Cout<<"enter a no.";
Cin>>a[i][j];
if(a[i][j]%2!=0)
s+=a[i][j];
}
Cout<<"sum="<<s;
getch();
}



2017-12-15
ibraahin comment

 ibraahin

I do no , can u tell me step by step




2017-01-11
KLD comment

 KLD

Write a c++ program to find the sum of odd numbers in 2D-array.


2016-12-05



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.