Solved

# codes

Posted on 2007-10-11
138 Views
hey guys i'm having a problem on how to start this problem.. i basically just started taking this C class and having problems doing these codes. i appreciate the help

Write a program to do the following:
- obtain two random numbers from the rand() function
- place the random numbers in variables 'a' and 'b'
- set an integer variable 'bigger' so it is the highest value of 'a' and 'b'
- set an integer variable 'smaller' so it is the lowest value of 'a' and ''b'
- obtain values in integer 'c' by executing statements with each of the expressions listed below
- obtain values in float 'x' by executing statements with each of the expressions listed below
- for each expression: print on a new line text with the statement number and the value obtained
1. c = bigger/smaller
2. c = smaller/bigger
3. c = bigger%smaller
4. c = smaller%bigger
5. c = bigger++
6. c = -smaller++
7. c = bigger>smaller
8. c = ( smaller== 3 )
9. c = (( smaller + 3) && bigger )
10. x = bigger/smaller
11. x = smaller/bigger
12. x = (float) bigger/smaller
13. x = (float) (bigger/smaller)
14. x = (float)(smaller/bigger)
15. x = (float) bigger / (float)smaller
0
Question by:tsburt

LVL 24

Expert Comment

I posted to you other question. And as you know you should at least start yourself.  what can't be that hard to follow the instrctions?
a = random();
b = random();

What is that difficult about that:
Now how difficult can ot be to find the maximum of two numbers?

and what can be that difficult to write
c= bigger/smaller if you know what you had to write?

Friedrich
0

LVL 1

Author Comment

well just started not sure how to start....
i got this so far.

#include <stdlib.h>
#include<iostream.h>

int main(void);
{
a = rand();
b = rand();
if (a>b)

bigger = a; else bigger = b
bigger=b && smaller=a;
c = bigger/smallercout << c << endl;
c = smaller/biggercout << c << endl;
c = bigger%smallercout << c << endl;
c = smaller%biggercout << c << endl;
c = bigger++cout << c << endl;
c = -smaller++cout << c << endl;
c = bigger>smallercout << c << endl;
c = ( smaller== 3)cout << c << endl;
c = (( smaller + 3) && bigger )cout << c << endl;
x = bigger/smallercout << x << endl;
x = smaller/biggercout << x << endl;
x = (float) bigger/smallercout << x << endl;
x = (float) (bigger/smaller)cout << x << endl;
x = (float)(smaller/bigger)cout << x << endl;
x = (float) bigger / (float)smallercout << x << endl;

am i missing something ?
0

LVL 24

Accepted Solution

iostream.h is totally unkown to C you can use
#include <stdio.h>

or you can make up you mind whether you like to learn C or C++.

The formatting is really bad and the logic is wrong also.
if (a > b) {
bigger = a;
smaller = b;
} else {
bigger = b;
smaller = a;
}

the code below is just not C but I don't know what.

c = biggeer / smaller;
printf("bigget/smaller result = %d\n", c);

Yes you are missing quite a lot
Regards
Friedrich
0

## Featured Post

### Suggested Solutions

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.