Target
-------------------------------
Answer:
185 = 1011 1001
252 = 1111 1100
Explanation:
If you add the decimal values corresponding to the bit positions that are 1, you get your decimal number.
Answer:
- def longest(L):
- for x in L:
- if(len(x) % 2 == 0):
- if(x.endswith("ing")):
- return x
- return ""
-
- print(longest(["Playing", "Gaming", "Studying"]))
Explanation:
The solution is written in Python 3.
Firstly, create a function longest that takes one parameter L as required by question (Line 1).
In the function, create a for loop to traverse through each string in L and check if the current string length is even (Line 2 - 3). If so, use string endwiths method to check is the current string ended with "ing". If so return the string (Line 4-5).
At last, test the function by passing a list of string and we shall get the output "Gaming".
Answer:
#include <iostream>
using namespace std;
int main()
{
const int LENGTH = 9;
char sample1[LENGTH];
char sample2[LENGTH];
cout << "Enter 9 characters to be converted to uppercase: ";
for(int i = 0; i < LENGTH; i++){
cin >> sample1[i];
sample1[i] = toupper(sample1[i]);
cout << sample1[i];
}
cout << endl;
cout << "Enter 9 characters to be converted to lowercase: ";
for(int i = 0; i < LENGTH; i++){
cin >> sample2[i];
sample2[i] = tolower(sample2[i]);
cout << sample2[i] ;
}
return 0;
}
Explanation:
- Declare the variables
- Ask the user for the characters
- Using for loop, convert these characters into uppercase and print them
- Ask the user for the characters
- Using for loop, convert these characters into lowercase and print them
I'm not sure but I think d. Webmaster