Code: int a[6]={1,3,5,8,10,12}; int b[3]={3,5,9}; int c[6]={0}; if a is equal to ANY of the data in b, then c= a*2 if a isn't equal to any of the data in b, then c=a.
Here is the answer I want
Code: c[6]={1,6,10,8,10,12}
I tried using two for loop, but it isn't correct.....
Code: int a[6]={1,3,5,8,10,12}; int b[3]={3,5,9}; int c[6]={0};
So I'm doing this problem where the user will input a number that will be factored until the number is 1, 2 people will play this game and they will take turns entering a number that the initial number(named gameN) will be divided by until it is 1. Whoever get it to 1 wins. My problem is I'm not really sure how to do this, I'm pretty new to programming so besides some if statements and a loop, the problem shouldn't require too much to write. Some rules for the game are, the number entered to factor the gameN cant be less than 2, and has to divide evenly into gameN, which I have signifies with modulus. Here is where I'm at so far.
#include <stdio.h> int main(){ int gameN; int p1f; int p2f; printf("What number should the game be played with?"); scanf("%d", &gameN);
Write a C-program that efficiently multiplies a number by a factor 2 to the power n. The number to multiply and n are variables, which get a value at the start of the program.
Clue: 1 shift to the left is the same as multiplying by 2. 2 shifts to the left are the same as multiplying by 4. 3 shifts to the left are the same as multiplying by 8
How can I calculate GCF of many numbers? I thought I could calculate two by two numbers, but it not seems to be a very effective idea. There is my function:
int gcf (unsigned int x, unsigned int y) { return (y == 0) ? x : gcf (y, x % y); }
i want to write a program which find the biggest prime factor of a number for example the biggest prime factor of six is three or the biggest prime factor of fifteen is five. What is my program bug
Code:
#include <stdio.h> // main functions #include <math.h> // for sqrt function int main() { int i, j, k, f; // F = Flag; printf("Enter K
I am trying to find the largest prime factor of a number. But when I am trying to determine if a number is a prime number in the function:
int is_prime(int number), I am unable to exit the loop.
Here is the code:
#include<iostream> using namespace std; int is_prime(int number) //the problem is in this function { int num = number; int factor=0; do{ num++; for(int i=1;i<(num+1);i++){
[code].....
So when the program runs, it first divides 20 by 2, to get 10, then divides 10 by 2 to get 5. Since, // condition 1 is not met, it passes 2 to the function int is_prime(int number). The function is able to return 3, but cannot exit the loop when num is 4.
I think the problem lies in the function: int is_prime(int number).
My assignment is to create a simple stock broker program that ask the user how much they are willing to invest and ask what company they would like to invest in. Finally it outputs how many shares the user will have based on their investment amount. My code is below. My professor said to declare symbolic constants and factor out the if else statements. Ive been struggling trying to understand constant variables. How do I use const variables to factor out the if else statements?
I need codes for a program in C or C++ that will show the real factor (the smallest one, without the number 1) when an integer is given as input.
When the program is started, it will ask to enter a number and press enter. After entering a number, it will first check if it is a prime number or not. If prime, it will notice that it is a prime number, otherwise, it will print the smallest real factor of the given integer.
For example, if 12 is entered, it will print, the smallest real factor for this number is: 2
If 27 is entered, it will print, the smallest real factor for this number is: 3
I am trying to read an array values from Tmin.txt file. I take array size from user viz. number of raw & column and then, read the following data from Tmin.txt file which look like this:
I serialize a XML file, and i have this values here:
public class ServiceConfig { public List<DatabaseDescriptor> Databases { get; set; } } public class DatabaseDescriptor { [XmlElement("Name")]
[Code] ....
I have a form1 which is a datagrid view and get's updated like this:
dataGridView1.DataSource = xmlData.Databases;
Now i have a button: get tables, and it opens up form 2, there it's supposed to appear all the tables of the selected Database, when i click on the row i get the database name so i get all the list of Tables from
DatabaseDescriptor where DatabaseDescriptor.Name == name (I get this when i select the row)
But then on the 2nd form, i also have 2 textbox so i add a new table, i add the tablename and id. the new value should appear in the datagridview of the tables, and when i close it and reopen it, it should be there. Maybe i should concatenate first the values or something, how do i do?
I am trying to set the width of the data values which the user will input when using the program but I don't know how to get it to show the values when I tryto set the width of the variables in a nice column .
I have a problem I am working on where I need to sort some data based on the values of a string of bits. The strings look like this,
010000001110000000
there are 18 bits, 1 means a feature is present, 0 means the feature is absent.
Each of these string has 4 on bits. I need to sort them such that I have the longest possible runs with 3 of the same on bits. It doesn't matter which 3 bits are on, I am just looking to order them in blocks with the longest possible runs. As a second step, the ordered blocks will be sorted by size large>small.
The following data is ordered like I need it to be.
Code: // block 1, run of 12, keys 1,2,11 are identical (key 12 is also identical) 011000000001100000 011000000001100000 011000000001100000 011000000001100000
[Code] .....
This is the sort order that I am looking for. I need to be able to take a list of the bit strings in any particular order and sort them into the order above. The algorithm would need to recognize that there are 4 on keys and then look for groupings of three common on keys.
This is more of an algorithm question than one about specific implementation in code. I generally assume that most programming problems have been solved one way or another, so I don't know much about analyzing and manipulating strings of bits.
Is there a standard method for this kind of pattern recognition?
Ok I'm trying to create matrix of data that I can add values to based on a reading that I will get from a DVM. I'm using a 3d vector to do this. I need to keep track of the serial number, the day and within day I need to take two readings at different temps, this will continue for 7 days.
The rows of my 3d vector will be the days, the colums will be the serial numbers the depth will be the reading at the different temps.
What I need to do is compare the first element (days) and when it is greater then or equal to 4 I will perform calculations of the readings. So all I want to do is compare the first element of the vector, How do I do this?
and get an Iterator to the beginning of the match by
matches->at(i)->begin()
How can I get the relative position of the match within the entire target string (i.e. "Unseen University", where, in this case, the positions should be 0 and 7)??
I am using the (fairly) new STL implementation, which I just became aware of, of regexes. Seems to be an implementation of boost::regex Anyway, I have code, which I would like to use to get ALL matches within a string.
I have a variable named Authors. Sometimes I will insert one author into the database, sometimes more than one author will be inserted into the database.
The page that performs the update is a .cs page. Here is the layout:
using System; using System.Collections.Generic; using System.Configuration; using System.Data.SqlClient;
[Code]....
This definitely works for updating one author's name:
if (old.Author != Author) RequestItem.UpdateField(LibraryDocID, Editor, "Author", Author);
I just can not nail down how to insert a string of author's names.
I am writing a program to display values from a data file as an image. But I can only get a blue screen. Here is a small program resembling my code. what I have missed? I only changed OnDraw function.
This program is supposed to compare 2 strings and print out a 1 if the characters match and a 0 if they dont. It compiles but doesnt give me the correct output.
Code: #include <stdio.h> #include <string.h> void func(); int main () { func(); return 0;