1
Can someone help me fix the higher and lower command basically it has to speak the largest number of a value and the smallest number of the same value.
Example: I add the value 727522
the program will have to read it and say that the Maior valor é 7 e menor é 2
.
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <iostream>
//variaveis
int ckdig (int n, int* p, int* i)
{
//Valores nas variaveis
int d = 0;
if(n < 0) n = -n;
*p = *i = 0;
//Par e impar
while(n)
{
if((n % 2))
(*p)++;
else
(*i)++;
n /= 10;
d++;
}
return d;
}
//
inline int _abs (int n)
{
return (n < 0) ? -n:n;
}
int digits (int val, int base)
{
register int digs = 0, n;
n = _abs(val);
do
{
n /= base;
digs++;
}while(n);
return digs;
}
int main (int argc, char** argv)
{
//Variaveis
int n, p, i, d,maior=0,menor=0,num,sobra;
//Acento
(setlocale(LC_ALL,""));
//Da um Valor a n
printf("Digite um número:");
scanf("%d", &n);
d = ckdig(n, &p, &i);
//Escreve na tela os pares e impares
printf("Há %d pares e %d impares.\n", p, i);
//Soma
int soma;
printf("Soma de N:");soma=0;
while(n>0)
{
soma+=n%10;
n/=10;
}
printf("%d\n",soma);
// Maior e Menor
//encontra o maior valor
maior = n=0;
for (d = 1; d < n; d++) {
if (n> maior) {
maior = n;
}
}
//encontra o menor valor
menor = n=0;
for (d = 1; d < n; d++) {
if (n < menor) {
menor = n;
}
}
//Escreva na tela o maior e menor numero
printf("Maior valor é %d e o Menor é %d ",maior,menor);
}
correct the indentation of your code, otherwise it will be difficult for other people to understand and help...also, be direct (but polite) with the question, do not need to call for help, ask for help, etc
– zentrunix
And also put a more explanatory title to your doubt. I, for example, can’t get any information out. Which means exactly "DEV problem" ?
– Isac
Thanks for helping me I’m new to the forum and I want to learn more
– FT gamex