int main (int argc, const char * argv[]) { char c; FILE *file; int n=0, loop=0; int prodof5 = 1; int maxprod = 1; int num=1, firstnum=0; int firstfive[5] = {0}; int i=0; file = fopen("longnumber.txt", "r"); //to open the file in read mode, right now file is in the same directory as this file is printf("opend file\n"); if (file) { //initial set up for(i=0;i<5;i++) { if ((c = fgetc(file)) != EOF) { num = atoi2(c); firstfive[i] = num; prodof5 = prodof5 * num; } } maxprod = prodof5; while ((c = fgetc(file)) != EOF) { num = atoi2(c); if(num != 0){ // can improve a bit by checking if num==firstfive[0], in w/c case same result so can just continue in that case. prodof5 = prodof5/firstfive[0]; prodof5 = prodof5 * num; if (maxprod < prodof5) { maxprod = prodof5; reshuffle(firstfive, num); } else{ reshuffle(firstfive, num); } } //putchar(c); } fclose(file); } printf("consecutive sum is %d\n", maxprod); return 0; }
int evaluate (char **s, int n) { int i, tmp; char c; Stack st; empty(&st); for (i = 1; i <= n; i++) { switch (c = s[i][0]) { case '+': push (&st, pop(&st) + pop(&st)); break; case '-': tmp = pop(&st); push (&st, pop(&st) - tmp); break; case '/': tmp = pop(&st); push (&st, pop(&st) / tmp); break; case 'x': push (&st, pop(&st) * pop(&st)); break; case '^': push (&st, (int)pow (pop(&st), pop(&st))); break; default : push (&st, atoi2(s[i])); break;}} if(st.cs>0) printf("\n warning : Stack end not reached!!! Incomplete expression!!!\n"); return (st.vector[st.cs]); }
//Proceso Top int Tope(int argc, char* argv[]) { char* video= (char*)0xb8000; int proce[65]; char Mensaje [10]; int salto; int i; char a; k_clear_screen(); message("Top V1.0: Procesos y porcentaje de CPU utilizada",0,10); message("PID CPU% TTY NAME",2,0); Sti(); while(a!=68) { a=GetKey(); salto=3; for(i=0;i<65;i++) { proce[i]=0; } for(i=0;i<100;i++) { proce[last100[i]]++; } Cli(); for(i=0;i<65;i++) { PROCESS* p=GetProcessByPID(i); if(p->free==0) { itoa2(i,Mensaje); message(Mensaje,salto,0); itoa2(proce[i],Mensaje); message(Mensaje,salto,28); itoa2(p->tty,Mensaje); message(Mensaje,salto,56); message(p->name,salto,78); salto=salto+1; } message(" ",salto,0); } if (argc>1) i=atoi2(argv[1]); else i=0; Sti(); Sleep(i); } return 0; }
int main(void) { char line[MAX_LINE_LEN]; char a1[] = "283472"; char a2[] = "28.3472"; char num[MAX_LINE_LEN]; getline2(line); printf("%s\n", line); printf("a=%s, i=%d\n", a1, atoi2(a1)); printf("a=%s, i=%d\n", a2, atoi2(a2)); itoa2(1, num, 10); printf("%s\n", num); itoa2(12, num, 10); printf("%s\n", num); itoa2(-12, num, 10); printf("%s\n", num); char s0[] = ""; char s1[] = "1"; char s2[] = "12"; char s3[] = "123"; reverse(s0); printf("%s\n", s0); reverse(s1); printf("%s\n", s1); reverse(s2); printf("%s\n", s2); reverse(s3); printf("%s\n", s3); printf("%d\n", strindex("abc", "")); printf("%d\n", strindex("abc", "a")); printf("%d\n", strindex("abc", "c")); printf("%d\n", strindex("abc", "d")); printf("%d\n", strindex("", "abc")); printf("%d\n", strindex("a", "abc")); return 0; }