diogoAlves

IFF/Programação Estruturada/Lista 0/Exercício 2

May 3rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. //IFF - Programação Estruturada
  2. //Lista de Exercícios 0 - Exercício 2
  3.  
  4. #include<stdio.h>
  5. #include<stdlib.h>
  6.  
  7.  
  8. int calcularSoma(int n){
  9.     int soma=0;
  10.     for(int i=0;i<=n;i+=2){
  11.         soma+=i;
  12.     }
  13.     return soma;
  14. }
  15.  
  16. int main(){
  17.     setbuf(stdout, NULL);
  18.     int n, soma;
  19.     do{
  20.         printf("Entre com o valor alvo: ");
  21.         scanf("%d",&n);
  22.     }while(n<=1);
  23.     soma=calcularSoma(n);
  24.     printf("A soma dos números pares de 0 a %d foi %d.",n, soma);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment