From e9a2b40da6576c83a99de88cdede2d3751442289 Mon Sep 17 00:00:00 2001 From: keshavgarg23 Date: Wed, 16 Dec 2020 21:50:38 +0530 Subject: [PATCH 1/2] correct all hards --- ...1).c => correct author-JASKIRAT SINGH(1).c | 91 ++++++++++--------- ...).c => corrected author-PALAK AGRAWAL(1).c | 36 ++++---- ....c => corrected author-PRAGYA NAINWAL(1).c | 60 ++++++------ 3 files changed, 96 insertions(+), 91 deletions(-) rename author-JASKIRAT SINGH(1).c => correct author-JASKIRAT SINGH(1).c (81%) rename author-PALAK AGRAWAL(1).c => corrected author-PALAK AGRAWAL(1).c (59%) rename author-PRAGYA NAINWAL(1).c => corrected author-PRAGYA NAINWAL(1).c (79%) diff --git a/author-JASKIRAT SINGH(1).c b/correct author-JASKIRAT SINGH(1).c similarity index 81% rename from author-JASKIRAT SINGH(1).c rename to correct author-JASKIRAT SINGH(1).c index 9cd43ba..8de65e7 100644 --- a/author-JASKIRAT SINGH(1).c +++ b/correct author-JASKIRAT SINGH(1).c @@ -1,45 +1,46 @@ -#include - -void transpose(int arr[][],int n) -{ - int tra[n][n],i,j; - for(i=0;i + +int n; +void transpose(int arr[][n]) +{ + int tra[n][n],i,j; + for(i=0;i -int main() -{ - int arr={23,45,132,90,345,1,45,8}; - int sum=sum_arr(arr[],8); - printf("Sum=%d",sum); - return 0; -} -int sum_arr(int arr[],int n) -{ - int sum; - for(i=0;i + +int sum_arr(int arr[],int n); +int main() +{ + int arr[]={23,45,132,90,345,1,45,8}; + int sum=sum_arr(arr,8); + printf("Sum=%d",sum); + return 0; +} +int sum_arr(int arr[],int n) +{ + int sum=0,i; + for(i=0;i -int main() -{ - #define MAX 100 - char str1[MAX],*revstr; - printf("\n\n Recursion : Get reverse of a string :\n"); - printf("------------------------------------------\n"); - - printf(" Input any string: "); - scanf("%s",&str1); - - revstr = ReverseOfString(str1);//call the function ReverseOfString - - printf(" The reversed string is: %s\n\n",revstr); - return 0; -} -char ReverseOfString(char str1[]) -{ - static int i=0; - static char revstr[MAX]; - if(*str1) - { - ReverseOfString(str1+1);//calling the function ReverseOfString itself - revstr[i=+1] = *str1; - } - return revstr; -} - - +#include +#define MAX 100 + +char* ReverseOfString(char str1[]); +int main() +{ + char str1[MAX],*revstr; + printf("\n\n Recursion : Get reverse of a string :\n"); + printf("------------------------------------------\n"); + + printf(" Input any string: "); + scanf("%s",str1); + + revstr = ReverseOfString(str1);//call the function ReverseOfString + + printf(" The reversed string is: %s\n\n",revstr); + return 0; +} +char* ReverseOfString(char str1[]) +{ + static int i=0; + static char revstr[MAX]; + if(*str1) + { + ReverseOfString(str1+1);//calling the function ReverseOfString itself + revstr[i++] = *str1; + } + return revstr; +} + + From 43f2171c1b4b73553f2fc3595bbfa2763c9f4bf3 Mon Sep 17 00:00:00 2001 From: keshavgarg23 Date: Wed, 16 Dec 2020 22:53:30 +0530 Subject: [PATCH 2/2] corrected all mediums --- author- RIYA SINGHAL(4).c | 18 ---- author-PRAGYA NAINWAL(2).c | 6 +- ...).c => corrected author- RIYA SINGHAL(3).c | 4 +- corrected author- RIYA SINGHAL(4).c | 18 ++++ ...).c => corrected author- RIYA SINGHAL(5).c | 4 +- ...-ALI RAZA.c => corrected author-ALI RAZA.c | 34 +++---- ...DER(2).c => corrected author-ALWINDER(2).c | 16 ++-- ...AT(1).c => corrected author-GURSANGAT(1).c | 45 +++++---- ...N(1).c => corrected author-HIYA MADAN(1).c | 95 ++++++++++--------- ...N(2).c => corrected author-HIYA MADAN(2).c | 36 +++---- ...).c => corrected author-SANCHAY JOSHI(1).c | 8 +- 11 files changed, 145 insertions(+), 139 deletions(-) delete mode 100644 author- RIYA SINGHAL(4).c rename author- RIYA SINGHAL(3).c => corrected author- RIYA SINGHAL(3).c (56%) create mode 100644 corrected author- RIYA SINGHAL(4).c rename author- RIYA SINGHAL(5).c => corrected author- RIYA SINGHAL(5).c (62%) rename author-ALI RAZA.c => corrected author-ALI RAZA.c (56%) rename author-ALWINDER(2).c => corrected author-ALWINDER(2).c (70%) rename author-GURSANGAT(1).c => corrected author-GURSANGAT(1).c (74%) rename author-HIYA MADAN(1).c => corrected author-HIYA MADAN(1).c (93%) rename author-HIYA MADAN(2).c => corrected author-HIYA MADAN(2).c (84%) rename author-SANCHAY JOSHI(1).c => corrected author-SANCHAY JOSHI(1).c (73%) diff --git a/author- RIYA SINGHAL(4).c b/author- RIYA SINGHAL(4).c deleted file mode 100644 index 7ae8bb8..0000000 --- a/author- RIYA SINGHAL(4).c +++ /dev/null @@ -1,18 +0,0 @@ - -#include - -int main() -{ - int x=10; - for(int i=0;i<5;i-=1)//INFINITE LOOP - { - int x=9; - printf("the value of x variable is %d",x); - - } - char x;//ALREADY DECLARED ABOVE - printf("enter any character"); - scanf("%c",&x); - printf("the entered character is %c",x); - return 0; -} diff --git a/author-PRAGYA NAINWAL(2).c b/author-PRAGYA NAINWAL(2).c index b7580be..bbb994e 100644 --- a/author-PRAGYA NAINWAL(2).c +++ b/author-PRAGYA NAINWAL(2).c @@ -1,15 +1,15 @@ #include //Function to calculate the maximum sum of a sub-array of a given array -void maxSumarray(int a, int size){ +int maxSumarray(int a[], int size){ int i; int max_sum_so_far=0; int max_ending_here = 0; - for(i=0,i + +int main() +{ + int x=10; + for(int i=0;i<5;i+=1)//INFINITE LOOP + { + int x=9; + printf("the value of x variable is %d\n",x); + + } + char y;//ALREADY DECLARED ABOVE + printf("enter any character"); + scanf("%c",&y); + printf("the entered character is %c",y); + return 0; +} diff --git a/author- RIYA SINGHAL(5).c b/corrected author- RIYA SINGHAL(5).c similarity index 62% rename from author- RIYA SINGHAL(5).c rename to corrected author- RIYA SINGHAL(5).c index ba959fd..c55e4f4 100644 --- a/author- RIYA SINGHAL(5).c +++ b/corrected author- RIYA SINGHAL(5).c @@ -3,8 +3,8 @@ int main() { int x=10; - for(int i=0;i<5;i-=1){ + for(int i=0;i<5;i+=1){ int x=9; - printf(x);} + printf("%d",x);} return 0; } diff --git a/author-ALI RAZA.c b/corrected author-ALI RAZA.c similarity index 56% rename from author-ALI RAZA.c rename to corrected author-ALI RAZA.c index 665a17d..5c52fec 100644 --- a/author-ALI RAZA.c +++ b/corrected author-ALI RAZA.c @@ -1,17 +1,17 @@ -# include -void fun(int &x) -{ - *x = 30; -} - -int main() -{ - int y = 20; - fun(y); - printf("%d", *y); - return 0; -} - - - - +# include +void fun(int *x) +{ + *x = 30; +} + +int main() +{ + int y = 20; + fun(&y); + printf("%d", y); + return 0; +} + + + + diff --git a/author-ALWINDER(2).c b/corrected author-ALWINDER(2).c similarity index 70% rename from author-ALWINDER(2).c rename to corrected author-ALWINDER(2).c index 8a09f7e..4ae29e5 100644 --- a/author-ALWINDER(2).c +++ b/corrected author-ALWINDER(2).c @@ -1,8 +1,8 @@ -#include -int main(){ - char *ptr = "void pointer"; - void *vptr; - vptr = &ptr; - printf("%s" , **&(char **)vptr); - return 0; -} +#include +int main(){ + char *ptr = "void pointer"; + void *vptr; + vptr = &ptr; + printf("%s" , *(char **)vptr); + return 0; +} diff --git a/author-GURSANGAT(1).c b/corrected author-GURSANGAT(1).c similarity index 74% rename from author-GURSANGAT(1).c rename to corrected author-GURSANGAT(1).c index 1faf009..2b305e5 100644 --- a/author-GURSANGAT(1).c +++ b/corrected author-GURSANGAT(1).c @@ -1,22 +1,25 @@ -# include -int main() -{ - int i = 0; - for (i=0; i<20; i++) - { - switch(i); - { - case 0: - i += 5; - case 1: - i += 2; - case 5: - i += 5; - default: - i += 4; - break; - } - printf("%c "; i); - } - return 0; +# include +int main() +{ + int i = 0; + for (i=0; i<20; i++) + { + switch(i) + { + case 0: + i += 5; + break; + case 1: + i += 2; + break; + case 5: + i += 5; + break; + default: + i += 4; + break; + } + printf("%d ", i); + } + return 0; } \ No newline at end of file diff --git a/author-HIYA MADAN(1).c b/corrected author-HIYA MADAN(1).c similarity index 93% rename from author-HIYA MADAN(1).c rename to corrected author-HIYA MADAN(1).c index 3c7110f..85e2b00 100644 --- a/author-HIYA MADAN(1).c +++ b/corrected author-HIYA MADAN(1).c @@ -1,47 +1,48 @@ -/*A string is entered (For example: My name is jessie.) -Here is C program to get its reverse in a column as output i.e.: -jessie -is -name -My -Debug the following program to get the desired output. -*/ -#include -void main() -{ -char str[20]; -char *ptr=str,*temp; -int i=0,j; -scanf("%[^\n]",str); -while(*ptr) -{ -i++; -ptr++; -} -for(j=0;j -{ - if(*ptr==' ') - { - temp=ptr; - ptr--; - temp++; - while((*temp!=' ')&&(*temp!='\0')) - { - printf("%c",*temp); - temp++; - } - printf("\n"); - } - else - { - ptr--; - } -} -while(*ptr!=' ') -{ -printf("%c",*ptr); -ptr++; -} -getch(); -} - +/*A string is entered (For example: My name is jessie.) +Here is C program to get its reverse in a column as output i.e.: +jessie +is +name +My +Debug the following program to get the desired output. +*/ +#include +#include +void main() +{ +char str[20]; +char *ptr=str,*temp; +int i=0,j; +scanf("%[^\n]",str); +while(*ptr) +{ +i++; +ptr++; +} +for(j=0;j<=i;j++) +{ + if(*ptr==' ') + { + temp=ptr; + ptr--; + temp++; + while((*temp!=' ')&&(*temp!='\0')) + { + printf("%c",*temp); + temp++; + } + printf("\n"); + } + else + { + ptr--; + } +} +while(*ptr!=' ') +{ +printf("%c",*ptr); +ptr++; +} +getch(); +} + diff --git a/author-HIYA MADAN(2).c b/corrected author-HIYA MADAN(2).c similarity index 84% rename from author-HIYA MADAN(2).c rename to corrected author-HIYA MADAN(2).c index ba2f3eb..4637a46 100644 --- a/author-HIYA MADAN(2).c +++ b/corrected author-HIYA MADAN(2).c @@ -1,18 +1,18 @@ -//Pallindrome of a number -#include -#include -void main() -{ - - char *rev; - char str[15]; - scanf("%[^\n]",str); - int i,j; - for(i=strlen(str)-1,j=0;i>=0;i--,j++) - rev[j]=str[i]; - rev[j]='\0'; - if(strcmp(rev,str)) - printf("\nThe string is not a palindrome"); - else - printf("\nThe string is a palindrome"); -} +//Pallindrome of a number +#include +#include +void main() +{ + + char rev[15]; + char str[15]; + scanf("%[^\n]s",str); + int i,j; + for(i=strlen(str)-1,j=0;i>=0;i--,j++) + rev[j]=str[i]; + rev[j]='\0'; + if(strcmp(rev,str)) + printf("\nThe string is not a palindrome"); + else + printf("\nThe string is a palindrome"); +} diff --git a/author-SANCHAY JOSHI(1).c b/corrected author-SANCHAY JOSHI(1).c similarity index 73% rename from author-SANCHAY JOSHI(1).c rename to corrected author-SANCHAY JOSHI(1).c index d32200e..cc690d9 100644 --- a/author-SANCHAY JOSHI(1).c +++ b/corrected author-SANCHAY JOSHI(1).c @@ -2,10 +2,12 @@ int gcd(int a,int b) { - if(b < 0) - return a; + if(b > a) + return gcd(a,b-a); + else if(a>b) + return gcd(a-b,b); else - return gcd(b,a%b); + return a; } int main()