Posted 23/10/2005, 09:29
pode me ajudar
Olá
Bom dia
Tenho esses quatro popgramas, e preciso passa-los para pascal.
Se conhece as duas linguagens ajude me por favor.
Mande para alan.santana@gmail.com ou
alan_santana@terra.com.br
Obrigado
programa_01
#include <stdio.h>
/* So definindo os limites da tabela.em pascal acho que é com CONST */
#define LINHA 3
#define COLUNA 3
void LeMatriz(int MAT[][COLUNA])
{ int i,j;
for(i=0;i<LINHA;i++)
for (j=0;j<COLUNA;j++)
scanf("%d",&MAT[i][j]);
}
int SomaLinha(int MAT[][COLUNA],int ATUAL_COLUNA,int LINHA_ATUAL)
{ if(ATUAL_COLUNA>=COLUNA)
return 0;
else
return SomaLinha(MAT,ATUAL_COLUNA+1,LINHA_ATUAL)+MAT[LINHA_ATUAL][ATUAL_COLUNA];
}
int SomaTudo(int MAT[][COLUNA],int LINHA_ATUAL,int COLUNA_ATUAL)
{ if(LINHA_ATUAL>=LINHA)
return 0;
else
return SomaLinha(MAT,COLUNA_ATUAL,LINHA_ATUAL)+SomaTudo(MAT,LINHA_ATUAL+1,COLUNA_ATUAL);
}
main()
{
int MAT[LINHA][COLUNA]={0};
int i;
LeMatriz(MAT);
printf ("\n%d\n",SomaTudo(MAT,0,0));
}
____________________________________________________________________
programa_02
#include <stdio.h>
#include <stdlib.h>
#define VEZES 5
struct NODO{
int DADO;
struct NODO *PROX;
} typedef Elemento;
void InsereFinal(Elemento *INICIO,Elemento *NO)
{
if (INICIO->PROX==NULL)
{ INICIO->PROX=NO;
return;
}
else
InsereFinal(INICIO->PROX,NO);
}
void InsereNaPosicao(Elemento *INICIO,Elemento *NO,int CONTADOR,int POS)
{
if (CONTADOR==POS-1)
{ NO->PROX=INICIO->PROX;
INICIO->PROX=NO;
return;
}
else
InsereNaPosicao(INICIO->PROX,NO,CONTADOR+1,POS);
}
/* Só pra ver como tá a bagunça */
void ImprimeLista(Elemento *INICIO)
{
if (INICIO==NULL)
return;
else
{ printf (" %d ",INICIO->DADO);
ImprimeLista(INICIO->PROX);
}
}
main()
{
Elemento *HEAD=malloc(sizeof(Elemento));
Elemento *TEMP;
int QTDE=0;
int X=1;
int POS;
HEAD->PROX=NULL;
while (X<=VEZES)
{ TEMP=malloc(1*sizeof(Elemento));
TEMP->PROX=NULL;
printf ("\nInserir elemento:");
scanf("%d",&(*TEMP).DADO);
printf("\nPosicao:");
scanf("%d",&POS);
if (POS>QTDE)
{ if (QTDE==0)
InsereFinal(HEAD,TEMP);
else
InsereFinal(HEAD->PROX,TEMP);
}
else if (POS>0)
InsereNaPosicao(HEAD,TEMP,0,POS);
else printf ("digite uma posicao maior que zero");
QTDE++;
X++;
ImprimeLista(HEAD->PROX);
}
else
{ printf (" %d ",INICIO->DADO);
ImprimeLista(INICIO->PROX);
}
}
main()
{
Elemento *HEAD=malloc(sizeof(Elemento));
Elemento *TEMP;
int QTDE=0;
int X=1;
int POS;
HEAD->PROX=NULL;
while (X<=VEZES)
{ TEMP=malloc(1*sizeof(Elemento));
TEMP->PROX=NULL;
printf ("\nInserir elemento:");
scanf("%d",&(*TEMP).DADO);
printf("\nPosicao:");
scanf("%d",&POS);
if (POS>QTDE)
{ if (QTDE==0)
InsereFinal(HEAD,TEMP);
else
InsereFinal(HEAD->PROX,TEMP);
}
else if (POS>0)
InsereNaPosicao(HEAD,TEMP,0,POS);
else printf ("digite uma posicao maior que zero");
QTDE++;
X++;
ImprimeLista(HEAD->PROX);
}
free(HEAD);
}
____________________________________________________________________
programa_03
#include <stdio.h>
#include <stdlib.h>
struct NODO
{ int DADO;
struct NODO *PROX;
} typedef Elemento;
void TelaOpcao()
{ printf ("\n1-Inserir Numero");
printf ("\n2-Sair\n");
}
void InsereLista(Elemento *INICIO,Elemento *NO)
{
if (INICIO->PROX==NULL)
{ NO->PROX=INICIO->PROX;
INICIO->PROX=NO;
return;
}
else
InsereLista(INICIO->PROX,NO);
}
void ImprimeLista(Elemento *INICIO,int QTDE)
{
if (INICIO==NULL)
printf ("\nLista vazia\n");
else
{ while (INICIO!=NULL)
{ printf (" %d ",INICIO->DADO);
INICIO=INICIO->PROX;
}
printf ("\nElementos na lista:%d\n",QTDE);
}
}
void PrimeiraOpcao(Elemento *INICIO,int *QTDE)
{
int NUM;
Elemento *TMP=malloc(sizeof(Elemento));
printf("\nNúmero (digite -1 para imprimir a lista)");
scanf("%d",&NUM);
if(NUM!=-1)
{ TMP->DADO=NUM;
InsereLista(INICIO,TMP);
(*QTDE)++;
}
else
ImprimeLista(INICIO->PROX,(*QTDE));
}
void SegundaOpcao(Elemento *HEAD)
{ free(HEAD); }
main()
{
int OPCAO,QTDE=0;
Elemento *HEAD=malloc(sizeof(Elemento));
do
{
TelaOpcao();
scanf("%d",&OPCAO);
switch(OPCAO) {
case 1:
PrimeiraOpcao(HEAD,&QTDE);
break;
case 2:
SegundaOpcao(HEAD);
break;
default: printf ("\nNao existe essa opcao");
}
}while (OPCAO && OPCAO!=2);
}
____________________________________________________________________
programa_04
#include <stdio.h>
#include <stdlib.h>
#define VEZES 10
struct NODO
{ int NUM;
struct NODO *PROX;
} typedef Elemento;
void Opcoes()
{ printf ("\n1-Inserir Numero\n2-Remover Numero\n");
printf ("\n3-No Final da Lista\n4-No inicio da lista\\n");
printf ("\n>>");
}
void LeituraNumero(Elemento *TMP)
{ printf ("\nDigite o numero a ser inserido:");
scanf("%d",&(*TMP).NUM);
}
void InsereNumero(Elemento *INICIO,Elemento *NO,int OP)
{ if (OP==4)
{ NO->PROX=INICIO->PROX;
INICIO->PROX=NO;
}
else if (OP==3)
{ if (INICIO->PROX!=NULL)
while (INICIO->PROX!=NULL)
INICIO=INICIO->PROX;
NO->PROX=NULL;
INICIO->PROX=NO;
}
}
void RemoveNumero(Elemento *INICIO,int OP)
{ Elemento *TMP;
if (OP==4)
{
TMP=INICIO->PROX;
INICIO->PROX=INICIO->PROX->PROX;
free(TMP);
}
else if (OP==3)
{ if (INICIO->PROX!=NULL)
{ while (INICIO->PROX->PROX!=NULL)
INICIO=INICIO->PROX;
free(INICIO->PROX);
INICIO->PROX=NULL;
}
}
}
void ImprimeLista(Elemento *NO)
{ while (NO!=NULL)
{ printf (" %d ",NO->NUM);
NO=NO->PROX;
}
}
main()
{
Elemento *HEAD=malloc(sizeof(Elemento));
Elemento *TMP;
int OP1,OP2,X=0;
while (X<VEZES)
{
Opcoes();
scanf("%d %d",&OP1,&OP2);
if (OP1==1)
{ TMP=malloc(sizeof(Elemento));
LeituraNumero(TMP);
InsereNumero(HEAD,TMP,OP2);
}
else if (OP1==2 && HEAD->PROX!=NULL)
RemoveNumero(HEAD,OP2);
ImprimeLista(HEAD->PROX);
X++;
}
free(HEAD);
}