Answer:
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
for(int j=2;j<=n-1;j++) //loop to check prime..
{
if(n%j==0)
return false;
}
return true;
}
int main(){
int n;
cout<<"Enter the integer"<<endl;//taking input..
cin>>n;
if(isPrime(n))//printing the message.
{
cout<<"The number you have entered is prime"<<endl;
}
else
{
cout<<"The number is not prime"<<endl;
}
return 0;
}
Output:-
Enter the integer
13
The number you have entered is prime
Explanation:
The above written program is in C++.I have created a function called isPrime with an argument n.I have used a for loop to check if the number is prime or not.In the main function I have called the function isPrime for checking the number is prime or not.
Answer:
mystr = input("Enter a string ")
length = len(mystr)
while length<10:
mystr = input("Enter a string ")
length = len(mystr)
if(length>=10):
break
if len(mystr)%2==0:
print(mystr.lower())
else:
print(mystr.upper())
Explanation:
The variable mystr is used to save user's input which is received with the input function
A second variable length is used to save the length of the input string Using a while statement the user is continually prompted to enter a string while length is less than 10.
If length is greater or equal to 10. We check for even or odd using the modulo (%) operator.
We use lower() and upper() to change the case of the string
Answer:
Yes there is
Explanation:
It is scratch a coding game to do almost anything you can also code flappybird
Hope this helps.
Have fun with scratch
Answer:
It goes like:
public class Program
{
public static void main(String[] args)
{
int j=18;
int sum=0;
for (int i =1; i<7; i++)
{
sum=sum+(i*(j-2));
j=j-2;
}
System.out.println(sum);
}
}
Explanation:
<u>Variables used: </u>
j : controls the first number in product and decreases by 2 each time the loop runs.
sum: saves the values of addition as the loop runs.
Answer:
The value of myArray2[index2] when index1 = 12 is 30
Explanation:
In the source code, the formula for myArray2[index2] is;
myArray2[index2] = index2 + index3 + myArray1[index1],
myArray1[index1] = index1 * 2,
index2 = index % 10 (equal to the remainder) and
index3 = index % 8
When index1 increases to 12 in the for-loop statement, the "myArray1[index1]" is equal to 24, index2 is equal to 2 and index3 is 4. The total sum is equal to 30 and assigned to "myArray2[index2]".