Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- n-th_root_v1.c by Dragan Milicev
- for Dan Sanchez It-it
- https://web.facebook.com/danzkie8888
- Task:
- https://web.facebook.com/photo.php?fbid=987931031542534&set=p.987931031542534&type=3&theater
- The task is vague and confusing.
- What is int& k and int &p in
- double findK(int& k, int &p) ?
- Why does a function get an argument k when it should return a value of k ?
- 3 ^ 23 != 12167
- Arguments should be pointers to n and p.
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- double findK_no_pointers( int n, int p )
- {
- int res=n;
- double k=0.0;
- while( res <= p )
- {
- res = res * n;
- k++;
- }
- return k;
- }
- double findK( int *n, int *p )
- {
- int res=*n;
- double k=0.0;
- while( res <= *p )
- {
- res = res * (*n);
- k++;
- }
- return k;
- }
- int main(void)
- {
- int n, p;
- double k;
- printf("\n Enter n = ");
- scanf("%d",&n);
- printf("\n Enter p = ");
- scanf("%d",&p);
- if( n<1 || p<1)
- {
- printf("\n n and p must be greater than or equal to 1 \n\n");
- return 1;
- }
- k = findK_no_pointers( n, p );
- printf("\n findK_no_pointers(), Result is k = %.0f \n\n", k);
- k = findK( &n, &p );
- printf("\n findK(), Result is k = %.0f \n\n", k);
- return 0;
- }
Advertisement
RAW Paste Data
Copied
Advertisement