Programação
Por: Luis Marcopolo • 17/8/2015 • Exam • 360 Palavras (2 Páginas) • 592 Visualizações
5a)
#include <stdlib.h>
#include <stdio.h>
int main ( )
{
int vetor[50], n=0;
while(n<=49){
vetor[n]= rand ( )%100;
printf("vetor[%d] = %d\n",n,vetor[n]);
n++;
}
system("pause");
return 0;
}
5b)
#include <stdlib.h>
#include <stdio.h>
int main ( )
{
int vetor[30], n=0;
while(n<=29){
vetor[n]= rand ( )%1000;
n++;
}
printf("vetor[1] = %d\n",vetor[1]);
printf("vetor[15] = %d\n",vetor[15]);
printf("vetor[29] = %d\n",vetor[29]);
system("pause");
return 0;
}
5c)
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <conio.h>
int main ( )
{
int vetor[100],x=0,y=0,p;
srand(time(NULL));
while(x<=99){
vetor[x]=rand( )%1000;
printf("\tvetor[%d] = %d\n",x,vetor[x]);
if(vetor[x]>y){
y = vetor[x];
p = x;
}
x++;
}
printf("\n\n\tvetor[%d] = %d\n\n",p,vetor[p]);
system("pause");
return 0;
}
5d)
#include <stdlib.h>
#include <stdio.h>
int main ( )
{
int vetor[10], n=0;
while(n<=9){
vetor[n]= n*2;
printf("vetor[%d] = %d\n",n,vetor[n]);
n++;
}
system("pause");
return 0;
}
5e)
#include <stdlib.h>
#include <stdio.h>
int main ( )
{
int vetor[10], n=0,par;
while(n<=9){
vetor[n]= rand ( )%100;
par = vetor[n] % 2;
if(par == 0){
printf("vetor[%d] = %d\n",n,vetor[n]);
}
n++;
}
system("pause");
return 0;
}
5f)
#include <stdlib.h>
#include <stdio.h>
int main ( )
{
int vetorA[5], vetorB[5], vetorC[10], x = 0;
printf("Entre com 5 valores para o vetor A:\n");
while(x <= 4){
scanf("%d",&vetorA[x]);
vetorC[x] = vetorA[x];
x++;
}
x=0;
printf("Entre com 5 valores para o vetor B:\n");
while(x <= 4){
scanf("%d",&vetorB[x]);
vetorC[x+5] = vetorB[x];
x++;
}
x=0;
printf("vetor C = { ");
while(x<=9){
printf(", %d ",vetorC[x]);
x++;
}
printf("}\n");
system("pause");
return 0;
}
5g)
#include <stdlib.h>
#include <stdio.h>
int main ( )
{
int vetorA[5], vetorB[8], vetorC[5], x, y,p=0;
printf("Entre com 5 valores para o vetor A:\n");
while(x <= 4){
scanf("%d",&vetorA[x]);
...