Answer the question
In order to leave comments, you need to log in
Why doesn't if in an array work as it should?
Task: Given two arrays of the same size, get the third array, each element of which is equal to the maximum of the elements with the same number in the given arrays? (sorry for the text in printf)
#include <stdio.h>
#include <conio.h>
#include <locale.h>
#include <stdlib.h>
#include <time.h>
main()
{
setlocale(LC_ALL,"RUS");
int a[100],b[100],c[100];
int i,n;
printf("Vvedite razmer massiva: ");
scanf("%d",&n);
while(n<=1 || n>100)
{
printf("\nError! Povtorite : ");
scanf("%d",&n);
}
for(i=0;i<n;i++)
{
a[i]=rand()%10;
b[i]=rand()%15;
}
printf("\n1-massiv:\n ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
printf("\n2-massiv:\n ");
for(i=0;i<n;i++)
{
printf("%d ",b[i]);
}
printf("\nmassiv is max :\n ");
for(i=0;i<n;i++)
{
if(a[i]=b[i])
{
c[i]=a[i];
}
else
{
if(a[i]>b[i])
{
c[i]=a[i];
}
else
{
c[i]=b[i];
}
}
}
for(i=0;i<n;i++)
{
printf("%d ",c[i]);
}
getch();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question