describe a time when you were responsible for organizing
different types of personnel to get work done and some of
them weren't very enthusiastic. what did you do?
5958
Hi
I have done my B.Sc computers and my query is that do i have
to compulsory write GRE or TOFEL to study in US. Please let
me whether I am eligibly for GRE or TOFEL with B.Sc
computers....
Regards Kamal
1782
Describe about 4G and Wimax.
1814
Hai I have one net cam.... I want to receive the captured
image to my mail id.. is it possible?.....plz give a better
solution.......
1573
describe atime when you felt it was necessary to change a
staffing pattern to better meet your unit's needs. how did
you handle the sutuation?
1622
end a movie clip using script in flash 5
1919
My question is. How many types of REGISTER? and define its all
types of REGISTER? plzzz
1843
Project 2 - Magic Squares
design2.txt - due 12/7 before 11:59 PM
project2 - due 12/13, before 11:59 PM
Orginally by Sue Evans
Hit the space bar for next page
The Objectives
The purpose of this assignment is to give you practice with:
recursion
using command line arguments
using the timing feature
and file handling.
The Background
According to The Math Forum @ Drexel University, A Magic
Square is an arrangement of the numbers 1 to n2 in an n x n
matrix with each number occuring exactly once, and such that
the sum of the entries of any row, any column, or any main
diagonal is the same. It is not hard to show that this sum
is n(n2 + 1)/2.
The simplest magic square is the 1 x 1 magic square whose
only entry is the number 1.
1
The next simplest is the 3 x 3 magic square.
(8 + 1 + 6) or 3(32 + 1)/2
This is also just ONE of many examples for a 3 x 3 Magic
Square!!
This 3 x 3 square is definitely magic and satisfies the
definition given above. There are 8 different arrangements
of entries in a 3 x 3 matrix that fit the definition of a
magic square. There are also magic squares of size 4 x 4, 5
x 5, etc.
The Background - Continued
For small n, say n <= 3, you could obviously sit down with
pencil and paper and discover a magic square in a fairly
short amount of time.
Take a few minutes now and do that, remembering that each of
the numbers, 1 through n2, appear only once in the square.
Now try it for n = 4 ...
Oh, there has to be a better way. :)
Of course, the computer doesn't have a patience problem. It
can solve the problem for us by using the brute force
method. This means that the computer will accomplish its
task by trying every single possible arrangement of the
numbers in a square and check each of the resulting squares
to see if it's a magic square.
[6, 2, 7, 5, 4, 8, 3, 9, 1]
[4, 2, 7, 6, 5, 8, 3, 9, 1]
[7, 4, 2, 6, 5, 8, 3, 9, 1]
...
The Task
Your assignment will be to determine all of the magic
squares when given an n, display permutations that match the
magic squares to the screen AND write it to a file.
You will only test when n == 3!!! But code it for n of ANY
number!!
It turns out that finding the magic squares for n >= 4 takes
too long for us to run it on the shared machines (linux1, 2
& 3)
Since if n == 1, the square is 1 (too easy!!)
and since for n == 2 there is no answer!!
Your program must come up with every possible arrangement
(permutation) of numbers within the square. These are known
as the permutations of that list of numbers. Each
permutation needs to be checked to see if it has formed a
magic square.
Program Requirements
Your program must:
use command line arguments. At the command line the user
must enter (in this order):
the name of the executable file,
n (which will ALWAYS be 3, but again could be run with other
numbers)
and the name of the output file in which to write the
squares.
use a recursive permute to give all of the permutations of
the square.
In other words, your function called "permute", must be a
recursive function.
So for each permutation, you should check to see if it is a
magic square, display it and write it to the file
write only the unique magic squares to the SCREEN and FILE.
No duplicates allowed.
HINT: Let your program produce duplicates first, then see
how you can refrain from writing the duplicates.
Then modify your code.
use a list of size n2.
The code for the recursive permute function will be much
easier to write if you store the numbers in a list
rather than a two-dimensional list (or array) of size n x n.
How you print the data is not related.
[6, 2, 7, 5, 4, 8, 3, 9, 1, ....] (size to n2)
[4, 2, 7, 6, 5, 8, 3, 9, 1, ....]
[7, 4, 2, 6, 5, 8, 3, 9, 1, ....]
...
close any files that you have opened as soon as you have
finished using them.
Time how long your program takes to find the magic square
and print that time at the end of the SAME file.
Sample Run
Here is a sample of output of this program. Please note that
the sample output only shows what is expected from your
program if the user is actually entering everything as
instructed. This is not a test of the program at all, but
just a sample for your clarification.
2 7 6
9 5 1
4 3 8
2 9 4
7 5 3
6 1 8
4 3 8
9 5 1
2 7 6
4 9 2
3 5 7
8 1 6
6 1 8
7 5 3
2 9 4
6 7 2
1 5 9
8 3 4
8 1 6
3 5 7
4 9 2
8 3 4
1 5 9
6 7 2
Total running time: 4.76 seconds.
2664
1.2million lux hours means
772
how many days can i store 7N sulfuric acid(H2S04)??
1092
Programming in C
JayLQue@hotmail.com
1. Which of the types listed below can be the type of the
result value returned by a user-defined function?
A) int
B) double
C) char
D) all of the above
E) none of the above
2. What is the output from this program?
#include
void do_something(int *thisp, int that)
{
int the_other;
the_other = 5;
that = 2 + the_other;
*thisp = the_other * that;
}
int main(void)
{
int first, second;
first = 1;
second = 2;
do_something(&second, first);
printf("%4d%4d\n", first, second);
return 0;
}
A) 35 2
B) 1 35
C) 35 7
D) 1 2
E) 0
3. In function apart defined below, how many of the
parameters are considered input parameters?
void apart(double x, int *wholep, double *fracp)
{
*wholep = (int)x; *fracp = x - *wholep;
}
A) 0
B) 1
C) 2
D) 3
E) all
4. Variables that represent neither problem inputs nor
problem outputs but are needed for internal computations
are called _____.
A) problem constants
B) prototypes
C) results
D) formula variables
E) program variables
5. This question concerns the following program fragment:
char r, x, y, z, w;
scanf("%c%c%c%c", &x, &y, &z, &w);
if (x < y)
r=x;
else
r=y;
if (r>z)
r=z;
if (r>w)
r=w;
printf("%c\n", r);
The program's effect can best be described as:
A) It displays the letter 'r' after comparing it to x, y,
and z.
B) Of the four input characters, it displays the one that
comes first in the alphabet.
C) Of the four input characters, it displays the one that
comes last in the alphabet.
D) Of the four input characters, it displays the one that
comes second in the alphabet.
E) It displays nothing since characters cannot be compared.
6. In a function that receives a value from the main
function via a parameter and then displays the parameter
value on the screen, that parameter is considered
__________.
A) an input parameter
B) an output parameter
C) an input/output parameter
D) a local variable
E) a stub
7. What is the complement of the following expression?
n||a <= b && c != 100
A) !n || a > b || c == 100
B) !(n && (a > b || c == 100))
C) !n && (a > b || c == 100)
D) !(n || (a > b || c == 100))
E) none of the above
8. The if statement:
if (13 < 12)
printf("never\n");
else
printf("always\n");
A) displays never.
B) displays always.
C) will not compile since 13 is not less than 12.
D) causes a run-time error since 13 is not less than 12.
E) displays nothing since 13 is not less that 12.
9. How many lines of output will be displayed by the
following program fragment?
i=0;
do
{
for (j = 0; j < 4; j = j + 1)
printf("%d\n", i + j);
i=i + 1;
}
while (i < 5);
A) 0
B) 7
C) 9
D) 16
E) 20
10. For what exact range of values of variable x does the
following code segment display the letter 'C'?
if (x <= 200)
if (x < 100)
if (x <= 0)
printf("A\n");
else
printf("B\n");
else
printf("C\n");
else
printf("D\n");
A) 0 < x < 100
B) x <= 0
C) 100 <= x <= 200
D) x > 200
E) 100 < x <= 200
11. The effect of the following program segment can best be
described as __________.
if (x > y)
z = x;
if (x == y)
z=0;
if (x < y)
z = y;
A) the smaller of x and y is stored in z.
B) the larger of x and y is stored in z.
C) the larger of x and y is stored in z unless x and y are
equal, in which case z is assigned zero.
D) the larger of x and y is stored in z unless x and y are
not equal, in which case z is assigned zero.
E) none of the above.
12. The expression: x *= i + j / y; is equivalent to
______.
A) x = x * i + j / y;
B) x = (x * i) + j / y;
C) x = (x * i + j) / y;
D) x = x * (i + j / y);
E) none of the above
13. The facts that a function assumes to be true of the
arguments that it receives are called __________.
A) function input validations
B) local variables
C) postconditions
D) preconditions
E) none of the above
14. How many times is the loop body of the while statement
executed? Refer to the following program segment. Assume
that all variables are of type int.
z=0;
g=0;
s=0;
i=0;
while (i < 50)
{
scanf("%d", &t);
s=s + t;
if (t >= 0)
g=g + 1;
else
z=z + 1;
i=i + 1;
}
A) once
B) never
C) 49 times
D) 50 times
E) until a number 50 or larger is entered
15. A special value that marks the end of a list of input
data is called a __________.
A) terminal value
B) sentinel value
C) loop control value
D) input value
E) loop termination value
16. Here is the prototype of a function:
void five (double x, double* yp, int* zp);
Given these variable declarations, which calls to five are
valid?
int m, n
double p, q
A) five(m, &p, &n);
B) q = five(6.2, &p, &m);
C) five(p, &q, &m);
D) five(7.1, &p, &q);
E) a and c only
F) a, b, c, and d
17. The ______ of a function take(s) information into the
function from the calling statement.
A) local variables
B) input arguments
C) output arguments
D) prototype
E) purpose
18. If the input to the program segment below is 85, what
is its output?
scanf("%d", &s);
if (s >= 90)
printf ("A\n");
else if (s >= 70)
printf ("C\n");
else if (s >= 80)
printf ("B\n");
else
printf ("D\n");
A) A
B) B
C) C
D) D
E) None of the above
19. The value stored in variable s at the end of the
execution of the loop could best be described as
__________. Refer to the following program segment. Assume
that all variables are of type int.
z=0;
g=0;
s=0;
i=0;
while (i < 50)
{
scanf("%d", &t);
s=s + t;
if (t >= 0)
g=g + 1;
else
z=z + 1;
i=i + 1;
}
A) the average of the numbers scanned
B) the sum of the numbers scanned
C) the largest of the numbers scanned
D) how many numbers were scanned
E) the sentinel value
20. What is displayed by the C statements that follow if
the value input is 2?
scanf ("%d", &ctl);
switch (ctl)
{
case 0:
case 1:
printf("red ");
case 2:
printf("blue ");
case 3:
printf("green ");
case 4: printf("yellow");
}
printf("\n");
A) red
B) blue
C) green
D) yellow
E) blue green yellow
21. What is displayed by the C statements below if the
value input is 3?
scanf ("%d", &n);
if (n = 5)
printf("Equal\n");
else if (n < 5)
printf("Less\n");
else
printf("Greater\n");
A) Equal
B) Less
C) Greater
D) No output
22. What will be the value of i after the C statements
below have been executed?
i=3;
j=10;
if ((3 * i) < j)
i=i + 2;
i=i+3;
A) 5
B) 6
C) 8
D) 10
E) 15
23. Which of the types listed below can be the type of a
function output parameter?
A) int*
B) double*
C) char*
D) all of the above
E) none of the above
24. Which one of the following lines names a constant
needed in a program that computes the price per square inch
of a round pizza?
A) scanf("%lf", &radius);
B) pi = 3.14159;
C) #define PI 3.14159
D) #include
E) none of the above
25. Which one of these is not the name of a C library
function?
A) printf
B) sqrt
C) void
D) scanf
E) log
3252
What is the purpose of measuring inductance in motor windings?
1961
what is multithreading
1640
If 2 is a prime no , then write a C program to test a number
is prime or not
1622
how many elements are common to living organisms?
1707