Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How can i print all complete square numbers available in the array
this is my array:
int main()
{
int array[6];
cout<<"Enter 6 #'s: "<<endl;
for(int i=0; i<6; i++) {
cin>>array[i];
}
Here's the algorithm:
For each slot in the array do:
if value in the slot is complete square number, print it.
The difficult part is determining a perfect square.
Hint: use sqrt (square root) function.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to make it, so lets say i type in 654321, it would say that i typed in 6 numbers.
I need to make it so it counts how many numbers i have typed in, and would display so.
Looking for anyone who could do that for me, thanks in advance.
Considering your entered number is an integer, you can setup a counter variable to count the number of digits and then divide the number by 10 and subsequently increment count in a loop:
#include <iostream>
int main()
{
long long num;
int count = 0;
std::cin>> num;
do
{ count++;
num /= 10;
} while(num != 0);
std::cout<< count;
}
Use long long for large input.
If your entered number is a string, then you can use stoi() to convert it into an integer.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have around 500 signals with the naming pattern
"Dem_AllEventsStatusByte._101"
"Dem_AllEventsStatusByte._102"
"Dem_AllEventsStatusByte._103"
...
"Dem_AllEventsStatusByte._490"
I want to loop over all of them.
I tried the following code but when i=10 then my signal name is like " Dem_AllEventsStatusByte._1010" which is false it should be 110 at the end.
for (i=1; i<=3;i++)
{
SPrint(signal, "Dem_AllEventsStatusByte._10%d", i);
How to loop over 490 signals of same name pattern? please help! Thank you
You probably want something this:
for (i = 1; i <= 490 - 100; i++)
{
SPrint(signal, "Dem_AllEventsStatusByte._%d", i + 100);
or maybe this:
for (i = 101; i <= 490; i++)
{
SPrint(signal, "Dem_AllEventsStatusByte._%d", i);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Here is the code, I know what does it do , but I don't understand, what does the if condition do?
if(n&1)
{
for(i=n/2,j=n/2+1;;i--,j++)
if(__gcd(i,j)==1)
{
cout<<i<<" "<<j<<endl;
break;
}
}
else
{
for(i=n/2-1,j=n/2+1;;i--,j++)
if(__gcd(i,j)==1)
{
cout<<i<<" "<<j<<endl;
break;
}
}
return 0;
}
Its a bitwise operator. There's a search term for you!
The & operator provides a mask that "cancels out" bits in the first depending if they're set in the second parameter - so assume N is the number 17, that expressed in binary is 00010001, the number 1 in binary is 00000001, so masking the two together will "blank" the first set of bits, leaving you with N as 00000001.
Basically that particular if statement drops all except the last bit, which is either 0 or 1, so it is a condition detecting if N is odd or even.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a problem to read a large int ( 1 to 10^100 ) into vector the problem is I cannot read it as numeric data-type and split it into the vector so I want a solution to read the number separately into the vector
Example:
45686469
vec[0] = 4
vec[1] = 5
...
vec[7] = 9
Here's one possible way to do it:
std::string yourinput;
cin>>yourinput; //capture your large number as a string
std::vector<char> vch;
for(size_t st=0;st<yourinput.length();++st)
{
vch.push_back(yourinput[st]); //move each character into the vector
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Increment a alpha numerical string "abcd1234" upto "abcd2000"
output:
abcd1234
abcd1235
.
.
.
abcd2000
Simply:
for (int a = 1234; a <= 2000; ++a)
{
std::cout << "abcd" << a;
}
In C,
for (int i=1234; i<= 2000;i++)
printf("abcd%d\n",i);