Ejsimprimirmas
Ejsimprimirmas
Ejsimprimirmas
h>
#include <string.h>
#include <math.h>
#include <ctype.h>
//EJ1
void tostring(char [], int);
int toint(char []);
//EJ2
void sumaNumerosdeUnTexto();
//EJ3
void ultimaLetraDelTexto();
//EJ4
void MasLargaYCorta();
//EJ5
void Print_BinCoeff(int x);
//EJ6
int matrizSimetrica();
//EJ7
int esInvertible();
//EJ8
int arrayReverso();
//EJ9
//EJ10
//EJ11
return 0;
}
//EJERCICIO 1- STRING(CHAR) TO INT Y VICEVERSA
n = num;
while (n != 0)
{
len++;
n /= 10;
}
for (i = 0; i < len; i++)
{
rem = num % 10;
num = num / 10;
str[len - (i + 1)] = rem + '0';
}
str[len] = '\0';
}
//EJERCICIO 3-IMPRIME LAS PALABRAS DE UN TEXTO
QUE ACABEN EN LA LETRA S
int i, t, j, len;
len = strlen(str);
} while (c != '\n');
string[i - 1] = '\0';
for (i = 0; i < strlen(string); i++)
{
while (i < strlen(string) && !isspace(string[i]) &&
isalnum(string[i]))
{
word[j++] = string[i++];
}
if (j != 0)
{
word[j] = '\0';
if (!flag)
{
flag = !flag;
strcpy(max, word);
strcpy(min, word);
}
if (strlen(word) > strlen(max))
{
strcpy(max, word);
}
if (strlen(word) < strlen(min))
{
strcpy(min, word);
}
j = 0;
}
}
printf("The largest word is '%s' and smallest word is '%s' in
'%s'.\n", max, min, string);
}
int main(){
int rows;
printf("Enter the Number of Rows in the Pascal Triangle::\t");
scanf("%d",&rows);
for(int i=0;i<rows;i++)//loop to iterate rows from 1 to rows
{
for (int k = rows - i-1 ; k > 0; k--)
{
//Prints spaces as many as number of rows in the triangle-
current number of row
printf(" ");
}
Print_BinCoeff(i);//function to print the binomial
coefficients.
}
return 0;
}
*/
/*
int main(){
int array[15][15], i, j, rows, num = 25, k;
*/
//EJERCICIO 6_COMPROBAR SI UNA MATRIZ ES
SIMETRICA A OTRA
int matrizSimetrica(){
int i, j, row, col, count = 0;
if(i!=j)
{
printf("Rows not equal to columns. Therefore Non-
Symmetric Matrix.");
return 0;
}
//Transpose of matrix
for(row = 0; row < i; row++)
{
for(col = 0;col < j; col++)
{
b[col][row] = a[row][col];
}
}
return 0;
}
int esInvertible(){
int a[3][3], i, j;
long determinant;
printf("Enter the 9 elements of matrix: ");
for(i = 0 ;i < 3;i++)
for(j = 0;j < 3;j++)
scanf("%d", &a[i][j]);
int arrayReverso(){
int size;
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter Array Elements: ");
int arr[size];
//Start points at the first element and end points at the last
element
int start=0,end=size-1;
while(start<end)
{
//Swapping elements
int temp=arr[start];
arr[start]=arr[end];
arr[end]=temp;
int main(void)
{
int i, n, index, arr[10];
printf("Enter the size of the array: ");
scanf("%d", &n);
printf("Enter the elements of the array: \n");
for (i = 0; i < n; i++)
{
printf("arr[%d] = ", i);
scanf("%d", &arr[i]);
}
printf("Enter the index of the element to be deleted: ");
scanf("%d", &index);
if (index >= n+1)
{
printf (" \n Deletion is not possible in the array.");
}
else
{
for (i = index; i < n - 1; i++)
arr[i] = arr[i + 1];
printf("The array after deleting the element is: ");
for (i = 0; i < n - 1; i++)
printf("%d ", arr[i]);
return 0;
}
}
*/
/*int main ()
{
char str[100], word[100], twoD[10][30];
int i = 0, j = 0, k = 0, len1 = 0, len2 = 0, l = 0;
twoD[k][j] = '\0';
j = 0;
for (i = 0; i < k; i++)
{
int present = 0;
for (l = 1; l < k + 1; l++)
{
if (twoD[l][j] == '\0' || l == i)
{
continue;
}
j = 0;
printf ("\n");
return 0;
}*/
//NUMERO DE CONSONANTES Y VOCALES
/*void main()
{
char sentence[80];
int i, vowels = 0, consonants = 0, special = 0;
/*
int main(){
int num, temp, remainder, reverse = 0;
//DECIMAL A BINARIO
/*
long dec_to_bin(long n){
long bin = 0;
long dec = n;
long i = 1;
return bin;
}
int main(void){
long n;
printf("Enter a decimal number: ");
scanf("%ld", &n);
printf("Binary equivalent of %ld = %ld\n", n, dec_to_bin(n));
return 0;
}
*/
//BINARIO A OCTAL
/*
int main(){
long int binarynum, octalnum = 0, j = 1, remainder;
//OCTAL A DECIMAL
/*
int main(){
//BINARIO A HEXADECIMAL
/*
int main(){
long int binaryval, hexadecimalval = 0, i = 1, remainder;
//DECIMAL A HEXADECIMAL
/*
int main(){
long decimalnum, quotient, remainder;
int i, j = 0;
char hexadecimalnum[100];
quotient = decimalnum;
while (quotient != 0)
{
remainder = quotient % 16;
if (remainder < 10)
hexadecimalnum[j++] = 48 + remainder;
else
hexadecimalnum[j++] = 55 + remainder;
quotient = quotient / 16;
}
/*
int main(){
long num, decimal_num, remainder, base = 1, binary = 0,
no_of_1s = 0;
if (remainder == 1){
no_of_1s++;
}
binary = binary + remainder * base;
num = num / 2;
base = base * 10;
}
printf("Input number is = %d\n", decimal_num);
printf("Its binary equivalent is = %ld\n", binary);
printf("No.of 1's in the binary number is = %d\n", no_of_1s);
}*/
/*
void predigit(char num1, char num2);
void postdigit(char c, int n);
char romanval[1000];
int i = 0;
int main(){
int j;
long number;
//CONVERSION TEMPERATURAS
int main(){
float Celsius, Kelvin, Fahrenhiet;
int choice;
printf("Choose the unit you want to convert: \n");
printf("1.Kelvin\n");
printf("2.Celsius\n");
printf("3.Fahrenhiet \n");
scanf("%d", &choice);
switch (choice){
case 1:
printf("Enter the temperature in kelvin: ");
scanf("%f",&Kelvin);
Celsius = (Kelvin - 273.15);
Fahrenhiet = 1.8 *(Kelvin -273.15) + 32.0;
printf("In Celsius the value is:\t %f \n",Celsius);
printf("In Fahrenhiet the value is:\t %f",Fahrenhiet);
break;
case 2:
printf("Enter the temperature in Celsius: ");
scanf("%f",&Celsius);
Kelvin = (Celsius + 273.15);
Fahrenhiet = (Celsius * 1.8) + 32.0;
printf("In kelvin the value is : %f \n",Kelvin);
printf("In Fahrenhiet the value is: %f",Fahrenhiet);
break;
case 3:
printf("Enter the temperature in fahrenhite: ");
scanf("%f",&Fahrenhiet);
Kelvin = (Fahrenhiet - 32.0) * 5/9 +273.15;
Celsius = (Fahrenheit - 32.0) * 5/9;
printf("In Celsius the value is :\t %f \n",Celsius);
printf("In Kevlin the value is :\t %f \n",Kelvin);
break;
default:
printf("Please! enter a valid value \n");
break;
}
printf("\n\n");
return 0;
}*/
//ROMANO A DECIMAL
/*
int digit(char);
int main(){
char roman_Number[1000];
int i=0;
long int number =0;
while(roman_Number[i]){
return 0;
int value=0;
switch(c){
case 'I': value = 1; break;
case 'V': value = 5; break;
case 'X': value = 10; break;
case 'L': value = 50; break;
case 'C': value = 100; break;
case 'D': value = 500; break;
case 'M': value = 1000; break;
case '\0': value = 0; break;
default: value = -1;
}
return value;
}*/
//MULTIPLICACION DE BINARIOS
/*
int binaryproduct(int, int);
int main(){
//NUMERO DE PALABRAS
void main(){
char s[200];
int count = 0, i;
void main(){
int n;
printf("Enter number of elements in the array: ");
scanf("%d", &n);
int arr[n];
if (m == n){
printf("Enter the co-efficients of the matrix\n");
for (i = 0; i < m; ++i){
for (j = 0; j < n; ++j){
scanf("%dx%d", &array[i][j]);
}
}
}*/
/*int main(){
int n, count = 0;
printf("Enter number of elements in the array: ");
scanf("%d", &n);
int arr[n], temp[n];
if(n==0){
printf("No element inside the array.");
exit(0);
}
printf("Enter elements in the array: ");
for (int i = 0; i < n; i++){
scanf("%d", &arr[i]);
}
return 0;
}
//MODA DE UN ARRAY
int main(){
int i, j, a[20] = {0}, sum = 0, n, t, b[20] = {0}, k = 0, c = 1,
max = 0, mode;
float x = 0.0, y = 0.0;
printf("\nEnter the limit\n");
scanf("%d", &n);
printf("Enter the set of numbers\n");
for (i = 0; i < n; i++){
scanf("%d", &a[i]);
}
for (i = 0; i < n - 1; i++){
mode = 0;
for (j = i + 1; j < n; j++){
if (a[i] == a[j]){
mode++;
}
}
if ((mode > max) && (mode != 0)) {
k = 0;
max = mode;
b[k] = a[i];
k++;
}
else if (mode == max) {
b[k] = a[i];
k++;
}
}
for (i = 0; i < n; i++){
if (a[i] == b[i])
c++;
}
if (c == n)
printf("\nThere is no mode");
else{
printf("\nMode\t= ");
for (i = 0; i < k; i++)
printf("%d ",b[i]);
}
printf("\n");
return 0;
}
char string[20];
int n, count = 0;
}*/
//TEXTO AL REVES
int main(){
char str1[100], *ptr;
int len1 = 0, i;
char ch;
printf("Enter the string:\n");
scanf("%[^\n]s", str1);
ptr = str1;
len1 = strlen(str1);
printf("Using iteration:\n");
for (i = len1 - 1; i >= 0;i--){
ch = str1[i];
printf("%c", ch);
}*/
/*
char caps_check(char *);
int main()
{
char string[20], letter;
/*
int main (){
int a = 0, b = 0, temp = 0, i = 0, countCast = 0;
char BYTE_HERE[8];
int FULL_BYTE[8];
return 0;
}
/*
int main (){
int num = 0, count = 0, n = 0, i = 0;
/*int main(){
int array[MAXSIZE];
int i, j, num, temp;
/*int main(){
char string[SIZE], string1[SIZE], string2[SIZE];
int i, j = 0, a = 0, temp, len = 0, len1 = 0, k = 0;
printf("\nEnter a string:");
scanf("%[^\n]s", string1);
/*
int main(){
int array1[10][10], array2[10][10];
int i, j, k, a, m, n;
printf("Enter the order of the matrix \n");
scanf("%d %d", &m, &n);
printf("Enter co-efficients of the matrix \n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
scanf("%d", &array1[i][j]);
array2[i][j] = array1[i][j];
}
}
printf("The given matrix is \n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(" %d", array1[i][j]);
}
printf("\n");
}
printf("After arranging rows in ascending order\n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
for (k =(j + 1); k < n; ++k)
{
if (array1[i][j] > array1[i][k])
{
a = array1[i][j];
array1[i][j] = array1[i][k];
array1[i][k] = a;
}
}
}
}
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(" %d", array1[i][j]);
}
printf("\n");
}
printf("After arranging the columns in descending order \n");
for (j = 0; j < n; ++j)
{
for (i = 0; i < m; ++i)
{
for (k = i + 1; k < m; ++k)
{
if (array2[i][j] < array2[k][j])
{
a = array2[i][j];
array2[i][j] = array2[k][j];
array2[k][j] = a;
}
}
}
}
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
printf(" %d", array2[i][j]);
}
printf("\n");
}
}*/
int str = 1;
while(str <= num){
int i = 1;
while(i ++ <= (num - str) * 2 + 1)
printf(" ");
i = 0;
while(i ++ < 2 * str - 1)
printf("* ");
str ++;
printf("\n");
}
str = num - 1;
while(str != 0)
{
int i = 1;
while(i ++ <= (num - str) * 2 + 1)
printf(" ");
i = 0;
while(i ++ < 2 * str - 1)
printf("* ");
str --;
printf("\n");
}
}
//IMPRIMIR ESTE PATRON(FLOYD TRIANGLE)
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
int main(){
int i = 1, j = 0, rows = 7;
int num = 1;
while (i <= rows)
{
while (j <= i - 1)
{
printf("%d ", num);
j++;
num++;
}
j = 0;
i++;
printf("\n");
}
return 0;
}*/
/*
int main(){
int array[MAXSIZE];
int i, num, power;
float x, polySum;
printf("Enter the order of the polynomial \n");
scanf("%d", &num);
printf("Enter the value of x \n");
scanf("%f", &x);
if (array[i] > 0)
printf(" + ");
else if (array[i] < 0)
printf(" - ");
else
printf(" ");
printf("%dx^%d ", abs(array[i]), power--);
}
printf("\n Sum of the polynomial = %6.2f \n", polySum);
}*/
//STRING PALINDROMO
/*
void main(){
char string[25], reverse_string[25] = {'\0'};
int i, length = 0, flag = 0;
/*
//ENUNCIADO EJERCICIO
c) Calcular 1 * 3 * 5 * ··· * n
int main() {
int valorParaCalculo=0; int opcionUsuario = 1;
while (opcionUsuario!=4) {
printf("\n\n1: Introducir valor\n2: Calcular serie 1+3+5...\
n");
printf("3: Calcular serie 1*3*5...\n4: Salir\n\nElija opcion:
");
scanf("%d", &opcionUsuario);
if (opcionUsuario==1) {
valorParaCalculo = obtenerValorParaCalculo();
rellenarArray (valorParaCalculo);
}
if (opcionUsuario==2) {
if (valorParaCalculo!=0) {
printf("n = %d El valor del sumatorio es: %ld",
valorParaCalculo, valorSumatorio(numeroItems));
} else {
printf("No hay un valor para calculo que permita
obtener sumatorio 1+3+5+...");
}
}
if (opcionUsuario==3) {
if (valorParaCalculo!=0) {
printf("n = %d El valor del producto es: %ld",
valorParaCalculo, valorProducto(numeroItems));
} else {
printf("No hay un valor para calculo que permita
obtener resultado 1*3*5*...");
}
}
}
return 0;
}
int obtenerValorParaCalculo() {
int imparElegido = 0;
do {
printf("\nPor favor introduzca numero entero impar entre 1
y 19: ");
scanf("%d", &imparElegido);
} while (imparElegido<=0 || imparElegido> NMAX ||
imparElegido%2==0);
return imparElegido;
}