Skip to content

Instantly share code, notes, and snippets.

@kaldas
Created August 2, 2011 16:48
Show Gist options
  • Save kaldas/1120628 to your computer and use it in GitHub Desktop.
Save kaldas/1120628 to your computer and use it in GitHub Desktop.
#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;
}
@Arthurmourao
Copy link

Interessante, trabalho dos calouros?

@kaldas
Copy link
Author

kaldas commented Aug 2, 2011

Uhummm... Eu realmente não tinha nada melhor pra fazer =(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment