PDA

View Full Version : سوال: رفع اشکال



apple-man
دوشنبه 17 آذر 1393, 14:21 عصر
// q2.cpp : Defines the entry point for the console application.
میخوام برنامه بنویسم که یه تعداد عدد مثبت رو بگیره ور در صورت برابری وارون اونها با خودشون چاپ بشن
(مثل 545)



#include "stdafx.h"
#include<iostream>
using namespace std;
void main()
{
int a, arr[10],b,c,r,store[10];




for (int i = 0; i <10; i++)
{
cout<<"enter number "<<i+1<<endl;
cin>>b;
arr[i]=b;


c=arr[i];
r=0;
while (c>0)
{
r=(c%10)+10*r;
c=c/10;


}
if (r==b)
{
store[i]=r;

}



}
cout<<store[10];
cin.get();
cin.ignore();
}

mahsa_ziafat
دوشنبه 17 آذر 1393, 22:57 عصر
خدمت شما ..... اگه شما منظورتون فقط برای اعداد 3 رقمی باشه که کار راحت میشه ...... اینی که نوشتم برای اعداد n رقمی هم جواب میده :

تعداد عدد هارو زدم 1 به جای 10 ..... خودت هرچندتا دوست داشتی بزن ( توی دوتا حلقه ی اول مقدارش رو عوض کن )




#include "stdafx.h"
#include<iostream>
using namespace std;
void main()
{
int a, arr[10], c, t, r, store[10],k,p=0;
bool check = true;
for (int i = 0; i < 1; i++)
{
cout << "enter number " << i + 1 << endl;
cin >> arr[i];
}
system("cls");
for (int i = 0; i <1; i++)
{
c = t = arr[i];
r = 0;
k = 1;
for (; c - ((long)c)>0; c *= 10, p++);
for (a=0 ; c>0 ; c = ((long)c / 10) , a++)
{
store[a] = (long)c % 10;
p--;
}
int *temp = new int[a];
for (int k = a - 1; k >= 0; k--, t /= 10)
temp[k] = t % 10;
for (int j = 0; j < a; j++)
if (store[j] != temp[j])
check = false;
if (check == true)
cout << arr[i] << endl;


}
system("pause");
}