PDA

View Full Version : به نظرتون اشکال این کد چیه؟(اشاگر)



صفا خانوم
دوشنبه 08 خرداد 1391, 08:19 صبح
سلام
نمدونم چرا این خط کد اشکال داره اگه میشه راهنمایی کنید؟:افسرده:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void swap(int *,int *);
int main()
{
int x,y;
printf("enter two integer:");
scanf("%d%d",x,y);
printf("You Enterd x=%d and y=%d.\n",x,y);
swap(&x,&y);
printf("New value :x=%d and y=%d",x,y);
getch();
return 0;
}
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}

esmn1900
دوشنبه 08 خرداد 1391, 09:25 صبح
اشکال در خط 9 .
کد را به این صورت تصحیح کنید:


scanf("%d%d",&x,&y);

بهروز عباسی
دوشنبه 08 خرداد 1391, 13:42 عصر
اینطوری هم میشه

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void swap(int& a,int &b);
int main()
{
int x,y;
printf("enter two integer:\n\n");
printf("Enter an value for X: ");
scanf("%d",&x);
printf("Enter an value for Y: ");
scanf("%d",&y);
printf("\nBefor call Swap \tx=[%d] \tand y=[%d]\n",x,y);
swap(x,y);
printf("After call Swap \tx=[%d] \tand y=[%d]",x,y);
getch();
return 0;
}
void swap(int& a,int& b)
{
int temp;
temp=a;
a=b;
b=temp;
}