Ej C

Descargar como txt, pdf o txt
Descargar como txt, pdf o txt
Está en la página 1de 3

A continuación se cita un programa de ejemplo Hola mundo escrito en C++:

/* Esta cabecera permite usar los objetos que encapsulan los descriptores stdout

y stdin: cout(<<) y cin(>>)*/

#include <iostream>

using namespace std;

int main()

cout << "Hola mundo" << endl;

cin.get();

Este es un programa donde:

Dado un numero verificar:


- Que tenga dos digitos
- Verificar si sus digitos son pares
- Promediar sus digitos

Código:

#include <stdio.h>
#include <conio.h>
int main ()
{
int numero;
printf("Inserte núm. de dos digitos pares: ");
scanf("%d",&numero);
int aux=numero;
if(numero<100 && numero>9)
{
int d1=numero%10;
numero=numero/10;
int d2=numero%10;
if(d1%2==0 & d2%2==0)
printf("El promedio d los digitos de %d es: %d",aux,(d1+d2)/2);
}
else
printf("a ERROR: el numero no tiene dos digitos");
getch();
}

Este es un programa donde :

Dado un número verificar si es positivo, negativo o nulo

Código:

#include <stdio.h>
#include <conio.h>
int main ()
{
int numero;
printf("Inserte un numero: ");
scanf("%d",&numero);
if(numero==0)
printf("El numero %d es NULO",numero);
else
{
if(numero<0)
printf("El numero %d es NEGATIVO”, numeró);
else
printf("El numero %d es POSITIVO”, número);
}
getch();
}

Este es un programa donde:

Dados seis números enteros determinar, el menor de ellos

Código:

#include<stdio.h>
#include<conio.h>
int main()
{
int a, b, c, d, e, f;
printf("Inserte num.1: "); scanf("%d",&a);
printf("Inserte num.2: "); scanf("%d",&b);
printf("Inserte num.3: "); scanf("%d",&c);
printf("Inserte num.4: "); scanf("%d",&d);
printf("Inserte num.5: "); scanf("%d",&e);
printf("Inserte num.6: "); scanf("%d",&f);
int menor=a;
if(b<menor) menor=b;
if(c<menor) menor=c;
if(d<menor) menor=d;
if(e<menor) menor=e;
if(f<menor) menor=f;
printf("El menor de %d,%d,%d,%d,%d,%d ",a,b,c,d,e,f);
printf(" Es %d",menor);
getch();
}

Este es un programa donde tenemos que:

Hallar la sumatoria de: 2! + 4! + 6! + 8! + ...

Código:

#include <stdio.h>
#include <conio.h>
int facto (int x)
{
int f=1;
for (int i=1;i<=x;i++)
{f=f*i;}
return (f);
}

int main ()
{
int n, serie=2, suma=0;
printf ("Inserte cantidad de terminos a generar: ");

scanf ("%d",&n);
for (int i=1;i<=n;i++)
{
printf ("%d! + ",serie);
suma=suma+(facto(serie));
serie=serie+2;
}
printf (" = %d",suma);
getch();
}

También podría gustarte

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy