Skip to content

Instantly share code, notes, and snippets.

@Sanokei
Created November 10, 2021 01:52
Show Gist options
  • Save Sanokei/1d2fe68d628246319293ce2161a8019b to your computer and use it in GitHub Desktop.
Save Sanokei/1d2fe68d628246319293ce2161a8019b to your computer and use it in GitHub Desktop.
#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