May 2021 2 124 Report
¿como hacer el triangulo de pascal en c++?

que quede centrado y con printf y scanf sin utillizar cin y cut porfis :D

Actualización:

#include "stdafx.h"

#include <stdio.h>

#include <stdlib.h>

#include<conio.h>

int main(int argc, char *argv[])

{ int pasc[11];

int n;

int x, i, j;

x=0;

printf("ingrese la cantidad de lineas que quiere:");

scanf("%d",n);

//valida el numero de lineas

for (i=1; i<=n ; i++)

{

//Construimos el triangulo de pascal

for (j=x; j>=0; j--)

{

if(j==x || j==0)

{

pasc[j] = 1;

}

else

{

pasc[j] = pasc[j] + pasc[j-1];

}

}

x++;

printf("\n");

//Truco para imprimir el triangulo

for (j=1; j<=n-i; j++)

printf(" ");

for(j=0; j<x; j++)

{

printf("%3d ", pasc[j]);

}

}

getch();

}

me lo pueden explicar un poco no lo tengo muy claro porfas


Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments




Helpful Social

Copyright © 2024 Q2A.MX - All rights reserved.