Computer Science File.pdf

Embed Size (px)

Citation preview

  • 7/24/2019 Computer Science File.pdf

    1/49

    Computer Science File

    Udbhav Gupta S G

  • 7/24/2019 Computer Science File.pdf

    2/49

    1

    INDEXAcknowledgements

    Programs:

    1. Addition of Two Integers

    2. Count Till

    3. Average Marks of 5 Students

    3. Area of Circle

    4. Difference of Two Integers

    5. All Even Numbers from 2 to 40

    6. Roots of a Quadratic equation

    7. All Odd Numbers less than 50

    8. Highest Common Factor of Two Integers

    9. Lowest Common Multiple of Two Integers

    10.Even Number or Odd Number

    11. Prime Number

    12. Multiples of any Natural Number up to 100

    13. Factors of a Number

    14. Multiplication Table of a Number

    15. Number Pyramid

    16. Star Pyramid

    17. Check Whether a Triangle is Equilateral,

    Isosceles or Scalene

    18. Addition, Subtraction, Multiplication, Division of

  • 7/24/2019 Computer Science File.pdf

    3/49

    2

    Two integers (Switch Case)

    19. Reverse Order

    20. Sum and Average of 10 Integers

    21. Largest and Smallest Number in an Array

    22. Even Numbers in an Array

    23. Fibonaccis Sequence

    24. Ascending Order (Linear Sorting)

    26. Palindrome

    27. Factorial of a Number

    28. Length of a String

    29. Descending Order (Bubble Sorting)

    30. Number of Spaces and Words

    31. Display Initials of the first two words in a string

  • 7/24/2019 Computer Science File.pdf

    4/49

    3

    ACKNOWLEDGMENT

    I would like to express my deep gratitude to Gautam Sarkar Sir

    for his expert advice and brilliance in the subject. Because of

    your immense knowledge of the subject the concepts are easily

    understandable and the classes are always fun.

    I would also like to thank Yogita maam for her patient

    guidance. The completion of this file could not have been

    accomplished without your valuable support.

  • 7/24/2019 Computer Science File.pdf

    5/49

    4

    1.Write a Program for addition of Two Integers

    #include //iostream.h is for cin and coutvoid main()

    { int a, b, sum;

    cout

  • 7/24/2019 Computer Science File.pdf

    6/49

    5

    2.Write a Program to Find out the Marks and

    Average of 5 Students

    #include

    void main(){

    float m1, m2, m3, m4, m5, avg; //float is used for decimals

    coutm1;cout

  • 7/24/2019 Computer Science File.pdf

    7/49

    6

    Output:

  • 7/24/2019 Computer Science File.pdf

    8/49

    7

    3.Write a Program to Calculate the Area of a

    Circle

    #include

    void main(){

    float area, radius;

    cout

  • 7/24/2019 Computer Science File.pdf

    9/49

    8

    4.Write a Program to Check Whether the Difference

    of 2 integers is Greater Than or Less Than 0

    #include

    void main(){

    int a, b, diff;

    cout

  • 7/24/2019 Computer Science File.pdf

    10/49

    9

    Output:

  • 7/24/2019 Computer Science File.pdf

    11/49

    10

    5.Write a Program to Print all Even Numbers from 2

    to 40

    #include

    void main(){

    int i;i=2;

    cout

  • 7/24/2019 Computer Science File.pdf

    12/49

    11

    6.Write a Program to Find The Real Roots of a

    Quadratic Equation

    #include

    #includevoid main(){

    float a, b, c, D, r1, r2;

    cout

  • 7/24/2019 Computer Science File.pdf

    13/49

    12

    Output:

  • 7/24/2019 Computer Science File.pdf

    14/49

    13

    7.Write a Program to Display all Odd Numbers Less

    Than 50

    #includevoid main(){

    int odd;odd=1;

    while(odd

  • 7/24/2019 Computer Science File.pdf

    15/49

    14

    8.Write a Program to Find the HCF of Two Integers

    #include

    void main(){

    int no1, no2, M, N, HCF;

    cout

  • 7/24/2019 Computer Science File.pdf

    16/49

    15

    Output:

  • 7/24/2019 Computer Science File.pdf

    17/49

    16

    9.Write a Program to Find the LCM of Two Integers

    #includevoid main(){

    int no1, no2, M, LCM;

    cout

  • 7/24/2019 Computer Science File.pdf

    18/49

    17

    Output:

  • 7/24/2019 Computer Science File.pdf

    19/49

    18

    10. Write a Program to Find if a Number is Even

    or Odd

    #include

    void main(){

    int no;

    cout

  • 7/24/2019 Computer Science File.pdf

    20/49

    19

    11. Write a Program to Check Whether a Given

    Natural Number is Prime or Not

    #include

    void main(){

    int x, prime, A;

    cout

  • 7/24/2019 Computer Science File.pdf

    21/49

    20

    Output:

  • 7/24/2019 Computer Science File.pdf

    22/49

    21

    12. Write a Program to print the Multiples of any

    Natural Number upto 100

    #include

    void main(){

    int x, y;cout

  • 7/24/2019 Computer Science File.pdf

    23/49

    22

    13. Write a Program to Find the Factors of a Number

    #includevoid main()

    {int x, y;

    cout

  • 7/24/2019 Computer Science File.pdf

    24/49

    23

    14. Write a Program for the Multiplication Table of

    a Natural Number

    #include

    void main(){

    int no, divisor, product;

    cout

  • 7/24/2019 Computer Science File.pdf

    25/49

    24

    15. Write a Program to Print a Number Pyramid

    #includevoid main()

    {cout

  • 7/24/2019 Computer Science File.pdf

    26/49

    25

    16. Write a Program to Print a Star Pyramid

    #includevoid main()

    {cout

  • 7/24/2019 Computer Science File.pdf

    27/49

    26

    17. Write a Program to Check Whether a Triangle

    is Equilateral, Isosceles or Scalene

    #include

    void main(){

    float side1, side2, side3;cout

  • 7/24/2019 Computer Science File.pdf

    28/49

    27

    Output:

  • 7/24/2019 Computer Science File.pdf

    29/49

    28

    18. Write a Program to Perform Addition,

    Subtraction, Multiplication and Division of Two

    Integers

    #includevoid main(){

    int a, b, sum, diff, product, div;char op;

    cout

  • 7/24/2019 Computer Science File.pdf

    30/49

    29

    couta;coutb;

    div=a/b;cout

  • 7/24/2019 Computer Science File.pdf

    31/49

    30

    19. Write a Program to Print the Given Numbers in

    Reverse Order

    #include

    void main(){

    float A[5]; //'A[ ]' is an arrayint i;

    cout

  • 7/24/2019 Computer Science File.pdf

    32/49

    31

    Output:

  • 7/24/2019 Computer Science File.pdf

    33/49

    32

    20. Write a Program to Find the Sum and Mean Average

    of 10 Integers

    #include

    void main(){

    int A[10];float avg, sum=0;

    cout

  • 7/24/2019 Computer Science File.pdf

    34/49

    33

    21. Write a Program to Find the Largest and the

    Smallest Number in an Array

    #include

    void main(){

    int A[10], MAX, MIN, i;

    cout

  • 7/24/2019 Computer Science File.pdf

    35/49

    34

    Output:

  • 7/24/2019 Computer Science File.pdf

    36/49

    35

    22. Write a Program to Display all Even Numbers in

    an Array

    #include

    void main(){

    int A[10], i;

    cout

  • 7/24/2019 Computer Science File.pdf

    37/49

    36

    23. Write a Program to display the First 20 Numbers

    of the Fibonaccis Sequence

    #include

    void main(){

    int fib[20], i, a, b;

    cout

  • 7/24/2019 Computer Science File.pdf

    38/49

    37

    24. Write a Program to sort an Array in Ascending

    Order (Linear Sort)

    #include

    void main(){

    int A[6], i, j, flag;

    cout

  • 7/24/2019 Computer Science File.pdf

    39/49

    38

    Output:

  • 7/24/2019 Computer Science File.pdf

    40/49

    39

    25. Write a Program to check if a Given String is a

    Palindrome

    #include

    #include //this is to use gets function#includevoid main(){

    int i, j, len=0, flag=0;char str[100];

    cout

  • 7/24/2019 Computer Science File.pdf

    41/49

    40

    Output:

  • 7/24/2019 Computer Science File.pdf

    42/49

    41

    26. Write a Program to find the Factorial of a

    Number

    #include

    void main(){

    float i, x, factorial=1;

    cout

  • 7/24/2019 Computer Science File.pdf

    43/49

    42

    27. Write a Program to Find the Logical Length of a

    String

    #include

    #include#includevoid main(){

    int length;char str[50];

    cout

  • 7/24/2019 Computer Science File.pdf

    44/49

    43

    28. Write a Program to sort an Array in Descending

    Order (Bubble Sort)

    #include

    void main(){

    int A[6], i, j, flag;

    cout

  • 7/24/2019 Computer Science File.pdf

    45/49

    44

    Output:

  • 7/24/2019 Computer Science File.pdf

    46/49

    45

    29. Write a Program to count the Number of Spaces

    and Words in a String.

    #include

    #include#includevoid main(){

    int count=0, i;char str[100];

    cout

  • 7/24/2019 Computer Science File.pdf

    47/49

    46

    Output:

  • 7/24/2019 Computer Science File.pdf

    48/49

    47

    30. Write a Program to Display the Initials of only

    the First Two Words in a String

    #include

    #include#includevoid main(){

    int i;char str[100];

    cout

  • 7/24/2019 Computer Science File.pdf

    49/49

    Output: