Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Exponents: powers of 2: Positive integers to the power of 2: pot=2^n; CREATIVE COMMONS COPYRIGHT LAURI K. FRIBERG 2015. Laskee kahden potensseja, 2^n. Tärkeä binäärijärjestelmän käyttämisessä: "pot.c", fixed further. Korjattu enemmän.
- //how to compile using gcc: "gcc pot.c -o pot". How to run on GNU/POSIX/UNIX/LINUX systems: "./pot".
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main(int argc, char **argv)
- {
- long long int i, x=1ULL, pot;
- puts("CREATIVE COMMONS COPYRIGHT LAURI K. FRIBERG 2015, 2017.");
- printf("Mikä on \"n\" jos x=2^n? ");
- if(argc>=2)
- {
- if(!(strcmp(argv[1],"--help"))||!(strcmp(argv[1],"-h"))||!(strcmp(argv[1],"-?")))
- {
- puts("CREATIVE COMMONS COPYRIGHT LAURI K. FRIBERG 2015, 2017.");
- printf("Kuinka monta kertaa toistetaan operaatio? mMnenteen potenssiin haluat laskea 2^n? ");
- printf("Kuinka monta kakkosta haluat? 2*2*2*...*2. Mikä on \"n\" jos x=2^n?\n\n");
- exit(1);
- }
- }
- if(argc>=2) { pot = atoi(argv[1]); }
- if(argc<=1)
- {
- printf("\nMikä on suurin laskurin n arvo eli kahden potenssi? ");
- scanf("%llu", &pot);
- }
- if (pot<0)
- {
- puts("");
- fprintf(stderr,"ERROR NUMBER 013: \"NEGATIVE NUMBER INPUT\": RETCODE 13: Varoitus! Laittamasi potenssi on negatiivinen numero, eli alle");
- fprintf(stderr," nollan (pot<0): älä anna tällaisia numeroita enää, kiitos. Ole kiltti ja laita seuraavalla ajokerralla nollaa suurempi,");
- fprintf(stderr," eli positiivinen luku.\n\n");
- exit(13);
- }
- if (pot==0)
- { puts(""); puts("2⁰==1"); exit(0); }
- else if (pot==1)
- { puts(""); puts("2⁰==1"); puts("2¹==2"); exit(0); }
- else if (pot==2)
- { puts(""); puts("2⁰==1"); puts("2¹==2"); puts("2²==4"); exit(0); }
- else if (pot==3)
- { puts(""); puts("2⁰==1"); puts("2¹==2"); puts("2²==4"); puts("2³==8"); exit(0); }
- puts("");
- for (i=0ULL; i<=pot; i++)
- { printf("2^%llu==%llu\n", i, x); x=2*x; }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement