
C/C++
помогите ччто бы рандом числа вводились\
C++ ПОМОГИТЕ ПЛИИЗ

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
unsigned n,count=0;
do
{
printf("n = ");
scanf("%u",&n);
}while(!n);
int * A = (int*) malloc(n * sizeof(unsigned));
srand(time(NULL));
rand();
for(unsigned x = 0; x < n; x++)
{
A[x] = rand() % 16;
printf("%u ",A[x]);
if(x > 1)
{
if(A[x-1] > A[x-2] && A[x-1] > A[x]) count++;
}
}
printf("\n\n%u\n",count);
if(A == (int*) NULL) exit(1);
free(A);
A = (int*) NULL;
return 0;
}
#include <time.h>
#include <stdlib.h>
int main()
{
unsigned n,count=0;
do
{
printf("n = ");
scanf("%u",&n);
}while(!n);
int * A = (int*) malloc(n * sizeof(unsigned));
srand(time(NULL));
rand();
for(unsigned x = 0; x < n; x++)
{
A[x] = rand() % 16;
printf("%u ",A[x]);
if(x > 1)
{
if(A[x-1] > A[x-2] && A[x-1] > A[x]) count++;
}
}
printf("\n\n%u\n",count);
if(A == (int*) NULL) exit(1);
free(A);
A = (int*) NULL;
return 0;
}
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <iostream>
using namespace std; int main()
{ int i, j = 0, n; cout << "n: "; cin >> n;
int *a = new int [n]; srand(time(nullptr));
for (i = 0; i < n; i++) { j++; a[i] = rand() % 1000;
cout << setw(4) << a[i]; if (j == 10) { j = 0;
cout << endl; } } if (j) cout << endl; j = 0;
for (i = 1; i < n - 1; i++)
if (a[i] > a[i - 1] && a[i] > a[i + 1]) { j++;
cout << setw(4) << j << ") " << setw(4)
<< a[i - 1] << setw(4) << a[i] << setw(4)
<< a[i + 1] << " (№" << i + 1 << ')' << endl; }
delete [] a; cin.get(); cin.get(); }

#include <cstdlib>
#include <iomanip>
#include <iostream>
using namespace std; int main()
{ int i, j = 0, n; cout << "n: "; cin >> n;
int *a = new int [n]; srand(time(nullptr));
for (i = 0; i < n; i++) { j++; a[i] = rand() % 1000;
cout << setw(4) << a[i]; if (j == 10) { j = 0;
cout << endl; } } if (j) cout << endl; j = 0;
for (i = 1; i < n - 1; i++)
if (a[i] > a[i - 1] && a[i] > a[i + 1]) { j++;
cout << setw(4) << j << ") " << setw(4)
<< a[i - 1] << setw(4) << a[i] << setw(4)
<< a[i + 1] << " (№" << i + 1 << ')' << endl; }
delete [] a; cin.get(); cin.get(); }

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
const int N=12;
int A[N],i,c,j,iMax,max, min, n, a,iMin;
printf ("Введите элементы массива:\n");
for (i=0; i<N; i++)
{
printf ("A[%d]=", i);
scanf ("%d", &A[i]);
}
printf("Исходный массив \n");
for( i=0; i < N; i++ )
printf("%4d", A[i]);
for (i = 0; i < N-1; i ++)
{
for (j = N-2; j >=i ; j --)
if ( A[j] > A[j+1] )
max = A[0];
iMax = 0;
for ( i=1; i < N; i++ )
if ( A[i] > max ) {
max = A[i];
iMax = i;
}
}
iMin=0;
for(i=0; i<N; i++)
if(A[i]<A[iMin])
{
iMin=i;
}
printf("\nВ массиве элементы находятся в интервале от %d, до %d ",A[iMin],A[iMax]);
getch();
}
примерный код
#include<conio.h>
#include<math.h>
main()
{
const int N=12;
int A[N],i,c,j,iMax,max, min, n, a,iMin;
printf ("Введите элементы массива:\n");
for (i=0; i<N; i++)
{
printf ("A[%d]=", i);
scanf ("%d", &A[i]);
}
printf("Исходный массив \n");
for( i=0; i < N; i++ )
printf("%4d", A[i]);
for (i = 0; i < N-1; i ++)
{
for (j = N-2; j >=i ; j --)
if ( A[j] > A[j+1] )
max = A[0];
iMax = 0;
for ( i=1; i < N; i++ )
if ( A[i] > max ) {
max = A[i];
iMax = i;
}
}
iMin=0;
for(i=0; i<N; i++)
if(A[i]<A[iMin])
{
iMin=i;
}
printf("\nВ массиве элементы находятся в интервале от %d, до %d ",A[iMin],A[iMax]);
getch();
}
примерный код
Похожие вопросы
- Программирование на C. Помогите бездарю
- Задача на c++ помогите решить без рандомного заполнения массива
- Читаю книжку по C, помогите с указателями
- C++ Помогите люди!
- C++ ПОМОГИТЕ ПОЖАЛУЙСТА
- Задача на C++, помогите решить.
- C++,помогите срочно!!! Ни как не могу понять как решить данную задачу
- Знающие C++, помогите пожалуйста:)
- Можно через delete [ ] ? c++ помогите пожалуйста!
- C++, помогите с классами