Saturday, 14 October 2017

Practical-8

PRACTICAL- 8
Aim of the practical:-
Write a program (WAP) to enter any number and check that whether it is a Prime number or Composite number.

Header files used:-
#include <iostream.h>
#include <stdlib.h>
Conditional statements/Loops used:-
i.                   If– else statement
ii.                 while loop/for loop
Prime  & Composite Number:
A prime number is a natural number greater than 1 which has no positive divisors other than 1 and itself.
A natural number that is greater than 1 and that is not a prime number is called a Composite number.
Procedures followed:-
The user will be asked to enter any number. The number entered by the user will be divided with all numbers starting from 1 up to the number itself to find its divisors, using a for loop and an if statement. By comparing the number of divisors found with 2 using an if-else statement we can find weather it is a prime or composite number.

Coding:-

Practical-7

PRACTICAL- 7
Aim of the practical:-
Write a program (WAP) to enter any number and check that whether it is an Armstrong number or not.

Header files used:-
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
Conditional statements/Loops used:-
i.                   If– else statement
ii.                 while loop
Armstrong Number:-
A positive number is called an Armstrong number if the number formed by the sum of the cubes of indevidual digits of that number is the number itself.
For example:- 0,1,153,370,371 and 407
153=1*1*1+5*5*5+3*3*3
Procedures followed:-
The user will be asked to enter any number. We need to store a duplicate copy of that number in another variable. Then the each digit of the number will be added after finding its cube and stored in another variable. After this the number formed will be compared with the duplicate copy stored earlier to check whether it is an Armstrong number or not.

Coding:-

Tuesday, 10 October 2017

Practical - 6

          PRACTICAL- 6
Aim of the practical:-
Write a program (WAP) to enter any number and check that whether it is palindrome or not.

Header files used:-
#include <iostream.h>
#include <stdlib.h>
Conditional statements/Loops used:-
i.                    If– else statement
ii.                  while loop
Procedures followed:-
The user will be asked to enter any number. We need to store a duplicate copy of that number in another variable. Then the reverse of that number will be formed using a while loop. After forming the reverse of the number it will be compared with the duplicate copy stored earlier to check whether it is palindrome or not.
Coding:-

Practical-5

PRACTICAL- 5
Aim of the practical:-
Write a program (WAP) to enter the value of Coefficient of x2 (a), Coefficient of x (b) and constant term (c), and  find the roots of a quadratic equation ax2+bx+c=0
Header files used:-
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
Conditional statements/Loops used:-
i.                   If– else –if ladder
Procedures followed:-
The coefficient of x2, x, and constant term of the quadratic equation ax2 + bx + c = 0 is entered by the user. Then we find the discriminant by applying the formula D=b2 - 4ac.
Then this discriminant is compared with 0 in an if- else- if ladder and the roots are found as per the rules given below.
i.                  D>0, Roots are real and distinct.
ii.                D=0, Roots are real and equal.
iii.              D<0, Roots are imaginary.

Coding:-


Monday, 2 October 2017

Practical-4

PRACTICAL-4
Aim of the practical:-
Write a program (WAP) to check the input from keyboard is a alphabet or number or a special character.
Header files used:-
#include <iostream.h>
#include <stdlib.h>
Conditional statements/Loops used:-
i.                   If– else –if ladder
Procedures followed:-
The user will be asked to press any key from the keyboard. Then the input will be compared with its range of ASCII values in successive if- else if () statements to identify which particular category it belongs to (alphabets/numbers/special characters).And finally the condition which it will satisfy will be shown as the output.
The details of range of ASCII values are:-
Characters
ASCII values
A… Z (Upper case alphabets)
65 to 90
a… z  (Lower case alphabets)
97 to 122
0…9   (Numbers)
48 to 57

Coding:-

Dussehra Puja Holiday Home Work

1.  Evaluate the following expressions
a.  x – y < z  &&  y + z > x || x-z <= y – x + z
i.            If x=4,y=7 and z=10
ii.          If x=3, y=8 and z=-5
iii.         If x=-5, y=1 and z=3
b.  (y) && (y-z) || !(2y+z-x)
i.            If x=13,y=14 and z=5
ii.          If x=10, y=5 and z=5
iii.         If x=5,y=6 and z=9
2.  Determine the values of the following C++ expressions when a, b, c are integers and d, f are floating point numbers. The values of a=5,b=3 and d=1.5
i.            f= a + b/a
ii.          c= d * a + b
iii.         c= (a++)  *d +a
iv.        f= (++b)*b – a
v.          c= a - (b++)*(- - a)
3.  Suppose a, b, c are integers and a=3, b=6, c=-5 and x, y, z are floating point variables where x=8.8, y=3.5, z=-5.2
Determine the value of the following expressions.
i.            a % c
ii.          a*b/c
iii.         (a*c)%b
iv.        x/y
v.          x/(x + y)
vi.        int (x) % int (y)
4.  Wap to input a number. If the number is even then print its square otherwise print its cube. (do it using conditional operator)
5.  Wap to input a number. If the number is even and positive then print its square root otherwise print its cube.
6.  Wap to enter any two numbers from the user other then zero and also any arithmetic operator (+, - , *, /). Then it should produce the arithmetic operation between the two numbers and finally displays the result.
7.  Wap to enter any year from the keyboard and display weather it is a leap year or non- leap year..
8.  Find the output of the question numbers 11 and 12 of chapter no.10 page no.266 and 267 of Sumita Arora book .


Practical-3

PRACTICAL-3
Aim of the practical:-
Write a program (WAP) to enter any three different numbers and arrange them in both ascending and descending order.
Header files used:-
#include <iostream.h>
#include <stdlib.h>
Conditional statements/Loops used:-
i.                   If statement
ii.                 If else statement
Procedures followed:-
The user will be asked to enter any three different numbers. One of the three numbers will be taken as the greatest and will be compared with the other two in successive if () statements to find out the greatest among the all.
After finding the greatest of all, the other two will be compared in successive if else statements to find the 2nd and 3rd greatest of them.

Coding:-