SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Soluciones de la dirigida 4
/* Este programa pide ingresar un entero positivo "n" mayor que 2
* y muestra todos los primos menores o iguales a "n" */
#include <stdio.h>
void rombo (int n);
void tri1 (int n);
void tri2 (int n);
void main (void)
{
int n;
printf("n Ingrese un entero mayor que 1: ");
scanf("%d",&n);
printf("n Rombo de diagonal %d:n", 2*n + 1);
rombo(n);
printf("n Triangulo de altura %d y ancho %d:n", 2*n - 1, n);
tri1(n);
printf("n Triangulo de altura %d y ancho %d:n", n, 2*n - 1);
tri2(n);
printf("n");
}
void rombo (int n)
{
int x, y;
for (y = -n; y <= n ; y++)
{
for (x = n; x >= -n; x--)
if ( (abs(x) + abs(y)) <= n ) printf("*");
else printf(" ");
printf("n");
}
}
void tri1 (int n)
{
int x, y;
for (y = 1; y < n ; y++)
{
for (x = 1; x <= y; x++)
printf("*");
printf("n");
}
for ( ; y > 0 ; y--)
{
for (x = 1; x <= y; x++)
printf("*");
printf("n");
}
}
void tri2 (int n)
{
int x, y;
for (y = n-1; y >= 0; y--)
{
for (x = -n+1; x <= n-1; x++)
if ( (abs(x) + abs(y)) <= n-1 ) printf("*");
else printf(" ");
printf("n");
}
}
/* Este programa pide ingresar dos enteros positivos y muestra
el MCD y el MCM de ambos, empleando funciones */
#include <stdio.h>
// prototipos de funciones
int mcd (int a, int b);
int mcm (int a, int b);
int main (void)
{
int a,b;
printf("n a: ");
scanf("%d", &a);
printf(" b: ");
scanf("%d", &b);
printf(" mcd = %d.n",mcd(a,b));
printf(" mcm = %d.n",mcm(a,b));
printf("n");
return 7;
}
// funcion que retorna el MCD si se ingresan dos enteros positivos
int mcd (int a, int b)
{
int d = 1, m;
while (d <= a && d <= b)
{
if (a % d == 0 && b % d == 0) m = d;
d++;
}
return m;
}
// funcion que retorna el MCM si se ingresan dos enteros positivos
int mcm (int a, int b)
{
int m = mcd(a,b);
return (a*b)/m;
}
#include <stdio.h>
#include <stdlib.h>
int dot_product(int *, int *, size_t);
int
main(void)
{
int a[3] = {1, 3, -5};
int b[3] = {4, -2, -1};
printf("%dn", dot_product(a, b, sizeof(a) / sizeof(a[0])));
return EXIT_SUCCESS;
}
int
dot_product(int *a, int *b, size_t n)
{
int sum = 0;
size_t i;
for (i = 0; i < n; i++) {
sum += a[i] * b[i];
}
return sum;
}
/* Este programa pide ingresar un entero positivo "n" mayor que 2
* y muestra todos los primos menores o iguales a "n" */
#include <stdio.h>
int esprimo (int N);
void main (void)
{
int n, i, d, cont;
printf("n Ingrese un entero n mayor que 2: ");
scanf("%d", &n);
printf(" Los primos menores o iguales a %d son: 2", n);
for(i = 3; i < n; i++)
if (esprimo(i) == 1) printf(", %d",i);
printf(".nn");
}
int esprimo (int N)
{
int d = 2, cont = 0;
while (d < N && cont == 0)
{
if (N % d == 0) cont++;
d++;
}
if (cont == 0) return 1;
else return 0;
}
#include<stdio.h>
typedef struct{
float i,j,k;
}Vector;
Vector a = {3, 4, 5},b = {4, 3, 5},c = {-5, -12, -13};
float dotProduct(Vector a, Vector b)
{
return a.i*b.i+a.j*b.j+a.k*b.k;
}
Vector crossProduct(Vector a,Vector b)
{
Vector c = {a.j*b.k - a.k*b.j, a.k*b.i - a.i*b.k, a.i*b.j - a.j*b.i};
return c;
}
float scalarTripleProduct(Vector a,Vector b,Vector c)
{
return dotProduct(a,crossProduct(b,c));
}
Vector vectorTripleProduct(Vector a,Vector b,Vector c)
{
return crossProduct(a,crossProduct(b,c));
}
void printVector(Vector a)
{
printf("( %f, %f, %f)",a.i,a.j,a.k);
}
int main()
{
printf("n a = "); printVector(a);
printf("n b = "); printVector(b);
printf("n c = "); printVector(c);
printf("n a . b = %f",dotProduct(a,b));
printf("n a x b = "); printVector(crossProduct(a,b));
printf("n a . (b x c) = %f",scalarTripleProduct(a,b,c));
printf("n a x (b x c) = "); printVector(vectorTripleProduct(a,b,c));
return 0;
}

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Union
UnionUnion
Union
 
C언어 스터디 강의자료 - 4차시
C언어 스터디 강의자료 - 4차시C언어 스터디 강의자료 - 4차시
C언어 스터디 강의자료 - 4차시
 
Ejercicios.
Ejercicios. Ejercicios.
Ejercicios.
 
Opasignacion
OpasignacionOpasignacion
Opasignacion
 
Trabajo de programacion
Trabajo de programacionTrabajo de programacion
Trabajo de programacion
 
Introduction to TDD in C
Introduction to TDD in CIntroduction to TDD in C
Introduction to TDD in C
 
Progrma para calcular los numeros pares e impares
Progrma para calcular los numeros pares e imparesProgrma para calcular los numeros pares e impares
Progrma para calcular los numeros pares e impares
 
Progrma para calcular los numeros pares e impares
Progrma para calcular los numeros pares e imparesProgrma para calcular los numeros pares e impares
Progrma para calcular los numeros pares e impares
 
Rafael vasquez
Rafael vasquezRafael vasquez
Rafael vasquez
 
Numeros primos
Numeros primosNumeros primos
Numeros primos
 
Sujet bac info 2012 g1, g2 et g3 avec correction
Sujet bac info 2012 g1, g2 et g3 avec correctionSujet bac info 2012 g1, g2 et g3 avec correction
Sujet bac info 2012 g1, g2 et g3 avec correction
 
Program to remove Left factoring
Program to remove Left factoringProgram to remove Left factoring
Program to remove Left factoring
 
งาน#2
งาน#2งาน#2
งาน#2
 
Curva de lorentz
Curva de lorentz Curva de lorentz
Curva de lorentz
 
B.f.s
B.f.sB.f.s
B.f.s
 
Sum2
Sum2Sum2
Sum2
 
Par o impar
Par o imparPar o impar
Par o impar
 
listing output program C
listing output program Clisting output program C
listing output program C
 
programa Polinomio de newton
programa Polinomio  de newtonprograma Polinomio  de newton
programa Polinomio de newton
 
Public class c
Public class cPublic class c
Public class c
 

Kürzlich hochgeladen

30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...
30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...
30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...Nguyen Thanh Tu Collection
 
أَسَانِيدُ كُتُبِ وَأُصُولِ النَّشْرِ لِابْنِ الْجَزَرِيِّ وَالْوَصْلُ بِهَا....
أَسَانِيدُ كُتُبِ وَأُصُولِ النَّشْرِ لِابْنِ الْجَزَرِيِّ وَالْوَصْلُ بِهَا....أَسَانِيدُ كُتُبِ وَأُصُولِ النَّشْرِ لِابْنِ الْجَزَرِيِّ وَالْوَصْلُ بِهَا....
أَسَانِيدُ كُتُبِ وَأُصُولِ النَّشْرِ لِابْنِ الْجَزَرِيِّ وَالْوَصْلُ بِهَا....سمير بسيوني
 
، ژیانا ئینگلیزا ب کوردی ، ئینگلیزەکان ، راپورتی کوردی ، راپورتا مێژوی ، ژ...
، ژیانا ئینگلیزا ب کوردی ، ئینگلیزەکان ، راپورتی کوردی ،    راپورتا مێژوی ، ژ...، ژیانا ئینگلیزا ب کوردی ، ئینگلیزەکان ، راپورتی کوردی ،    راپورتا مێژوی ، ژ...
، ژیانا ئینگلیزا ب کوردی ، ئینگلیزەکان ، راپورتی کوردی ، راپورتا مێژوی ، ژ...Idrees.Hishyar
 
TUYỂN TẬP 25 ĐỀ THI HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2023 CÓ ĐÁP ÁN (SƯU...
TUYỂN TẬP 25 ĐỀ THI HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2023 CÓ ĐÁP ÁN (SƯU...TUYỂN TẬP 25 ĐỀ THI HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2023 CÓ ĐÁP ÁN (SƯU...
TUYỂN TẬP 25 ĐỀ THI HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2023 CÓ ĐÁP ÁN (SƯU...Nguyen Thanh Tu Collection
 
French Revolution (फ्रेंच राज्यक्रांती)
French Revolution  (फ्रेंच राज्यक्रांती)French Revolution  (फ्रेंच राज्यक्रांती)
French Revolution (फ्रेंच राज्यक्रांती)Shankar Aware
 
TUYỂN TẬP 20 ĐỀ THI KHẢO SÁT HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2020 (CÓ Đ...
TUYỂN TẬP 20 ĐỀ THI KHẢO SÁT HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2020 (CÓ Đ...TUYỂN TẬP 20 ĐỀ THI KHẢO SÁT HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2020 (CÓ Đ...
TUYỂN TẬP 20 ĐỀ THI KHẢO SÁT HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2020 (CÓ Đ...Nguyen Thanh Tu Collection
 

Kürzlich hochgeladen (6)

30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...
30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...
30 ĐỀ PHÁT TRIỂN THEO CẤU TRÚC ĐỀ MINH HỌA BGD NGÀY 22-3-2024 KỲ THI TỐT NGHI...
 
أَسَانِيدُ كُتُبِ وَأُصُولِ النَّشْرِ لِابْنِ الْجَزَرِيِّ وَالْوَصْلُ بِهَا....
أَسَانِيدُ كُتُبِ وَأُصُولِ النَّشْرِ لِابْنِ الْجَزَرِيِّ وَالْوَصْلُ بِهَا....أَسَانِيدُ كُتُبِ وَأُصُولِ النَّشْرِ لِابْنِ الْجَزَرِيِّ وَالْوَصْلُ بِهَا....
أَسَانِيدُ كُتُبِ وَأُصُولِ النَّشْرِ لِابْنِ الْجَزَرِيِّ وَالْوَصْلُ بِهَا....
 
، ژیانا ئینگلیزا ب کوردی ، ئینگلیزەکان ، راپورتی کوردی ، راپورتا مێژوی ، ژ...
، ژیانا ئینگلیزا ب کوردی ، ئینگلیزەکان ، راپورتی کوردی ،    راپورتا مێژوی ، ژ...، ژیانا ئینگلیزا ب کوردی ، ئینگلیزەکان ، راپورتی کوردی ،    راپورتا مێژوی ، ژ...
، ژیانا ئینگلیزا ب کوردی ، ئینگلیزەکان ، راپورتی کوردی ، راپورتا مێژوی ، ژ...
 
TUYỂN TẬP 25 ĐỀ THI HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2023 CÓ ĐÁP ÁN (SƯU...
TUYỂN TẬP 25 ĐỀ THI HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2023 CÓ ĐÁP ÁN (SƯU...TUYỂN TẬP 25 ĐỀ THI HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2023 CÓ ĐÁP ÁN (SƯU...
TUYỂN TẬP 25 ĐỀ THI HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2023 CÓ ĐÁP ÁN (SƯU...
 
French Revolution (फ्रेंच राज्यक्रांती)
French Revolution  (फ्रेंच राज्यक्रांती)French Revolution  (फ्रेंच राज्यक्रांती)
French Revolution (फ्रेंच राज्यक्रांती)
 
TUYỂN TẬP 20 ĐỀ THI KHẢO SÁT HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2020 (CÓ Đ...
TUYỂN TẬP 20 ĐỀ THI KHẢO SÁT HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2020 (CÓ Đ...TUYỂN TẬP 20 ĐỀ THI KHẢO SÁT HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2020 (CÓ Đ...
TUYỂN TẬP 20 ĐỀ THI KHẢO SÁT HỌC SINH GIỎI MÔN TIẾNG ANH LỚP 6 NĂM 2020 (CÓ Đ...
 

PROBLEMAS DE PROGRAMACION 2 por jordan puente quinto

  • 1. Soluciones de la dirigida 4 /* Este programa pide ingresar un entero positivo "n" mayor que 2 * y muestra todos los primos menores o iguales a "n" */ #include <stdio.h> void rombo (int n); void tri1 (int n); void tri2 (int n); void main (void) { int n; printf("n Ingrese un entero mayor que 1: "); scanf("%d",&n); printf("n Rombo de diagonal %d:n", 2*n + 1); rombo(n); printf("n Triangulo de altura %d y ancho %d:n", 2*n - 1, n); tri1(n); printf("n Triangulo de altura %d y ancho %d:n", n, 2*n - 1); tri2(n); printf("n"); } void rombo (int n) { int x, y; for (y = -n; y <= n ; y++) { for (x = n; x >= -n; x--) if ( (abs(x) + abs(y)) <= n ) printf("*"); else printf(" "); printf("n"); } } void tri1 (int n) { int x, y; for (y = 1; y < n ; y++) { for (x = 1; x <= y; x++) printf("*"); printf("n"); } for ( ; y > 0 ; y--) { for (x = 1; x <= y; x++) printf("*"); printf("n"); } } void tri2 (int n) { int x, y; for (y = n-1; y >= 0; y--) { for (x = -n+1; x <= n-1; x++) if ( (abs(x) + abs(y)) <= n-1 ) printf("*"); else printf(" "); printf("n"); } } /* Este programa pide ingresar dos enteros positivos y muestra el MCD y el MCM de ambos, empleando funciones */ #include <stdio.h> // prototipos de funciones int mcd (int a, int b); int mcm (int a, int b);
  • 2. int main (void) { int a,b; printf("n a: "); scanf("%d", &a); printf(" b: "); scanf("%d", &b); printf(" mcd = %d.n",mcd(a,b)); printf(" mcm = %d.n",mcm(a,b)); printf("n"); return 7; } // funcion que retorna el MCD si se ingresan dos enteros positivos int mcd (int a, int b) { int d = 1, m; while (d <= a && d <= b) { if (a % d == 0 && b % d == 0) m = d; d++; } return m; } // funcion que retorna el MCM si se ingresan dos enteros positivos int mcm (int a, int b) { int m = mcd(a,b); return (a*b)/m; } #include <stdio.h> #include <stdlib.h> int dot_product(int *, int *, size_t); int main(void) { int a[3] = {1, 3, -5}; int b[3] = {4, -2, -1}; printf("%dn", dot_product(a, b, sizeof(a) / sizeof(a[0]))); return EXIT_SUCCESS; } int dot_product(int *a, int *b, size_t n) { int sum = 0; size_t i; for (i = 0; i < n; i++) { sum += a[i] * b[i]; } return sum; } /* Este programa pide ingresar un entero positivo "n" mayor que 2 * y muestra todos los primos menores o iguales a "n" */ #include <stdio.h> int esprimo (int N); void main (void) { int n, i, d, cont; printf("n Ingrese un entero n mayor que 2: "); scanf("%d", &n); printf(" Los primos menores o iguales a %d son: 2", n); for(i = 3; i < n; i++) if (esprimo(i) == 1) printf(", %d",i); printf(".nn"); }
  • 3. int esprimo (int N) { int d = 2, cont = 0; while (d < N && cont == 0) { if (N % d == 0) cont++; d++; } if (cont == 0) return 1; else return 0; } #include<stdio.h> typedef struct{ float i,j,k; }Vector; Vector a = {3, 4, 5},b = {4, 3, 5},c = {-5, -12, -13}; float dotProduct(Vector a, Vector b) { return a.i*b.i+a.j*b.j+a.k*b.k; } Vector crossProduct(Vector a,Vector b) { Vector c = {a.j*b.k - a.k*b.j, a.k*b.i - a.i*b.k, a.i*b.j - a.j*b.i}; return c; } float scalarTripleProduct(Vector a,Vector b,Vector c) { return dotProduct(a,crossProduct(b,c)); } Vector vectorTripleProduct(Vector a,Vector b,Vector c) { return crossProduct(a,crossProduct(b,c)); } void printVector(Vector a) { printf("( %f, %f, %f)",a.i,a.j,a.k); } int main() { printf("n a = "); printVector(a); printf("n b = "); printVector(b); printf("n c = "); printVector(c); printf("n a . b = %f",dotProduct(a,b)); printf("n a x b = "); printVector(crossProduct(a,b)); printf("n a . (b x c) = %f",scalarTripleProduct(a,b,c)); printf("n a x (b x c) = "); printVector(vectorTripleProduct(a,b,c)); return 0; }