SREE SOWDAMBIKA COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
ZEAL 2K25
CODE DEBUGGING
1) #include <stdio.h> (1 mark)
#include <string.h> Output:
int main() {
margorPC
char s[]="CProgram";
for(int i=strlen(s)-1;i>=0;i--) printf("%c",s[i]);
2) #include <stdio.h> (1 mark)
int main() { Output:
int a[]={3,7,2,9,5}, max=a[0];
M Max = 9
for(int i=1;i<5;i++) if(a[i]>max) max=a[i];
printf("Max = %d\n", max);
3) #include <stdio.h> (1 mark)
int fib(int n){ return (n<=1)?n:fib(n-1)+fib(n-2); } Output:
int main(){ 011235
for(int i=0;i<6;i++) printf("%d ", fib(i));
}
4) #include <stdio.h> (2 mark)
void swap(int *x,int *y){int t=*x;*x=*y;*y=t;} Output:
int main(){
20 10
int a=10,b=20;
swap(&a,&b);printf("%d %d\n",a,b);
5) #include <stdio.h> (2 mark)
int main(){ Output:
char s[]="C is easy";int c=1;for(char *p=s;*p;p++) Words=3
if(*p==' ')c++;printf("Words=%d",c);}
6) #include <stdio.h> (2mark)
#include <string.h> Output:
struct Student{char name[20];int age;} s1,s2; Enter name and age: Copied: Arun 21
int main(){
printf("Enter name and age: ");scanf("%s %d",[Link],&[Link]);
strcpy([Link],[Link]);
[Link]=[Link]; printf("Copied: %s %d",[Link],[Link]);}
7) #include <stdio.h> (2 mark)
int main() {
char ch;printf("Alphabets from A to Z:\n"); Output:
Alphabets from A to Z:
for (ch = 'A'; ch <= 'Z'; ++ch) { printf("%c ", ch); }
ABCDEFGHIJKLMNOPQRSTUVWXYZ
return 0;
}
8) #include <stdio.h> (3 mark)
void hanoi(int n,char A,char B,char C){ Output:
Move disk 1 from A -> C
if(n==0)return;
Move disk 2 from A -> B
hanoi(n-1,A,C,B);
Move disk 1 from C -> B
printf("Move disk %d from %c -> %c\n",n,A,C); Move disk 3 from A -> C
hanoi(n-1,B,A,C);} Move disk 1 from B -> A
Move disk 2 from B -> C
int main()
Move disk 1 from A -> C
{hanoi(3,'A','B','C');}
9) #include <stdio.h> (3 mark)
Transpose:
#include <stdlib.h> Output
12
int main(){
23
int r=2,c=3,*a=malloc(r*sizeof(int));
34
for(int i=0;i<r;i++){a[i]=malloc(c*sizeof(int));for(int j=0;j<c;j++)a[i][j]=i+j+1;}
printf("Transpose:\n");
for(int i=0;i<c;i++){for(int j=0;j<r;j++)printf("%d ",a[j][i]);printf("\n");}
10) #include <stdio.h> (3 mark)
#include <stdlib.h> Output
int main(){ Sum = 15
int n=5,*a,sum=0;
a=(int*)malloc(n*sizeof(int));
for(int i=0;i<n;i++){ a[i]=i+1; sum+=a[i]; } printf("Sum = %d\n", sum); free(a);