Unit 1 Flashcards

(14 cards)

1
Q

How do you include a catalog ?

A

include <stdio.h></stdio.h>

#include <math.h></math.h>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do we define variables?

A

int x,y;
float x,y;

or

int x=3, y=9;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do we start our main set of functions ? and what does the “int” stand for.

A

int main() {

return 0;
}

“int” means that we will output an integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write a “for” statement that prints the sequence of 1 to 50

A

int i;

for (i=1; i<=50; i++)
printf(“%d\n”, i);

return 0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write a “for” statement that prints a sequence of 0 to 50 by intervals of 10

A

int i, count=0;

for(i=1; i<6; i++)
{
count = i*10;
printf(“%d\n”, count);
}

return 0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write a program that tells whether or not the number you entered is a multiple of 5

A

include <stdio.h></stdio.h>

#include <math.h></math.h>

int main () {

int x;
printf(“Enter a multiple of 5: “);
scanf(“%d”, &x);

if (x%5==0)
printf(“Yes”);
else printf(“NO”);

return 0;

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain these line of code if given a set of numbers:

for(i=0; i<=500; i++){
if (a[i]>150.0 && a[i]<200.0){
count ++;
}
}
printf(“%d\n”, count);

return 0;

A

line 1: this is a line to count i to 500 by intervals of 1

line 2: starting an if statement for the condition that a[] picks up a number between the values 150 & 200

line 3: the {} brakets define the condition; under this condition the variable count increases by and interval of 1 every time it crosses a number that meets the condition os line 2.

line 4 the brackets close out both the for and if statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

include <stdio.h></stdio.h>

How to ensure this code produces floats:

#include <stdlib.h></stdlib.h>

int main()
{
int i;

for (i=0; i < 10; i++) printf(“%d\n”, rand());

printf(“\nMAX = %d\n”, RAND_MAX);

return 0;
}

A

change the %d to %f then multipy the “rand” part by a floating 1: 1.0 x rand()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

include <stdio.h></stdio.h>

Explain what comes out and why

void func1(float x, float y)
{
x = -x + y;
y = y -1;
}

void func2(float *px, float *py)
{
*px = *py - *px;
*py = 2**px + *py - 1;

}

int main()
{
float x=2, y=3, z= 1;
int i;

func1(x, y);
func2(&x, &y);
func2(&y, &x);

printf(“%f\n”, y);
return 0;
}

A

-3 is the answer

we work with the func2’s since it is the last one mentioned and also one of the two functions out of the three that actually has the values addressed.

We can then do the math starting with the first equation:

Since its Func2(y, x) our y value will be put in place of x for the solution.

*px = 1 - 3 = -2

Now the second equation:

*py = 2(-2) + (2) -1
= -4 + 1

*py = -3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

include <stdio.h></stdio.h>

Explain the Output:

int main()
{
int i;
float x=1;
for (i=10;i<13;i++)
x = (x + 6/x)/2;
printf(“%f\n”, x);
return 0;
}

A

since there is a For Loop we know that it will run until the value of i is just before 13.

10,11,12 = 3 iterations.

we solve the equation 3 time adding the new value of x to each time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does *a *(a+i) mean

A

this is calling into the array a but based on the number being added

a[i]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

how to declare a pointer using p

A

pa

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how to declare a pointed directly onto a variable

A

&a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how to make a pointer spit our a variable ?

A

*pa
*&a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly