You are on page 1of 8

Name Naqeeb Ullah

Id 33662
Assignment no 1
Q1: Multiply five numbers with your ID by using Europe Method, American
Method, and Russian Method?
Ans: Russian Method of Multiplication: -
33833*98765=3341516245

33833 98765
16916 197530
8458 395060
4229 790120
2114 1580240
1057 3160480
528 6320960
264 12641920
132 25283840
66 50567680
33 101135360
16 202270720
8 404541440
4 809082880
2 1618167760
1 3236331520

Separate odd entries and add them


98765+790120+3160480+101135360+3236331520 = 3341516245

American Method of Multiplication: -


33833*12345 = 417668385
33 83 3 12 34 5
33*12 = 396000000
33*34 = 11220000
33*5 = 165000
83*12 = 9960000
83*34 = 282200
83*5 = 4150

3*12 = 36
3*34 = 1020
3*5 = 15

Sum all the answers:


396000000+11220000+165000+9960000+282200+4150+36000+1020+15
= 417668385 (Ans)

European Method of Multiplication: -

I= 33833 II = 33833
* 12345 * 98765

417668385 3341516245

Q2: What is difference between \n and \r?

Ans: \n: - \n is called (back-slash n). It is a notation which is used in C


programming language to return pointer to point a new line.
In general term \n is used to change line

\r: - \r is a carriage return character; it tells your terminal emulator to move
the cursor at the start of the line. The cursor is the position where the next
characters will be rendered. So, printing a \r allows to override the current
line of the terminal emulator.

Q3: What is difference between signed and un-signed integer?


Ans: Signed Integer: -
= It represents both positive and negative integer
= The data type qualifier is signed int or int. signed int a; OR int a.
= By default int are signed
= It reserve 16 bits (2 byte) in memory
= Range -2^15 to +2^15 i.e., -32,768 to 32,768
= Its conversion character is d

Unsigned Integer: -

= It represents only positive integer


= The data type qualifier is unsigned int or unsigned variable are defined as
unsigned int a OR int a.
= Un signed int have to be declared explicitly
= It reserve 16 bits (2 byte) in a memory
= Range from 0 to +2^16 i.e.,0 to 65,535
= Its conversion character is u

Q4: Why is integer range smaller while float is larger?


Ans: As we know, both of these types are 32-bits. int can hold only integer
numbers, whereas float also supports floating point numbers (as the type
names suggest). But the range of integer is smaller as compare to float
because of the decimal point Int stores whole number while float have
decimal number.
Let us suppose we have a float value 123.453
The bits will be divided in to both parts.123 and 453 while in integer value is
123

Q5: Write the ternary condition structure of grading system?


Ans:
#include<iostream>
using namespace std;
int main ()
{ int marks;
string result;
cin>>mark;
cout<<” Enter your marks :”;

result=(marks>=90&&marks<=100)?” your grade is A” :(marks>=80&&marks<=89)? “Your


grade is B “:(marks>=70&&marks<=79)?” Your grade is C+” (marks>=60&&marks<=69)?”
Your grade is C”) :(marks<60&&marks>=60)? “Your grade is F”;
cout<<” Result:”;}
Q6: Write ternary condition structure for capital character; smaller
character and for digits?

Ans:
#include<iostream>
using namespace std;
int main()
{ char ch;
cout<<"Enter any character: ";
cin>>ch;
if(ch>=65&&ch<=90)
cout<<"You entered "<< ch<<endl<<"You entered an uppercase character";
else if(ch>=48&&ch<=57)
cout<<endl<<"You entered a digit";
else if(ch>=97&&ch<=122)
cout<<"You entered "<< ch<<endl<<"You entered a lowercase character";
return 0;
}

Q7: What is the ASCII Code of small alphabet; capital alphabet and
digits?

Ans: Following are the ASCII code of small alphabet large alphabet and digits
ASCII value of lowercase alphabets = 97 to 122.

ASCII value of uppercase alphabets = 65 to 90.

ASCII value of digits = 48 to 57

Q8: Does modulus work with float, int and float, float and int?

Ans: Modulus Division operator % in C++ language does not work with float,
int and float, float and int. because modulus division operator can be used only
with integer variables or constants.

Q9: Write ternary condition structure for capital character; smaller


character and for digits by using ASCII?
Ans: #include <iostream>
using namespace std;
int main ()
{
char character;
int result;
cout<<"Enter a character:";
cin>>character;
result=((character>='a' && character<='z’) ||(character>='A' && character<='Z'))?
(int)character:0;
cout<<result;)

Q10: Make a flow chart of five subjects’ grade?


Ans: Grade flow chart

Start

Enter Marks

Calculate %age

If
Yes Grade =A
%age>=90
&<=100

No

Else if
Yes
%age>=80 Grade =B+
&<=89
Else if
Grade =B
%age>=70
No &<=79

Yes

No Else if YES
%age>=60 Grade =C
&<=69

No

Else
%age<60

Grade =Fail

Stop
doff
Q11: Write down the pseudo code of GPA and make its flow chart?
Ans: Pseudo Code:
1. Enter your grade
2. If(grade=A)
3. GPA is 4/4
4. Else
5. if(grade=B+)
6. GPA is 3.5/4
7. Else
8. if(grade=B)
9. GPA is 3.0/4
10. Else
11. if(grade=C+)
12. GPA is 2.5/4
13. Else
14. if(grade=C)
15. GPA is 2.0/4
16. Else
17. F grade

Start

Enter Marks

Calculate %age

If
Yes A = 4 GPA
%age>=90
&<=100

No

Else if
%age>=80
Yes
B+= 3.5GPA

NO

Else if Yes
%age>=70 B= 3.0 GPA
&<=79
No

Else if
%age>=60&
Yes
C+= 2.5GPA
<=69

No

Yes
Else
C=2.0 GPA
%age<60

No

Grade =Fail

Stop
doff

You might also like