This is my code:
#include%26lt;stdio.h%26gt;
main()
{
int cas,cnt,ctr,x=1,y=2;
clrscr();
printf("Enter case number[1-4]:");
scanf("%d",%26amp;cas);
switch(cas)
{
case 1:
{ for(cnt=5;cnt%26gt;0;cnt--,x++,y++)
{for(ctr=cnt;ctr%26gt;0;ctr--)
gotoxy(x,y);printf("%d",ctr);
printf("\n");
}
break;
}
case 2:
{ for(cnt=1;cnt%26lt;=5;cnt++)
{for(ctr=cnt;ctr%26lt;=5;ctr++)
printf("%d",cnt);
printf("\n");
}
break;
}
case 3:
{ for(cnt=5;cnt%26gt;0 %26amp;%26amp; ctr%26gt;6;cnt--)
{for(ctr=1;ctr%26lt;=5;ctr++)
printf("%d",ctr);
printf("\n%d\n%d\n%d\n%d",ctr-4,ctr-...
}
break;
}
case 4:
{ for(cnt=1;cnt%26lt;=10;cnt++)
{for(ctr=1;ctr%26lt;=10;ctr++)
printf("%d\t",ctr*cnt);
printf("\n");
}
break;
}
}
getch();
}
--------------------------------
which must produce in case 1:
54321
4321
321
21
1
in case 2:
12345
1234
123
12
1
in case 3:
12345
2
3
4
5
in case 4:
10x10 multiplication table
thx in advance.... :-)
Can anyone who is expert in turbo c can correct my code here? thanks in advance:?
There's no need for a gotoxy in case1. In case 2 you're printing cnt, you should be printing ctr. I've rewritten case 3 to something simpler. Case 4 looks fine to me.
Enjoy.
switch(cas)
{
case 1:
for(cnt=5;cnt%26gt;0;cnt--)
{
for(ctr=cnt;ctr%26gt;0;ctr--)
printf("%d",ctr);
printf("\n");
}
break;
case 2:
{
for(cnt=1;cnt%26lt;=5;cnt++)
{
for(ctr=1;ctr%26lt;=6-cnt;ctr++)
printf("%d",ctr);
printf("\n");
}
}
case 3:
{
for(cnt=1;cnt%26lt;=5;cnt++)
{
printf("%d",cnt);
if (cnt==1)
for(ctr=2;ctr%26lt;=5;ctr++)
printf("%d",ctr);
printf("\n");
}
}
break;
case 4:
{
for(cnt=1;cnt%26lt;=10;cnt++)
{
for(ctr=1;ctr%26lt;=10;ctr++)
printf("%d\t",ctr*cnt);
printf("\n");
}
}
break;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment