Object
Write a program that prints the sum of two random numbers.
Algorithm
- Declare integer variables a, b and sum.
- a = rand()%8.
- b = rand()%9.
- sum = a + b.
- Write sum.
- Exit.
Flowchart

C++ Source Code
// program 72
#include<iostream>
using namespace std;
int main()
{
int a, b, sum;
a = rand() % 8; // in the range 0 to 7
b = rand() % 9; // in the range 0 to 8
sum = a + b;
cout << a << " + " << b << " = " << sum;
return 0;
}
C Source Code
/*program 72*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a, b, sum;
a = rand()%8;
b = rand()%9;
sum = a + b;
printf("%d + %d = %d", a, b, sum);
return 0;
}
Output
1 + 8 = 9
