My while, is showing error, calculate and show on the screen the sum of the n odd power of degree 2 of 10 integer numbers any

Asked

Viewed 21 times

-4

#include <stdio.h>
#include <stdlib.h>
int main()
{
 int numero,cont, som1, somtotal;
 int i;
 som1 = 1;
 somtotal = 1;
 char cod;
 
 while(cod!='F'){ 
     
    for(cont = 1; cont < numero;cont = cont + 1){
         printf("\nDigite o %d° numero inteiro: ",i+1);
         scanf("%i", &numero); 
         printf("%d ao quadrado = ",numero);
        printf("%d",som1);
         if(cont < numero-1)
         printf(" + ");
         som1 = som1 + 2;
         somtotal = somtotal + som1;
    }
    printf(" = %d",somtotal);
    somtotal=0;
    numero=0;
    som1=0
    cod= getche();
                  
  }
    return 0;
    
}
  • Please clarify your specific problem or provide Additional Details to Highlight Exactly what you need. As it’s Currently Written, it’s hard to Tell Exactly what you’re asking.

  • that’s the problem, can you help me? It is possible to calculate a power of Degree 2 by Adding Odd Numbers, Knowing that n 2 (n to the Quadrat, or power of Degree 2 of n) is Equal to the sum of the first n Odd natural Numbers. Example: 5 2 = 1 + 3 + 5 + 7 + 9 = 25 16 2 = 1 + 3 + 5 + 7 + 9 + 11 + 13 + 15 + 17 + 19 + 21 + 25 + 27 + 29 + 31 = 256 Write a program that Calculates and displays on the screen, as in the above examples, the power of Degree 2 of 10 any Whole Numbers, entered by the user

  • for(cont = 1; cont < numero;cont = cont + 1), what will be the value of numero here?

  • is a number any user enters

  • 1

    The problem is that you only ask the user to enter the number afterward who enters the for. The way it is, numero has not been initialized, so when it arrives at the for it can have any value (the so-called "memory junk") and if it works, it will be by coincidence. The same goes for cod, that you only read the value after the while

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.