Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //IFF - Programação Estruturada
- //Lista de Exercícios 0 - Exercício 2
- #include<stdio.h>
- #include<stdlib.h>
- int calcularSoma(int n){
- int soma=0;
- for(int i=0;i<=n;i+=2){
- soma+=i;
- }
- return soma;
- }
- int main(){
- setbuf(stdout, NULL);
- int n, soma;
- do{
- printf("Entre com o valor alvo: ");
- scanf("%d",&n);
- }while(n<=1);
- soma=calcularSoma(n);
- printf("A soma dos números pares de 0 a %d foi %d.",n, soma);
- }
Advertisement
Add Comment
Please, Sign In to add comment