diff --git a/p1debuglog.txt b/p1debuglog.txt index e69de29b..42e16184 100644 --- a/p1debuglog.txt +++ b/p1debuglog.txt @@ -0,0 +1,69 @@ + gdb a.out +GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 +Copyright (C) 2018 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. Type "show copying" +and "show warranty" for details. +This GDB was configured as "x86_64-linux-gnu". +Type "show configuration" for configuration details. +For bug reporting instructions, please see: +. +Find the GDB manual and other documentation resources online at: +. +For help, type "help". +Type "apropos word" to search for commands related to "word"... +Reading symbols from a.out...done. +(gdb) b main +Breakpoint 1 at 0x7fc: file p1final.c, line 16. +(gdb) r +Starting program: /home/runner/pps-IA1-practice-2/a.out +warning: Error disabling address space randomization: Operation not permitted + +Breakpoint 1, main () at p1final.c:16 +16 { +(gdb) s +18 input(&a,&b); +(gdb) s +input (a=0x7fff68a0d02c, b=0x7fff68a0d030) at p1final.c:4 +4 printf("enter the 2 numbers\n"); +(gdb) n +enter the 2 numbers +5 scanf("%d%d",&*a,&*b); +(gdb) n +3 +6 +6 } +(gdb) p a +$1 = (int *) 0x7fff68a0d02c +(gdb) p b +$2 = (int *) 0x7fff68a0d030 +(gdb) n +main () at p1final.c:19 +19 add(a,b,&sum); +(gdb) p a +$3 = 3 +(gdb) p b +$4 = 6 +(gdb) s +add (a=3, b=6, sum=0x7fff68a0d034) at p1final.c:9 +9 *sum=a+b; +(gdb) n +10 } +(gdb) n +main () at p1final.c:20 +20 output(a,b,sum); +(gdb) p sum +$5 = 9 +(gdb) s +output (a=3, b=6, sum=9) at p1final.c:13 +13 printf("sum of %d + %d is %d",a,b,sum); +(gdb) n +14 } +(gdb) n +main () at p1final.c:21 +21 } +(gdb) c +Continuing. +sum of 3 + 6 is 9[Inferior 1 (process 112) exited normally] +(gdb) q \ No newline at end of file diff --git a/p1final.c b/p1final.c index e69de29b..69165c9a 100644 --- a/p1final.c +++ b/p1final.c @@ -0,0 +1,21 @@ +#include +void input(int *a,int *b) +{ + printf("enter the 2 numbers\n"); + scanf("%d%d",&*a,&*b); +} +void add(int a,int b,int *sum) +{ + *sum=a+b; +} +void output(int a,int b,int sum) +{ + printf("sum of %d + %d is %d",a,b,sum); +} +int main() +{ + int a,b,sum; + input(&a,&b); + add(a,b,&sum); + output(a,b,sum); +} diff --git a/p1original.c b/p1original.c index 7c111322..69165c9a 100644 --- a/p1original.c +++ b/p1original.c @@ -1,2 +1,21 @@ - -} \ No newline at end of file +#include +void input(int *a,int *b) +{ + printf("enter the 2 numbers\n"); + scanf("%d%d",&*a,&*b); +} +void add(int a,int b,int *sum) +{ + *sum=a+b; +} +void output(int a,int b,int sum) +{ + printf("sum of %d + %d is %d",a,b,sum); +} +int main() +{ + int a,b,sum; + input(&a,&b); + add(a,b,&sum); + output(a,b,sum); +} diff --git a/p2debuglog.txt b/p2debuglog.txt index e69de29b..723e0245 100644 --- a/p2debuglog.txt +++ b/p2debuglog.txt @@ -0,0 +1,95 @@ + gdb a.out +GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 +Copyright (C) 2018 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. Type "show copying" +and "show warranty" for details. +This GDB was configured as "x86_64-linux-gnu". +Type "show configuration" for configuration details. +For bug reporting instructions, please see: +. +Find the GDB manual and other documentation resources online at: +. +For help, type "help". +Type "apropos word" to search for commands related to "word"... +Reading symbols from a.out...done. +(gdb) b main +Breakpoint 1 at 0x839: file p2final.c, line 19. +(gdb) r +Starting program: /home/runner/pps-IA1-practice-2/a.out +warning: Error disabling address space randomization: Operation not permitted + +Breakpoint 1, main () at p2final.c:19 +19 int a=input(); +(gdb) s +input () at p2final.c:3 +3 { +(gdb) n +5 printf("enter the number\n"); +(gdb) n +enter the number +6 scanf("%d",&a); +(gdb) n +90 +7 return a; +(gdb) n +8 } +(gdb) n +main () at p2final.c:20 +20 int b=input(); +(gdb) p a +$1 = 90 +(gdb) s +input () at p2final.c:3 +3 { +(gdb) n +5 printf("enter the number\n"); +(gdb) n +enter the number +6 scanf("%d",&a); +(gdb) n +56 +7 return a; +(gdb) n +8 } +(gdb) n +main () at p2final.c:21 +21 int c=input(); +(gdb) s +input () at p2final.c:3 +3 { +(gdb) n +5 printf("enter the number\n"); +(gdb) n +enter the number +6 scanf("%d",&a); +(gdb) n +10 +7 return a; +(gdb) n +8 } +22 int largest=cmp(a,b,c); +(gdb) s +cmp (a=90, b=56, c=10) at p2final.c:11 +11 return a>b?a>c?a:c:b>a?b>c?b:c:a; +(gdb) n +12 } +(gdb) n +main () at p2final.c:23 +23 output(a,b,c,largest); +(gdb) p largest +$3 = 90 +(gdb) s +output (a=90, b=56, c=10, largest=90) at p2final.c:15 +15 printf("the largest number of %d %d and %d is %d\n",a,b,c,largest); +(gdb) n +the largest number of 90 56 and 10 is 90 +16 } +(gdb) n +main () at p2final.c:24 +24 } +(gdb) c +Continuing. +[Inferior 1 (process 185) exited normally] +(gdb) q \ No newline at end of file diff --git a/p2final.c b/p2final.c index e69de29b..be6f563d 100644 --- a/p2final.c +++ b/p2final.c @@ -0,0 +1,24 @@ +#include +int input() +{ + int a; + printf("enter the number\n"); + scanf("%d",&a); + return a; +} +int cmp(int a,int b,int c) +{ + return a>b?a>c?a:c:b>a?b>c?b:c:a; +} +void output(int a,int b,int c,int largest) +{ + printf("the largest number of %d %d and %d is %d\n",a,b,c,largest); +} +int main() +{ + int a=input(); + int b=input(); + int c=input(); + int largest=cmp(a,b,c); + output(a,b,c,largest); +} diff --git a/p2original.c b/p2original.c index e69de29b..4a211811 100644 --- a/p2original.c +++ b/p2original.c @@ -0,0 +1,37 @@ +#include +int input() +{ + int a; + printf("enter the number\n"); + scanf("%d",&a); + return a; +} +int cmp(int a,int b,int c) +{ + if(ac) + return a; + else + return c; + } +} +void output(int a,int b,int c,int largest) +{ + printf("the largest number of %d %d and %d is %d\n",a,b,c,largest); +} +int main() +{ + int a=input(); + int b=input(); + int c=input(); + int largest=cmp(a,b,c); + output(a,b,c,largest); +} diff --git a/p3debuglog.txt b/p3debuglog.txt index e69de29b..11e4f7e5 100644 --- a/p3debuglog.txt +++ b/p3debuglog.txt @@ -0,0 +1,108 @@ + gdb a.out +GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 +Copyright (C) 2018 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. Type "show copying" +and "show warranty" for details. +This GDB was configured as "x86_64-linux-gnu". +Type "show configuration" for configuration details. +For bug reporting instructions, please see: +. +Find the GDB manual and other documentation resources online at: +. +For help, type "help". +Type "apropos word" to search for commands related to "word"... +Reading symbols from a.out...done. +(gdb) b main +Breakpoint 1 at 0x83d: file p3final.c, line 23. +(gdb) r +Starting program: /home/runner/pps-IA1-practice-2/a.out +warning: Error disabling address space randomization: Operation not permitted + +Breakpoint 1, main () at p3final.c:23 +23 printf("enter the limit\n"); +(gdb) n +enter the limit +24 int n=input_n(); +(gdb) s +input_n () at p3final.c:3 +3 { +(gdb) n +5 scanf("%d",&a); +(gdb) 3 +Undefined command: "3". Try "help". +(gdb) n +3 +6 return a; +(gdb) n +7 } +(gdb) n +main () at p3final.c:25 +25 int sum=sum_n(n); +(gdb) p n +$1 = 3 +(gdb) s +sum_n (n=3) at p3final.c:10 +10 int sum=0; +(gdb) n +11 for(int i=1;i<=n;i++) +(gdb) p i +$2 = 1574748203 +(gdb) n +12 sum=sum+i; +(gdb) p i +$3 = 1 +(gdb) n +11 for(int i=1;i<=n;i++) +(gdb) p sum +$4 = 1 +(gdb) n +12 sum=sum+i; +(gdb) p i +$5 = 2 +(gdb) n +11 for(int i=1;i<=n;i++) +(gdb) p sum +$6 = 3 +(gdb) n +12 sum=sum+i; +(gdb) p i +$7 = 3 +(gdb) n +11 for(int i=1;i<=n;i++) +(gdb) n +13 return sum; +(gdb) p sum +$8 = 6 +(gdb) n +14 } +(gdb) n +main () at p3final.c:26 +26 output(n,sum); +(gdb) s +output (n=3, sum=6) at p3final.c:17 +17 for(int i=1;i +int input_n() +{ + int a; + scanf("%d",&a); + return a; +} +int sum_n(int n) +{ + int sum=0; + for(int i=1;i<=n;i++) + sum=sum+i; + return sum; +} +void output(int n,int sum) +{ + for(int i=1;i +int input_n() +{ + int a; + scanf("%d",&a); + return a; +} +int sum_n(int n) +{ + int sum=0; + for(int i=1;i<=n;i++) + sum=sum+i; + return sum; +} +void output(int n,int sum) +{ + for(int i=1;i +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. Type "show copying" +and "show warranty" for details. +This GDB was configured as "x86_64-linux-gnu". +Type "show configuration" for configuration details. +For bug reporting instructions, please see: +. +Find the GDB manual and other documentation resources online at: +. +For help, type "help". +Type "apropos word" to search for commands related to "word"... +Reading symbols from a.out...done. +(gdb) b main +Breakpoint 1 at 0x8d9: file p4final.c, line 31. +(gdb) r +Starting program: /home/runner/pps-IA1-practice-2/a.out +warning: Error disabling address space randomization: Operation not permitted + +Breakpoint 1, main () at p4final.c:31 +31 { +(gdb) n +32 printf("enter the array size\n"); +(gdb) n +enter the array size +33 int n=input_array_size(); +(gdb) s +input_array_size () at p4final.c:3 +3 { +(gdb) n +5 scanf("%d",&a); +(gdb) n +3 +6 return a; +(gdb) n +7 } +(gdb) n +main () at p4final.c:34 +34 int a[n]; +(gdb) p n +$1 = 3 +(gdb) n +35 printf("enter the array\n"); +(gdb) n +enter the array +36 input_array(n,a); +(gdb) s +input_array (n=3, a=0x7ffd183c1870) at p4final.c:10 +10 for(int i=0;i +int input_array_size() +{ + int a; + scanf("%d",&a); + return a; +} +void input_array(int n, int a[n]) +{ + for(int i=0;i +int input_array_size() +{ + int a; + scanf("%d",&a); + return a; +} +void input_array(int n, int a[n]) +{ + for(int i=0;i +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. Type "show copying" +and "show warranty" for details. +This GDB was configured as "x86_64-linux-gnu". +Type "show configuration" for configuration details. +For bug reporting instructions, please see: +. +Find the GDB manual and other documentation resources online at: +. +For help, type "help". +Type "apropos word" to search for commands related to "word"... +Reading symbols from a.out...done. +(gdb) b main +Breakpoint 1 at 0x884: file p5final.c, line 25. +(gdb) r +Starting program: /home/runner/pps-IA1-practice-2/a.out +warning: Error disabling address space randomization: Operation not permitted + +Breakpoint 1, main () at p5final.c:25 +25 printf("enter the number\n"); +(gdb) n +enter the number +26 float n=input(); +(gdb) s +input () at p5final.c:3 +3 { +(gdb) n +5 scanf("%f",&a); +(gdb) n +5 +6 return a; +(gdb) p a +$1 = 5 +(gdb) n +7 } +(gdb) n +main () at p5final.c:27 +27 output(n,my_sqrt(n)); +(gdb) p n +$2 = 5 +(gdb) s +my_sqrt (n=5) at p5final.c:10 +10 float x=0.5*(4+n/4); +(gdb) n +11 float a=x+1; +(gdb) p x +$3 = 2.625 +(gdb) n +12 while(a-x>0.00001) +(gdb) p a +$4 = 3.625 +(gdb) n +14 a=x; +(gdb) n +15 x=0.5*(x+n/x); +(gdb) p a +$5 = 2.625 +(gdb) n +12 while(a-x>0.00001) +(gdb) p x +$6 = 2.2648809 +(gdb) n +14 a=x; +(gdb) n +15 x=0.5*(x+n/x); +(gdb) p a +$7 = 2.2648809 +(gdb) n +12 while(a-x>0.00001) +(gdb) p x +$8 = 2.23625135 +(gdb) n +14 a=x; +(gdb) n +15 x=0.5*(x+n/x); +(gdb) p a +$9 = 2.23625135 +(gdb) n +12 while(a-x>0.00001) +(gdb) p x +$10 = 2.23606801 +(gdb) n +14 a=x; +(gdb) n +15 x=0.5*(x+n/x); +(gdb) p a +$11 = 2.23606801 +(gdb) n +12 while(a-x>0.00001) +(gdb) p x +$12 = 2.23606801 +(gdb) n +17 return x; +(gdb) n +18 } +(gdb) s +output (n=5, sqrt_result=2.23606801) at p5final.c:21 +21 printf("Square root of %f is %f",n,sqrt_result); +(gdb) n +22 } +(gdb) n +main () at p5final.c:28 +28 } +(gdb) c +Continuing. +Square root of 5.000000 is 2.236068[Inferior 1 (process 186) exited normally] +(gdb) q + diff --git a/p5final.c b/p5final.c index e69de29b..759e287a 100644 --- a/p5final.c +++ b/p5final.c @@ -0,0 +1,28 @@ +#include +float input() +{ + float a; + scanf("%f",&a); + return a; +} +float my_sqrt(float n) +{ + float x=0.5*(4+n/4); + float a=x+1; + while(a-x>0.00001) + { + a=x; + x=0.5*(x+n/x); + } + return x; +} +void output(float n, float sqrt_result) +{ + printf("Square root of %f is %f",n,sqrt_result); +} +int main() +{ + printf("enter the number\n"); + float n=input(); + output(n,my_sqrt(n)); +} diff --git a/p5original.c b/p5original.c index e69de29b..ae7fce63 100644 --- a/p5original.c +++ b/p5original.c @@ -0,0 +1,28 @@ +#include +float input() +{ + float a; + scanf("%f",&a); + return a; +} +float my_sqrt(float n) +{ + float x=0.5*(2+n/2); + float a=x+1; + while(a-x>0.00001) + { + a=x; + x=0.5*(x+n/x); + } + return x; +} +void output(float n, float sqrt_result) +{ + printf("Square root of %f is %f",n,sqrt_result); +} +int main() +{ + printf("enter the number\n"); + float n=input(); + output(n,my_sqrt(n)); +} diff --git a/p6debuglog.txt b/p6debuglog.txt index e69de29b..f66ac33d 100644 --- a/p6debuglog.txt +++ b/p6debuglog.txt @@ -0,0 +1,130 @@ + gdb a.out +GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 +Copyright (C) 2018 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. Type "show copying" +and "show warranty" for details. +This GDB was configured as "x86_64-linux-gnu". +Type "show configuration" for configuration details. +For bug reporting instructions, please see: +. +Find the GDB manual and other documentation resources online at: +. +For help, type "help". +Type "apropos word" to search for commands related to "word"... +Reading symbols from a.out...done. +(gdb) b main +Breakpoint 1 at 0x92f: file p6final.c, line 41. +(gdb) r +Starting program: /home/runner/pps-IA1-practice-2/a.out +warning: Error disabling address space randomization: Operation not permitted + +Breakpoint 1, main () at p6final.c:41 +41 { +(gdb) n +43 input_two_string(a,b); +(gdb) s +input_two_string (a=0x7fffe7638030 "\001", + b=0x7fffe7638050 "\240\t਼U") at p6final.c:4 +4 printf("enter the two strings\n"); +(gdb) n +enter the two strings +5 scanf("%s",a); +(gdb) n +hi +6 scanf("%s",b); +(gdb) n +good +7 } +(gdb) n +main () at p6final.c:44 +44 output(a,b,strcmp(a,b)); +(gdb) s +strcmp (a=0x7fffe7638030 "hi", b=0x7fffe7638050 "good") at p6final.c:10 +10 int z=0,w=0; +(gdb) n +11 for(int i=0;a[i]!='\0'|| b[i]!='\0';i++) +(gdb) n +13 if(a[i]==b[i]) +(gdb) p a[0] +$1 = 104 'h' +(gdb) p b[0] +$2 = 103 'g' +(gdb) n +18 else if(a[i]>b[i]) +(gdb) n +19 z++; +(gdb) n +11 for(int i=0;a[i]!='\0'|| b[i]!='\0';i++) +(gdb) p z +$3 = 1 +(gdb) n +13 if(a[i]==b[i]) +(gdb) p a[1] +$4 = 105 'i' +(gdb) p b[1] +$5 = 111 'o' +(gdb) n +18 else if(a[i]>b[i]) +(gdb) n +21 w++; +(gdb) n +11 for(int i=0;a[i]!='\0'|| b[i]!='\0';i++) +(gdb) p z +$6 = 1 +(gdb) p w +$7 = 1 +(gdb) n +13 if(a[i]==b[i]) +(gdb) p a[2] +$8 = 0 '\000' +(gdb) p b[2] +$9 = 111 'o' +(gdb) n +18 else if(a[i]>b[i]) +(gdb) n +21 w++; +(gdb) n +11 for(int i=0;a[i]!='\0'|| b[i]!='\0';i++) +(gdb) p z +$10 = 1 +(gdb) p w +$11 = 2 +(gdb) n +13 if(a[i]==b[i]) +(gdb) p b[3] +$12 = 0 'd' +(gdb) n +18 else if(a[i]>b[i]) +(gdb) n +21 w++; +(gdb) n +11 for(int i=0;a[i]!='\0'|| b[i]!='\0';i++) +(gdb) p z +$13 = 1 +(gdb) p w +$14 = 3 +(gdb) n +23 if(z>w) +(gdb) n +25 else if(z==w) +(gdb) n +28 return -1; +(gdb) n +30 } +(gdb) s +output (a=0x7fffe7638030 "hi", b=0x7fffe7638050 "good", result=-1) + at p6final.c:33 +33 if(result<0) +(gdb) n +34 printf("%s is greater than %s",b,a); +(gdb) n +39 } +(gdb) n +main () at p6final.c:45 +45 } +(gdb) c +Continuing. +good is greater than hi[Inferior 1 (process 334) exited normally] +(gdb) q \ No newline at end of file diff --git a/p6final.c b/p6final.c index e69de29b..71d3dd34 100644 --- a/p6final.c +++ b/p6final.c @@ -0,0 +1,45 @@ +#include +void input_two_string(char *a, char *b) +{ + printf("enter the two strings\n"); + scanf("%s",a); + scanf("%s",b); +} +int strcmp(char *a, char *b) +{ + int z=0,w=0; + for(int i=0;a[i]!='\0'|| b[i]!='\0';i++) + { + if(a[i]==b[i]) + { + z++; + w++; + } + else if(a[i]>b[i]) + z++; + else + w++; + } + if(z>w) + return 1; + else if(z==w) + return 0; + else + return -1; + +} +void output(char *a, char *b, int result) +{ + if(result<0) + printf("%s is greater than %s",b,a); + else if(result>0) + printf("%s is greater than %s",a,b); + else + printf("%s is equal to %s",a,b); +} +int main() +{ + char a[20],b[20]; + input_two_string(a,b); + output(a,b,strcmp(a,b)); +} diff --git a/p6original.c b/p6original.c index e69de29b..c221e21f 100644 --- a/p6original.c +++ b/p6original.c @@ -0,0 +1,46 @@ +#include +void input_two_string(char *a, char *b) +{ + printf("enter the two strings\n"); + scanf("%s",a); + scanf("%s",b); +} +int strcmp(char *a, char *b) +{ + int x=0,y=0; + for(int i=0;a[i]!='\0'|| b[i]!='\0';i++) + { + if(a[i]==b[i]) + { + x++; + y++; + } + else if(a[i]>b[i]) + x++; + else + y++; + } + printf("%d %d",x,y); + if(x>y) + return 1; + else if(x==y) + return 0; + else + return -1; + +} +void output(char *a, char *b, int result) +{ + if(result<0) + printf("%s is greater than %s",b,a); + else if(result>0) + printf("%s is greater than %s",a,b); + else + printf("%s is equal to %s",a,b); +} +int main() +{ + char a[20],b[20]; + input_two_string(a,b); + output(a,b,strcmp(a,b)); +} diff --git a/p7debuglog.txt b/p7debuglog.txt index e69de29b..22921603 100644 --- a/p7debuglog.txt +++ b/p7debuglog.txt @@ -0,0 +1,86 @@ + gdb a.out +GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 +Copyright (C) 2018 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. Type "show copying" +and "show warranty" for details. +This GDB was configured as "x86_64-linux-gnu". +Type "show configuration" for configuration details. +For bug reporting instructions, please see: +. +Find the GDB manual and other documentation resources online at: +. +For help, type "help". +Type "apropos word" to search for commands related to "word"... +Reading symbols from a.out...done. +(gdb) b main +Breakpoint 1 at 0x87c: file p7final.c, line 27. +(gdb) r +Starting program: /home/runner/pps-IA1-practice-2/a.out +warning: Error disabling address space randomization: Operation not permitted + +Breakpoint 1, main () at p7final.c:27 +27 Complex a=input_complex(); +(gdb) s +input_complex () at p7final.c:8 +8 { +(gdb) n +10 printf("enter the complex numbers in format a+bi\n"); +(gdb) n +enter the complex numbers in format a+bi +11 scanf("%f %*c %f %*c",&a.real,&a.imaginary); +(gdb) n +3+4i +12 return a; +(gdb) n +13 } +(gdb) n +main () at p7final.c:28 +28 Complex b=input_complex(); +(gdb) p a +$1 = {real = 3, imaginary = 4} +(gdb) s +input_complex () at p7final.c:8 +8 { +(gdb) n +10 printf("enter the complex numbers in format a+bi\n"); +(gdb) n +enter the complex numbers in format a+bi +11 scanf("%f %*c %f %*c",&a.real,&a.imaginary); +(gdb) n +5+2i +12 return a; +(gdb) n +13 } +(gdb) n +main () at p7final.c:29 +29 Complex c=add(a,b); +(gdb) p b +$2 = {real = 5, imaginary = 2} +(gdb) s +add (a=..., b=...) at p7final.c:17 +17 c.real=a.real+b.real; +(gdb) n +18 c.imaginary=a.imaginary+b.imaginary; +(gdb) n +19 return c; +(gdb) p c +$3 = {real = 8, imaginary = 6} +(gdb) n +20 } +(gdb) n +main () at p7final.c:30 +30 output(a,b,c); +(gdb) s +output (a=..., b=..., c=...) at p7final.c:23 +23 printf("(%0.0f+%0.0fi)+(%0.0f+%0.0fi)=(%0.0f+%0.0fi)",a.real,b.imaginary,b.real,a.imaginary,c.real,c.imaginary); +(gdb) n +24 } +(gdb) n +main () at p7final.c:31 +31 } +(gdb) c +Continuing. +(3+2i)+(5+4i)=(8+6i)[Inferior 1 (process 413) exited normally] +(gdb) q \ No newline at end of file diff --git a/p7final.c b/p7final.c index e69de29b..f72b1a64 100644 --- a/p7final.c +++ b/p7final.c @@ -0,0 +1,31 @@ +#include +struct _complex +{ +float real,imaginary; +}; +typedef struct _complex Complex; +Complex input_complex() +{ + Complex a; + printf("enter the complex numbers in format a+bi\n"); + scanf("%f %*c %f %*c",&a.real,&a.imaginary); + return a; +} +Complex add(Complex a, Complex b) +{ + Complex c; + c.real=a.real+b.real; + c.imaginary=a.imaginary+b.imaginary; + return c; +} +void output(Complex a, Complex b, Complex c) +{ + printf("(%0.0f+%0.0fi)+(%0.0f+%0.0fi)=(%0.0f+%0.0fi)",a.real,b.imaginary,b.real,a.imaginary,c.real,c.imaginary); +} +int main() +{ + Complex a=input_complex(); + Complex b=input_complex(); + Complex c=add(a,b); + output(a,b,c); +} diff --git a/p7original.c b/p7original.c index e69de29b..d54edcce 100644 --- a/p7original.c +++ b/p7original.c @@ -0,0 +1,31 @@ +#include +struct _complex +{ +float real,imaginary; +}; +typedef struct _complex Complex; +Complex input_complex() +{ + Complex a; + printf("enter the complex numbers in format a+bi\n"); + scanf("%f + %f i",&a.real,&a.imaginary); + return a; +} +Complex add(Complex a, Complex b) +{ + Complex c; + c.real=a.real+b.real; + c.imaginary=a.imaginary+b.imaginary; + return c; +} +void output(Complex a, Complex b, Complex c) +{ + printf("(%f+%fi)+(%f+%fi)=(%f+%fi)",a.real,b.imaginary,b.real,a.imaginary,c.real,c.imaginary); +} +int main() +{ + Complex a=input_complex(); + Complex b=input_complex(); + Complex c=add(a,b); + output(a,b,c); +} diff --git a/p8debuglog.txt b/p8debuglog.txt index e69de29b..ae93f48a 100644 --- a/p8debuglog.txt +++ b/p8debuglog.txt @@ -0,0 +1,141 @@ + gdb a.out +GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 +Copyright (C) 2018 Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. Type "show copying" +and "show warranty" for details. +This GDB was configured as "x86_64-linux-gnu". +Type "show configuration" for configuration details. +For bug reporting instructions, please see: +. +Find the GDB manual and other documentation resources online at: +. +For help, type "help". +Type "apropos word" to search for commands related to "word"... +Reading symbols from a.out...done. +(gdb) b main +Breakpoint 1 at 0x9cd: file p8final.c, line 46. +(gdb) r +Starting program: /home/runner/pps-IA1-practice-2/a.out +warning: Error disabling address space randomization: Operation not permitted + +Breakpoint 1, main () at p8final.c:46 +46 { +(gdb) n +47 printf("enter the limit\n"); +(gdb) n +enter the limit +48 int n=get_n(); +(gdb) s +get_n () at p8final.c:8 +8 { +(gdb) n +10 scanf("%d",&a); +(gdb) n +2 +11 return a; +(gdb) n +12 } +(gdb) n +main () at p8final.c:49 +49 Complex c[n]; +(gdb) p n +$1 = 2 +(gdb) n +50 input_n_complex(n,c); +(gdb) s +input_n_complex (n=2, c=0x7ffdfc892340) at p8final.c:16 +16 printf("enter the complex numbers in format a+bi\n"); +(gdb) n +enter the complex numbers in format a+bi +17 for(int i=0;i +struct _complex +{ +float real,imaginary; +}; +typedef struct _complex Complex; +int get_n() +{ + int a; + scanf("%d",&a); + return a; +} +void input_n_complex(int n, Complex c[n]) +{ + Complex a; + printf("enter the complex numbers in format a+bi\n"); + for(int i=0;i +struct _complex +{ +float real,imaginary; +}; +typedef struct _complex Complex; +int get_n() +{ + int a; + scanf("%d",&a); + return a; +} +void input_n_complex(int n, Complex c[n]) +{ + Complex a; + printf("enter the complex numbers in format a+bi\n"); + for(int i=0;i