السوال الاول :
Find the error in each of the following segments and correct it.
a)
int * number ;
cout<< number <<endl ;
*numberb)
b)
double *realptr ;
long *integerptr ;
integerptr = realptr ;
*integerptr = * realptr ;
d)
int *x , y ;
x = y ;
*x=y;
d)
char s[] = "this is a character array" ;
for ( ; *s != '\0' ; s++)
cout<< *s ;
for ( int *s; *s != '\0' ; *s++)
________________________________________________________________________
السوال الثانى :
Write a program that reads and stores integer numbers in the 2-D array of 10 rows and 20 columns. Then the program uses the function reverseDiagonal to reverse both the diagonals of the array.
محاولتى :
#include<iostream>
using namespace std;
void reverseDiagonal (int [][]);
int main()
{ int a[10];
int a;
cout<<"Enter 10 integers:"<<endl;
reverseDiagonal (a);
cin>>a
cout<<endl<<"The array contains:"<<endl;
for(int j=0;j<10;j++)
cout<<"a["<<j<<"] = "<<a[j]<<endl;
return 0}
void reverseDiagonal (int a[][])
{for(int c=0;c<10;c++)
for(int r=0;r<20;r++)
a=[c][r];}
________________________________________________________
وماهو حل هذا السوال لاننى حاولت كثير ولم استطع ايجاد الحل
Write a C++ program that ask user to enter the number in decimal then convert it to the binary and vise versa .
Be sure that your program have the following :
1- Recursive function that convert from binary to decimal.
2- Validate function that check if the binary number entered by the user contain only 0s and 1s .
How Convert from binary to decimal :
To convert binary into decimal is very simple and can be done as shown below:
Say we want to convert the 4 bit value 1001 into a decimal value, we can use a formula like that below:
128 64 32 16 8 4 2 1
1 0 0 1
As you can see, we have placed the numbers 1, 2, 4, 8, 16, 32, 64, 128 (powers of two) in reverse numerical order, and then written the binary value below.
To convert, you simply take a value from the top row wherever there is a 1 below, and then add the values together.
For instance, in our example we would have 8 + 1 = 9 .
Because we know binary is base 2 then the above could be written as:
1*23 + 0*22 + 0*21 + 1*20 = 9 .
