Answer:
function countWords(sentence) {
return sentence.match(/\S+/g).length;
}
const sentence = 'This sentence has five words ';
console.log(`"${sentence}" has ${countWords(sentence)} words` );
Explanation:
Regular expressions are a powerful way to tackle this. One obvious cornercase is that multiple spaces could occur. The regex doesn't care.
Answer:
1)
n = int(input("Please enter the length of the sequence: "))
print("Please enter your sequence")
product = 1
for i in range(n):
val = int(input())
product *= val
print("The geometric mean is: %.4f"%pow(product,1/n))
2)
print("Please enter a non-empty sequence of positive integers, each one is in a separate line. End your sequence by typing done:")
product = 1
val = input()
n = 0
while(val!="done"):
product *= int(val)
n += 1
val = input()
print("The geometric mean is: %.4f"%pow(product,1/n))
Explanation:
Answer:
Explanation:
#include <stdio.h>
void main()
{
int j, sum = 0;
printf("The first 10 natural number is :\n");
for (j = 1; j <= 10; j++)
{
sum = sum + j;
printf("%d ",j);
}
printf("\nThe Sum is : %d\n", sum);
}
Answer:
Hope it helps you .............