Closed nikoaha closed 6 years ago
This program takes in two floats and prints a relative number of the given numbers.
/* START OF FILE */
#include "project.h"
#include` <stdio.h>
void scaler(float *num1, float *num2)
{
if (*num1 < *num2) {
*num1 = *num1 / *num2;
*num2 = 1.0;
}
if (*num1 >= *num2) {
*num2 = *num2 / *num1;
*num1 = 1.0;
}
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
UART_1_Start();
float num1, num2;
int b1 = 0;
while (b1 == 0) {
printf("Enter 1. number: \n");
scanf("%f", &num1);
if (num1 >= 0) {
b1++;
} else {
printf("Number must be positive!\n");
}
}
while (b1 == 1) {
printf("Enter 2. number: \n");
scanf("%f", &num2);
if (num2 >= 0) {
b1++;
} else {
printf("Number must be positive!\n");
}
}
if (b1 == 2) {
scaler(&num1, &num2);
b1++;
}
printf("Scaled values are: \n");
printf("1: %.5f\n", num1);
printf("2: %.5f\n", num2);
for(;;)
{
/* Place your application code here. */
}
}
/* [] END OF FILE */
The user enters five float numbers in an array and the program prints the smallest given number.
/* START OF FILE */
#include "project.h"
#include <stdio.h>
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
UART_1_Start();
float numbers[5];
int i = 0;
float smallestNumber = 0;
printf("\nEnter five numbers: \n");
for (i=0 ; i<5 ; i++) {
printf("Enter number %d: ", i+1);
scanf("%f", &numbers[i]);
}
smallestNumber = numbers[0];
for (i=0 ; i<5 ; i++) {
if (numbers[i] < smallestNumber) {
smallestNumber = numbers[i];
}
}
printf("The smallest number you entered was: %.3f\n", smallestNumber);
for(;;)
{
/* Place your application code here. */
}
}
/* [] END OF FILE */
This program multiplies or sums two given numbers and prints the result. This program is looped until the user quits.