Created
November 10, 2021 01:52
-
-
Save Sanokei/1d2fe68d628246319293ce2161a8019b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
//Write a program that stores 10 random single digit numbers, then print the sum of all gaps in these numbers. A gap is the difference between two adjacent numbers that being generated. | |
int main(){ | |
int a[10]; | |
int sum = 0; | |
for(int i = 0; i < 10; i++){ | |
a[i] = rand() % 10; | |
cout << a[i] << " "; | |
} | |
for(int i = 0; i < 9; i++){ | |
sum += a[i+1] - a[i]; | |
} | |
cout << endl << "The sum of the gaps is: " << sum; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment