You are on page 1of 18

1.

Write a program to ,

a) Display all numbers between 1 and 20


b) Display the numbers 1 8 5 22 50 57 64
c) Display the numbers 100 90 80 20 10 0
d) Display the following

1x5=5
2 x 5 = 10
...
...
10 x 5 = 50

e) Display the following

10 x 9 = 90
9 x 9 = 181
..
..
1x9=9

f) Display all even numbers between 1000 and 2000


g) Calculate and display the sum of all odd numbers in the range 100 to 499

1
4. In a contest , 20 questions are given. 5 point is given for each correct answer for the
odd number question and 3 point is given for each correct answer for the even
numbered question.Write a program segment to input the answer : C for correct
answer and W for wrong answer, and determine the total point the contestants
received.

6. Write a program to calculate the average of numbers within the given two
integers.For example,if the numbers are 3 and 7,the average value is 5 which
is calculated from ( 4+5+6)/3.

13. Without using division operator %,write a complete program using C++ to
find the divison and the remainder when dividing two positive integer
numbers.Display the value of quotient and the remainder.Make sure the divisor is
not zero.Display an appropriate message if the divisor is zero.

2
ANSWER:

QUESTION 1 (a)

#include<iostream>
#include<math.h>

using namespace std ;

int main()
{
int num = 0 ;

while ( num < 20 )

cout<< num <<" " ;


num = num + 1 ;

return 0 ;

3
QUESTION 1 (b)

#include<iostream>
#include<math.h>

using namespace std ;

int main()

{
int num = 1 ;

while ( num <= 64)

cout<< num <<" " ;


num = num + 7 ;

return 0 ;

4
QUESTION 1 (c)

#include<iostream>
#include<math.h>

using namespace std ;

int main()

{
int num = 100 ;

while ( num >= 0)

cout<< num <<" " ;


num = num -10 ;

return 0 ;

5
QUESTION 1 (d)

#include<iostream>
#include<math.h>

using namespace std;

int main()

const int num = 5;

int product;

for (int number =1; number<= 10; number++)

{
product = number * num;
cout<<number<<"*"<<num<<"="<<product<<endl;
}

return 0;

QUESTION 1 (e)
#include<iostream>
#include<math.h>

using namespace std;

int main()

int number = 10;


const int num = 9;
int product;

while (number != 0)

{
product = number * 9;
cout<<number<<"*"<<num<<"="<<product<<endl;
number--;
}

return 0;

QUESTION 1 (f)
#include<iostream>
#include<math.h>

using namespace std;

int main()

int num = 1000;


cout << List of even numbers between 1000 and 2000<< endl ;

do

{
cout<<num<<", ";
num = num + 2;
}
while ( num <= 1998 );

return 0;
}

8
QUESTION 1 (g)

#include<iostream> 9
#include<math.h>

using namespace std;


int main ()

int number;
int sum = 0;

for (number = 101; number <= 499; number++)

if (number%2 != 0)
sum = sum + number;

cout<<"SUM OF ALL ODD NUMBERS BETWEEN 100 TO 499: "<<sum<<endl;

return 0;

QUESTION 4

#include <iostream>
10

using namespace std;


int main()

{
int ques = 1;
int point = 0;
char ans;

cout<<"Enter the marking point [ C- CORRECT, W- WRONG]"<<endl;


while (ques <=20)
{
if(ques%2!=0)
{
cout<<"Question"<<ques<<"=";
cin>>ans;

if (ans =='C'||ans =='c')


{
point= point+5;
}

else
{
point= point;
}
}

else

{
cout<<"Question"<<ques<<"=";
cin>>ans;

if(ans =='C'||ans =='c')


{
point = point+3;
}
else
{
point =point;

}
ques++;
}
cout<<"Your total point
11 is ="<<point<<endl;

return 0;

}
cout<<" Total point: "<<point;

return 0;
}

QUESTION 6
12

#include<iostream>
#include<math.h>
using namespace std;

int main ()

{
int count = 0, integer, number;
float average, min = 100.0, max = 0.0, total = 0.0;

cout<<"HOW MANY INTEGERS DO YOU WANT TO INPUT: ";


cin>>integer;

while (count < integer)

{
cout<<"ENTER THE INTEGER: ";
cin>>number;

if ( min > number)


min = number - 1;

if ( max < number)


max = number + 1;

total = total + number;


count++;

average = total / integer;

cout<<"AVERAGE SCORE: "<<average<<endl;

return 0;
}

13
QUESTION 13

#include<conio.h>
#include<math.h>
14

using namespace std;

int main ()
{
int number, divisor, quotient = 0;

cout<<"INSERT THE NUMBER YOU WANT TO DIVIDE: ";


cin>>number;

cout<<" ENTER THE NUMBER FROM WHICH TO DIVIDE : ";


cin>>divisor;

if (divisor != 0)

{
while (number >= divisor)

{
number = number - divisor;
quotient += 1;
}

cout<<"ANSWER: "<<quotient<<endl;
cout<<"REMINDER: "<<number<<endl;

else
{
cout<<"INFINITY. PLEASE TRY AGAIN";
}

return 0;
}

15
16
17
18

You might also like