0% found this document useful (0 votes)
18 views5 pages

Ashmal

The document contains C++ code snippets and questions. Section B contains code snippets and explanations for different programming concepts. Snippets include examples of variable declaration and initialization, conditional operators, loops, functions, operators, and more. Section C contains questions about writing C++ code, including loops, conditional statements, functions to find largest number and series, and printing even numbers meeting certain criteria.

Uploaded by

Sheikh Asfand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

Ashmal

The document contains C++ code snippets and questions. Section B contains code snippets and explanations for different programming concepts. Snippets include examples of variable declaration and initialization, conditional operators, loops, functions, operators, and more. Section C contains questions about writing C++ code, including loops, conditional statements, functions to find largest number and series, and printing even numbers meeting certain criteria.

Uploaded by

Sheikh Asfand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Section B

Q2: (ii):
int x=8, y=90, z; z=++x; y=--z; x=++y;
cout<<++z<<x++<<--y;
output:
998

(iii) :
int x, y;
cout<<"please enter two numbers to swap them x and y \n";
cin>>x>>y;
swap(x,y);
cout<<"x= "<<x<<" y= "<<y;

(iv):
int x=899, y=90; (x>y) &&(x==y); (x<y)&& (x! =y) test the condition?
Ye ooper question e ajeeb sa likha h
Iss tarah hona chaeye tha
int x=899, y=90;
if((x>y) && (x==y))
if((x<y) && (x! =y))
from above conditions which one could be true
Answer:
For an ideal case the first condition cannot be true in any value of x and y because a number
cannot be greater than and equal to another number at the same time.
Second condition can be true for some other value of x but in this example, x is greater than
y so it will also be false.
(v):
Answer: iss ko conditional operator sy krna h just
(x>y)&&(x!=y)?True:False;
Bus ye aik line is ka answer h hint: book page no. 62-63

(vi):
Yar technically tou iss provided code mein bohat problems hain ye teacher sy pooch k e
solve hota h but
Jaisa k cout<<j<<endl saari brackets sy bahr h I mean k for loop sy b bahr h so ye aik e bar
output dy jo k ye hogi
Output:
4

(viii)
Definition page 48 sy parh lena
Code ye likh dena:
int a=5, b=2;
cout<<a/b;//c=a/b; // this statement will print an integer 2 because 5/2 = 2 in the form of
integer
// to get a float value we will use type casting
cout<<(float)a/b; //this time we will get a floating-point value

(ix):
89%2*(34+56/2-8*67)
Answer:
Sb sy pehly bracket solve hoti h so

 89%2*(34+28-8*67)
 89%2*(34+28-536)
 89%2*(-474)
 1*(-474)
So answer will be -474
(x) :
Write a C++ code that read a number and find its factorial
Answer:
int a,F=1;
cout<<"Please enter a number to find its factorial ";
cin>>a;
for(int j=a;j>=1;j--)
{
F=F*j;
}
cout<<"the factorial of "<<a<<" is "<<F;

(xi):
Answer:
int a, counter=0;
cout<<"please enter a number ";
cin>>a;
for (int j=2; j<a; j++)
{
if(a%j==0)
{
counter++;
break;
}
}
if(counter==0)
{
cout<<" It is a prime number ";
}
else
{
cout<<" It is a composite number ";
}

(xii):
Answer:
#include<iostream>
Using namespace std;
int main () {
cout<< “Information Technology” <<endl;
return 0;
}
(xiii): Answer:
//A variable can be declared without initializing it just like the below statement:
int a;
//but a constant cannot be declared without initializing it because we cannot change its
value during execution of program here is the example:
const int A=1;

(xiv):
Answer:
1) Letter C of Cout is upper case which is invalid we should use cout instead
2) Gatach() is an invalid function valid function is getch()

Section C:
Q4:
i)
Answer:
for(int j=1;j<=100;j++)
{
if(j%6==0)
cout<<j<<" is divisible by 6 \n";
if(j%9==0)
cout<<"\t\t\t\t\t"<<j<<" is divisible by 9 \n";
}
ii) Answer:
int a,b;
cout<<"Please enter two numbers to find the largest among them \n";
cin>>a>>b;
(a>b)?cout<<a<<" is largest":cout<<b<<" is largest";

Q5: Answer:
int i,j=0;
for( i=0;i<=30;i=i+3)
{
if(j==0)
{
cout<<1;
}
else
{
cout<<"+"<<i<<"/"<<j;
}
j++;
}

Q6 i) Answer:
Question e smj ni aaya
Paper mein pen sy cutting hui v h
ii) Answer:
For (int j=1; j<=50; j++)
{
if(j%2==0)
{
if((j%7==0) ||(j%5==0))
{ }
else
{
cout<<j<<" ";
}
}
}

You might also like