1. Crear un programa que calcule el valor absoluto de un número, pidiendo al usuario un número y el programa imprimirá su valor absoluto:
#include < stdio.h>
void main()
{
//To declare the variable of.
int num;
//Start the program.....
printf("\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$ ABSOLUTE VALUE $$$$$$$$$$$$\n");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("Please, introduce a number: ");
scanf("%d", &num);
//Doing the conditions and printing the result.
if(num < 0)
{
printf("\n\nYour number is: %d\n\n", -num);
}
else
{
printf("\n\nYour number is: %d\n\n", num);
}
}
2. Crear un programa que verifique si el carácter que el usuario ingresó es una letra minúscula, mayúscula, carácter especial o un número:
#include < stdio.h>
//To declare the consts of ASCII Table.
#define FIRST_CL 'A'
#define LAST_CL 'Z'
#define FIRST_LL 'a'
#define LAST_LL 'z'
#define MIN_NUM '0'
#define MAX_NUM '9'
void main()
{
//To declare the variable of the character that you enter by the keyboard.
char yourChar;
//Start the program.....
printf("\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$ TYPE OF CHARACTER $$$$$$$$$$\n\n");
printf("Please, introduce whatever character you want: ");
scanf("%c", &yourChar);
//Doing the conditions and print the results.
if((yourChar > FIRST_LL) && (yourChar < LAST_LL))
{
//Print that the solution is a lower-case letter.
printf("\n\nYour character %c is a: lower-case letter\n\n", yourChar);
}
else if((yourChar > FIRST_CL) && (yourChar < LAST_CL))
{
//Print that the solution is a capital letter.
printf("\n\nYour character %c is a: capital letter\n\n", yourChar);
}
else if((yourChar > MIN_NUM) && (yourChar < MAX_NUM))
{
//Print that the solution is a number.
printf("\n\nYour character %c is a: number\n\n", yourChar);
}
else
{
//Print that the solution is a special character.
printf("\n\nYour character %c is a: special character\n\n", yourChar);
}
}
3. Crear un programa que verifique si el año ingresado es bisiesto o año común. El año se ingresa como un entero:
#include < stdio.h>
void main()
{
//To declare the variable of the year that you are going to enter.
int typeYear;
//Start the program.....
printf("\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$ TYPE OF YEAR $$$$$$$$$$\n\n");
printf("Please, introduce whatever year you want: ");
scanf("%d", &typeYear);
//Doing the conditions and print the results.
if((typeYear % 4 == 0 && typeYear % 100 != 0) || (typeYear % 400 == 0))
{
//Print that the solution is leap year.
printf("\n\nYour year %d is a leap year\n\n", typeYear);
}
else
{
//Print that the solution is a common year.
printf("\n\nYour year %d is a common year, so it is not a leap year.\n\n", typeYear);
}
}
4. Crear un programa que verifique si la solución de la imagen es positiva o negativa y, si existe o no:
#include < stdio.h>
void main()
{
//To declare the mystery variable, and a store variable.
float x, sol;
//Start the program.....
printf("\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$ Resolve the ecuation $$$$$$$$$$\n");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n\n");
printf("Please, introduce a number to obtain a solution: ");
scanf("%f", &x);
//Doing the conditions and print the results.
sol = (x-5)*(x-3) / (x-2);
if((x-2) == 0)
{
printf("\n\nThe solution of the equation does not exists.\n\n");
}
else if(sol < 0)
{
printf("\n\nThe solution of the equation is (-)negative.\n\n");
}
else
{
printf("\n\nThe solution of the equation is (+)positive.\n\n");
}
}
5. Crear un programa que calcule las soluciones de una ecuación cuadrática. El programa solicita parámetros para la ecuación ax2 + bx + cx = 0. Después, imprime el número de soluciones racionales e irracionales que haya y, por último, imprime las soluciones x1 y x2:
#include < stdio.h>
#include < math.h>
void main()
{
//To declare the parameters a, b and c of the quadratic equation: ax2 + bx + c = 0.
float a, b, c;
//To declare the two solutions of the quadratic equation.
float x1, x2;
//Start the program.....
printf("\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$ RESOLVE THE QUADRATIC EQUATION $$$$$$$$$$\n");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("Please, introduce a number for the parameter a: ");
scanf("%f", &a);
printf("Please, introduce a number for the parameter b: ");
scanf("%f", &b);
printf("Please, introduce a number for the parameter c: ");
scanf("%f", &c);
//Doing the conditions and print the results.
x1 = (-b + sqrt(pow(b,2)-4*a*c))/2*a;
x2 = (-b - sqrt(pow(b,2)-4*a*c))/2*a;
if(a == 0 || b == 0 || c == 0)
{
printf("\n\nIn this case, it is not a quadratic equation.\n\n");
}
else
{
if(pow(b,2)-4*a*c < 0)
{
printf("\n\nThe solution of the quadratic equation %gx^2 + (%g)x + (%g) = 0 is irrational.\n\n", a, b, c);
}
else
{
if(x1 == x2)
{
printf("\n\nThe solution of the quadratic equation %gx^2 + (%g)x + (%g) = 0 is rational with 1 solution => x1 = x2 = %g\n\n", a, b, c, x1);
}
else
{
printf("\n\nThe solution of the quadratic equation %gx^2 + (%g)x + (%g) = 0 is rational with 2 solutions => x1 = %g and x2 = %g\n\n", a, b, c, x1, x2);
}
}
}
}
6. Crear un programa para comprobar si un número es divisible por el segundo número. El usuario introduce ambos números. Luego, el programa realiza la comprobación e imprime si son divisibles. Si el usuario intenta dividir por cero, imprime un error:
#include < stdio.h>
#include < math.h>
void main()
{
//To declare the dividend and the dividing variables.
int dividend, dividing;
//Start the program.....
printf("\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$ DIVISIBLE NUMBERS $$$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("Please, introduce the integer dividend: ");
scanf("%d", ÷nd);
printf("Please, introduce the integer dividing: ");
scanf("%d", &dividing);
//Doing the conditions and print the results.
if((dividing == 0) || (dividend == 0 && dividing == 0))
{
printf("\n\nSYNTAX ERROR!!!!!\n\n");
}
else
{
if(dividend % dividing == 0)
{
printf("\n\nThe number %d is divisible between the number %d.\n\n", dividend, dividing);
}
else
{
printf("\n\nThe number %d is NOT divisible between the number %d.\n\n", dividend, dividing);
}
}
}
7. Crear un programa que imprima la calificación de un estudiante en función de su puntaje en el examen:
Entre 0 y 54 => El estudiante suspendió
Entre 55 y 64 => 6
Entre 65 y 74 => 7
Entre 75 y 84 => 8
Entre 85 y 94 => 9
Entre 95 y 100 => 10
#include < stdio.h>
void main()
{
//To declare the score of the student in a subject.
int score;
//Start the program.....
printf("\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$ SUBJECT ASSESSMENT $$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("Please, introduce the score, between 0 and 100, of the student in this subject: ");
scanf("%d", &score);
//Doing the conditions and print the results.
if(score >= 0 && score <= 54)
{
printf("\n\nTHE FINAL SCORE OF THE STUDENT => FAILED\n\n");
}
else if(score >= 55 && score <= 64)
{
printf("\n\nTHE FINAL SCORE OF THE STUDENT => 6: Grade C\n\n");
}
else if(score >= 65 && score <= 74)
{
printf("\n\nTHE FINAL SCORE OF THE STUDENT => 7: Grade B-\n\n");
}
else if(score >= 75 && score <= 84)
{
printf("\n\nTHE FINAL SCORE OF THE STUDENT => 8: Grade B+\n\n");
}
else if(score >= 85 && score <= 94)
{
printf("\n\nTHE FINAL SCORE OF THE STUDENT => 9: Grade A-\n\n");
}
else if(score >= 95 && score <= 100)
{
printf("\n\nTHE FINAL SCORE OF THE STUDENT => 10: Grade A+\n\n");
}
else
{
printf("\n\nPLEASE, ENTER A VALIDATE NUMBER!!!\n\n");
}
}
8. Crear un programa que solicite al usuario que ingrese tres números. Luego, el programa imprime los tres números ordenados del menor a mayor:
#include < stdio.h>
void main()
{
//To declare three variables by the three numbers that the user has to enter.
int num1, num2, num3;
//Start the program.....
printf("\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$ SORTING OF NUMBERS $$$$$$$$$$$$$$$$$$$$$$\n");
printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
printf("Please, introduce the first number: ");
scanf("%d", &num1);
printf("Please, introduce the second number: ");
scanf("%d", &num2);
printf("Please, introduce the third number: ");
scanf("%d", &num3);
//Doing the conditions and print the results.
if(num1 < num2 && num1 < num3 && num2 < num3)
{
printf("\n\nSolution: %d < %d < %d\n\n", num1, num2, num3);
}
else if(num1 > num2 && num1 < num3)
{
printf("\n\nSolution: %d < %d < %d\n\n", num2, num1, num3);
}
else if(num1 > num2 && num1 > num3 && num2 < num3)
{
printf("\n\nSolution: %d < %d < %d\n\n", num2, num3, num1);
}
else if(num1 > num2 && num1 > num3 && num2 > num3)
{
printf("\n\nSolution: %d < %d < %d\n\n", num3, num2, num1);
}
else if(num1 < num2 && num1 > num3)
{
printf("\n\nSolution: %d < %d < %d\n\n", num3, num1, num2);
}
}
Ubicación: Universidad de Novi Sad - Dr Zorana Đinđića 1, Novi Sad 21000, Vojvodina, Serbia
Teléfono: +381 21 485 2056
Correo electrónico: iro.ftn@uns.ac.rs
Copyright © 2023-2030 My Professional WEB - Todos los derechos reservados