C Programming Question 1 For the following block of code fo
C++ Programming !
Question 1 For the following block of code: for (int x 15; x 7 x--) if x 2 -0) coutSolution
Question 1:
for(int i=15; x>7;x--)
{
if(!(x%2==0)))
cout<<x<<endl;
}
(i) Ans :
15
13
11
9
(ii) Ans :
#include <iostream>
using namespace std;
int main()
{
int x=15;
while(x>7)
{
if(!(x%2==0))
cout<<x<<endl;
x--;
}
}
Question 2:
(i) Ans :
int xyz(int x, int y, int z);
(ii) Ans :
enter x=1, y= -2, z=3;
ans = ((2*1 + 4*-2));
ans = -2
if(ans<0)
ans = -(-2); //ans = -(ans)
return ans (ans = 2)
(iii) Ans :
#include <iostream>
using namespace std;
int xyz(int x, int y, int z){
if(z<=0)
cout<<\"ir return -999 \ \"; // not visible proper error message in question
int ans = ((2*x + 4*y)/z);
if(ans<0)
ans = -(ans);
return ans;
}
int main()
{
int x,y,z;
cout << \"Enter x, y,z values \ \";
cin>>x>>y>>z;
int ans = xyz(x,y,z);
cout <<\"Ans = \"<<ans<<\"\ \";
return 0;
}
Question 3:
(i) Ans :
#include <iostream>
using namespace std;
struct HOUSE{
string owner_name;
int person_occupied;
bool rent;
float size;
};
(ii) Ans :
int main()
{
struct HOUSE myHome;
myHome.owner_name = \"tslee\";
myHome.person_occupied = 3;
myHome.rent = false;
myHome.size = 2800.68;
}

