Created
August 2, 2011 16:48
-
-
Save kaldas/1120628 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
#include "stdlib.h" | |
#define LINE_LIMIT 100 | |
int main(int argc, char** argv) | |
{ | |
int lineSize = 0, | |
lineCount = 0; | |
int n_Procurado = 2, | |
n_Atual = 1, | |
n_Flag = 0, | |
n_Soma = 0; | |
printf("\n"); | |
if(argc != 2) | |
{ | |
printf("Erro >> Input deve ser:\n%s numero_impar\n",argv[0]); | |
return -1; | |
} | |
if(atoi(argv[1]) % 2 == 0) | |
{ | |
printf("Erro >> Input deve ser um numero impar\n"); | |
return -1; | |
} | |
n_Procurado = atoi(argv[1]); | |
for(lineSize = 1;lineSize < LINE_LIMIT && n_Flag == 0;lineSize += 2) | |
{ | |
for(lineCount = 0;lineCount < lineSize;lineCount++) | |
{ | |
printf(" %i ",n_Atual); //debug | |
if(n_Flag != 0) | |
{ | |
if((lineSize - lineCount) < 4) | |
n_Soma += n_Atual; | |
} | |
if(n_Atual == n_Procurado) | |
n_Flag = 1; | |
n_Atual += 2; | |
} | |
printf("\n"); | |
} | |
printf("Resultado = %i",n_Soma); | |
//system("pause"); //windows >> fail | |
return 0x0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uhummm... Eu realmente não tinha nada melhor pra fazer =(