Debugging Results


Question 1

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
void main()
{
int i;
int ch;
char f;
int a,b,*ap,*bp;
*ap=10;
*bp=5;
clrscr();
scanf(“%d”,&i);
ch=i;
switch(ch)
{
case 1 : f=getche();
if(isalpha(f)) printf(“%c”,tolower(f));  break;
case 2 : printf(“%2d”,(ch%i));  break;
case 3 : printf(“%d”,*ap-*bp);    break;
case 4 : ap=(int*)malloc(sizeof(int)*10);  break;
case 5 : printf(“Technovate at Debugging Finals”);
default:
break;
}
getch();
}

Question 2

#include<conio.h>
#include<stdio.h>
#include<string.h>
void shaker(char *items,int count);
void main()
{
char s[255];
clrscr();
printf(“Enter the string”);
gets(s);
shaker(s,strlen(s));
printf(“The sorted string is:%s\n”,s);
getch();
}
void shaker(char *items,int count)
{
register int i;
int exchandge;
char t;
do
{
exchange=0;
for(i=count-1;i>0;–i)
{
if(items[i-1]>items[i])
{
t=items[i-1];
items[i-1]=items[i];
items[i]=t;
exchange++;
}
}
//printf(“%s “,items);
//getch();
/*for(i=1;i<count;++i)
{
if(items[i+1]>items[i])
{
t=items[i-1];
items[i-1]=items[i];
items[i]=t;
exchange–;
}
}*/
}while(exchange);
}

Question 3

#include<process.h>
#include<conio.h>
#include<stdio.h>
void main()
{ int i,b,p,d,n=0,sr,rem,a;
clrscr();
scanf(“%d%d%d”,&b,&p,&d);
a=b;
for(;a<d;)
{
a*=b;n++;
}
if(a==d)
{
rem=0;
printf(“%d”,rem);
exit(0);
}
n–;
a/=b;
sr=(p-n);
for(i=0;i<sr;i++)
{
rem=a%d;
a=rem*b;
}
printf(“%d”,rem);
getch();
}

Question 4

#include<conio.h>
#include<stdio.h>
#define MAX 3
void main()
{
int a[MAX][MAX];
int i,j,n,num;
clrscr();
printf(“Enter the value of n(odd)\n”);
scanf(“%d”,&n);
i=n-1;
j=(n-1)/2;
for(num=1;num<=n*n;num++)
{
a[i][j]=num;
i++;
j–;
if((num%n)==0)
{
i-=2;
j++;
}
if(i==n)
i=0;
if(j==-1)
j=n-1;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf(“%d\t”,a[i][j]);
printf(“\n”);
}
getch();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s