Informática, perguntado por butowisquiki33, 5 meses atrás

Faça um programa que leia um número inteiro N e mostre a soma de todos os inteiros menores ou iguais a N.

Soluções para a tarefa

Respondido por matheusnascimento20
1

Resposta:

Fiz na linguagem C

Explicação:

#include <stdio.h>

#include <stdlib.h>

int main(){

int n,soma=0,cont;    //DECLARAÇÃO DAS VARIÁVEIS

scanf("%d",&n);    //LEITURA DO VALOR DE N

 for(cont=1;cont<=n;cont++){    //ESTRUTURA DE REPETIÇÃO FOR

  if(cont<=n){    //ESTRUTURA DE CONDICIONAL

   soma+=cont;   //SOMATÓRIO

  }   //FIM DA ESTRUTURA CONDICIONAL

 }  //FIM DA ESTRUTURA DE REPETIÇÃO FOT

 printf("A soma = %d",soma);  //IMPRESSÃO DO RESULTADO DA SOMA

return 0;

}

Perguntas interessantes