#include<stdio.h>
#include<conio.h>
void main()
{
 printf("enter number:");
 scanf("%d",&n);
 for(i=1;i<=y;i++)
 {
  x++;
 }
 t=x;

 for(i=1;i<=y;i++)
 {
  t--;
 }
 y=t;
 getch();
}

Recommended Answers

All 5 Replies

Until you really know what you're doing, it's a good idea to compile code you want to show off before posting it.

And your question is? Then when you complied your code what did you get?

main.c:7:6: error: 'i' undeclared (first use in this function)
main.c:7:13: error: 'y' undeclared (first use in this function)
main.c:9:3: error: 'x' undeclared (first use in this function)
main.c:11:2: error: 't' undeclared (first use in this function)
#include<stdio.h>
#include<conio.h>
void main()
{
 int x,y,i,t;
 clrscr();
 printf("Enter x and y: ");
 scanf("%d%d",&x,&y);
 for(i=1;i<=y;i++)
 {
  x++;
 }
  t=x;
   for(i=1;i<=y;i++)
    {
     t--;
    }
     y=t;
      for(i=1;i<=y;i++)
      {
       x--;
      }
       printf("%d%d",x,y) ;

getch();  
}
Member Avatar for Mouche

Did you consider doing this with for loops a puzzle, or was that the only way you knew how to do it?

Your code from line 9 to 22 can be simplified to:

t = 0;
x = x + y;
t = x;
t = t - y;
y = t;
x = x - y;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.