Answer:
Following are the code to this question:
#include <iostream>//defining header file
using namespace std;
int main()//defining main method
{
int x[]={2,3,4,6,7,8,9,1,11,12};//defining 1-D array and assign value
int i,sum=0;//defining integer variable
for(i=0;i<10;i++)//defining loop for count value
{
if(x[i]%2==1)//defining if block to check odd value
{
sum=sum+x[i];//add value in sum variable
}
}
cout<<sum;//print sum
return 0;
}
Output:
31
Explanation:
In the above-given program, an integer array "x" is declared that holds some integer values, and in the next line two integer variable "i and sum" is defined which is used to calculate the value.
In the next line, a for loop is declared, that counts all array value, and it uses the if block to check the odd value and add all the value into the sum variable.
Answer:
Street prices are affected by the extent of illegal commercial copying. The availability of inexpensive, high-quality illegal copies reduces the demand for legal copies to the extent that some users buy illegal copies instead of legal ones.
Answer:
li=list(map(str,input().strip().split()))#taking input of the string.
#swapping first and last element.
temp=li[0]
li[0]=li[-1]
li[-1]=temp
print(li)#printing the list.
Explanation:
I have taken the list li for taking the input of strings.Then after that swapping first and last element of the list.Then printing the list.
Answer:
Following are the code to this question:
#include <iostream> //defining header file
using namespace std;
void numbers(ostream &outs, const string& prefix, unsigned int levels); // method declaration
void numbers(ostream &outs, const string& prefix, unsigned int levels) //defining method number
{
string s; //defining string variable
if(levels == 0) //defining condition statement that check levels value is equal to 0
{
outs << prefix << endl; //use value
}
else //define else part
{
for(char c = '1'; c <= '9'; c++) //define loop that calls numbers method
{
s = prefix + c + '.'; // holding value in s variable
numbers(outs, s, levels-1); //call method numbers
}
}
}
int main() //defining main method
{
numbers(cout, "THERBLIG", 2); //call method numbers method that accepts value
return 0;
}
Output:
please find the attachment.
Explanation:
Program description:
- In the given program, a method number is declared, that accepts three arguments in its parameter that are "outs, prefix, levels", and all the variable uses the address operator to hold its value.
- Inside the method a conditional statement is used in which string variable s and a conditional statement is used, in if the block it checks level variable value is equal to 0. if it is false it will go to else block that uses the loop to call method.
- In the main method we call the number method and pass the value in its parameter.