Practical No1

download Practical No1

of 91

  • date post

    07-Apr-2018
  • Category

    Documents

  • view

    224
  • download

    0

Embed Size (px)

Transcript of Practical No1

  • 8/6/2019 Practical No1

    1/91

    Practical no1#include

    #includevoid main()

    {clrscr();

    cout

  • 8/6/2019 Practical No1

    2/91

    cout

  • 8/6/2019 Practical No1

    3/91

    cout

  • 8/6/2019 Practical No1

    4/91

    Practical no 7#include

    #include

    void main(){clrscr();

    int num1,num2;coutnum1;coutnum2;cout

  • 8/6/2019 Practical No1

    5/91

    void main(){

    clrscr();int num1,num2;

    coutnum1;coutnum2;

    cout

  • 8/6/2019 Practical No1

    6/91

    cout

  • 8/6/2019 Practical No1

    7/91

    C=(5*(F-32))/9;cout

  • 8/6/2019 Practical No1

    8/91

    cin>>vi;couta;coutt;

    vf=vi+(a*t);cout

  • 8/6/2019 Practical No1

    9/91

    Practical No 14#include#include

    void main(){

    clrscr();float vi,a,vf,s;

    coutvi;

    coutvf;

    couts;

    a=((vf*vf)-(vi*vi))/(2*s);cout

  • 8/6/2019 Practical No1

    10/91

    Practical No 15

    #include

    #include

    void main()

    {

    clrscr();

    float r,d,c,a;

    coutr;

    d=2*r;

    c=2*3.14*r;

    a=3.14*r*r;

    cout

  • 8/6/2019 Practical No1

    11/91

    Practical No 16#include

    #includevoid main()

    {clrscr();

    float km,m,ft,inch,cm;coutkm;m=km*1000;

    cm=m*100;inch=cm/2.54;

    ft=inch/12;cout

  • 8/6/2019 Practical No1

    12/91

    cout

  • 8/6/2019 Practical No1

    13/91

    Practical no 19#include#include

    void main(){

    clrscr();int num1,num2,temp;

    coutnum1;

    coutnum2;

    temp=num1;num1=num2;

    num2=temp;cout

  • 8/6/2019 Practical No1

    14/91

    }

    Practical no 20

    #include

    #includevoid main()

    {clrscr();

    int num1,num2;coutnum1;coutnum2;num1=num1+num2;

    num2=num1-num2;num1=num1-num2;

    cout

  • 8/6/2019 Practical No1

    15/91

    Practical no 21

    #include#include

    void main(){

    clrscr();int num,fstd,sd,td,frd;

    int a,b,c;coutnum;fstd=num/1000;a=num%1000;

    sd=a/100;b=a%100;

    td=b/10;c=b%10;frd=c;cout

  • 8/6/2019 Practical No1

    16/91

    Practical no 22

    #include

    #includevoid main()

    {int marks;

    coutmarks;

    if(marks>=50)cout

  • 8/6/2019 Practical No1

    17/91

    cout

  • 8/6/2019 Practical No1

    18/91

    Practical no 25

    #include#include

    void main(){

    clrscr();cout

  • 8/6/2019 Practical No1

    19/91

    if(num%2==0)cout

  • 8/6/2019 Practical No1

    20/91

    Practical no 28#include

    #includevoid main()

    {clrscr();

    int month;coutmonth;month%4==0?cout

  • 8/6/2019 Practical No1

    21/91

    if(speed>=1 && speed

  • 8/6/2019 Practical No1

    22/91

  • 8/6/2019 Practical No1

    23/91

    #include#include

    void main(){

    clrscr();

    cout

  • 8/6/2019 Practical No1

    24/91

    coutnum3;

    min=num1;if(num1>num2)

    min=num2;

    if(num1>num3)min=num3;cout

  • 8/6/2019 Practical No1

    25/91

    Practical No 35

    #include#includevoid main(){clrscr();cout

  • 8/6/2019 Practical No1

    26/91

    Practical No 36#include#includevoid main(){cout

  • 8/6/2019 Practical No1

    27/91

    Practical No 37

    #include#includevoid main()

    {cout

  • 8/6/2019 Practical No1

    28/91

    else if(num1==num2 && num2==num3 && num1==num3){

    cout

  • 8/6/2019 Practical No1

    29/91

    {clrscr();cout

  • 8/6/2019 Practical No1

    30/91

    {clrscr();cout

  • 8/6/2019 Practical No1

    31/91

    cin>>c;

    couta;coutb;

    switch(c)

    {case 1:

    {d = a+b;

    cout

  • 8/6/2019 Practical No1

    32/91

    getch();

    }

    Practical no 41#include#include

    void main(){

    clrscr();cout

  • 8/6/2019 Practical No1

    33/91

    case 'O':case 'o':

    cout

  • 8/6/2019 Practical No1

    34/91

    cout

  • 8/6/2019 Practical No1

    35/91

    cout

  • 8/6/2019 Practical No1

    36/91

    switch(ft){ case 1:cout

  • 8/6/2019 Practical No1

    37/91

    case 6:cout

  • 8/6/2019 Practical No1

    38/91

    Practical no 46#include#include

    void main(){

    int i,n;

    cout

  • 8/6/2019 Practical No1

    39/91

    Practical no 47

    #include#include

    void main()

    {int i,s,e;couts;coute;for(i=0;i

  • 8/6/2019 Practical No1

    40/91

    Practical no 48#include

    #includevoid main()

    {

    int i;for(i=0;i

  • 8/6/2019 Practical No1

    41/91

    Practical no 49

    #include#include

    void main(){

    int i,n;coutn;for(i=0;i

  • 8/6/2019 Practical No1

    42/91

    Practical no 51

    #include

    #includevoid main()

    {int i,s,e;

    couts;

    coute;

    for(i=s;i

  • 8/6/2019 Practical No1

    43/91

    getch();}

    }

    Practical no 53

    #include#include

    void main(){

    int i,s,e;couts;coute;for(i=s;i

  • 8/6/2019 Practical No1

    44/91

    Practical no 55#include

    #includevoid main()

    {clrscr();

    int i=0,j=0;for(i=1;i

  • 8/6/2019 Practical No1

    45/91

    cout

  • 8/6/2019 Practical No1

    46/91

    Practical no 58

    #include

    #includevoid main()

    {clrscr();

    int i=0,j=0;for(i=1;i=i;j--)

    cout

  • 8/6/2019 Practical No1

    47/91

    cout

  • 8/6/2019 Practical No1

    48/91

    Practical no 63

    #include

    #includevoid main()

    {

    clrscr();int num,k,fact;coutnum;for(int i =1;i

  • 8/6/2019 Practical No1

    49/91

    cout

  • 8/6/2019 Practical No1

    50/91

    Practical no 66

    #include#includevoid main()

    {clrscr();

    cout

  • 8/6/2019 Practical No1

    51/91

    Practical No.74Task: Write a program that accept a number from the user as an input and calculates the square of a given number using function.Solution:

    //This program calculates the square of a given number

    #include

    #include

    // Function declarations.

    int square(int);

    void main()

    {

    int number=0, result=0;

    clrscr();

    cout number;

    // Calling the function square(int number)

    result = square(number);

    cout

  • 8/6/2019 Practical No1

    52/91

    SOLUTION:

    #include

    #include

    void eveodd(int);

    void main()

    {

    int num ;

    clrscr();

    coutnum;

    eveodd(num);

    getch();

    }

    void eveodd(int num)

    {

    if(num%2==0)

    cout

  • 8/6/2019 Practical No1

    53/91

    clrscr();

    int num1,num2,num3;

    coutnum2;

    cout>num3;

    min(num1,num2,num3);

    getch();

    }

    void min(int num1, int num2, int num3)

    {if(num1

  • 8/6/2019 Practical No1

    54/91

    Task: Write a program that calculates the area of the Ring using a single function.

    Solution:

    #include

    #include

    void ring(int a,int b);void main()

    {

    clrscr();

    int o,i;

    couto;

    couti;

    ring(o,i);

    cout

  • 8/6/2019 Practical No1

    55/91

    base exponentFor example, integerPower( 3, 4 ) = 3 * 3 * 3 * 3. Assume that exponent is apositive, nonzero integer and that base is an integer. The function integerPowershould use for or while to control the calculation. Do not use any math libraryfunctions.

    SOLUTION:

    #include

    #include

    void raise2pow(double,int);

    void main()

    {

    double result,x;

    clrscr();

    int pow;coutx;

    coutpow;

    raise2pow(x,pow);

    getch();

    }

    void raise2pow(double x, int pow){

    double result = 1.0;

    for(int i=0;i

  • 8/6/2019 Practical No1

    56/91

    Practical No. 78

    Task: An integer number is said to be a perfect numberif the sum of its factors,including 1 (but not the number itself), is equal to the number. For example, 6 isa perfect number, because 6 = 1 + 2 + 3. Write a function perfect that determineswhether parameter number is a perfect number. Use this function in a programthat determines and prints all the perfect numbers between 1 and 1000. Print thefactors of each perfect number to confirm that the number is indeed perfect.

    SOLUTION:#include

    #include

    void perfect(int);

    void main()

    {

    clrscr();

    int num;

    cout

  • 8/6/2019 Practical No1

    57/91

    }

    }

    }

    OUTPUT:

    Practical No. 79Task: A positive integer is entered through the keyboard. Write a function toobtain the prime factors of this number.For example: Prime factors of 24 are 2, 2, 2 and 3, whereas prime factors of 35 are

    5 and 7. Practical No. 80Task: Write a function that takes an integer value and returns the number withits digits reversed.For example, given the number 7631, the function should return 1367.

    SOLUTION:

    #include

    #include

    void rev(int);

    void main()

    {

    clrscr();

    int num;

    cout

  • 8/6/2019 Practical No1

    58/91

    c=((num/100) % 10);

    d=((num/100) / 10);

    cout

  • 8/6/2019 Practical No1

    59/91

    double roundToInteger( double );

    double roundToTenths( double );

    double roundToHundreths( double );

    double roundToThousandths( double );