001 Answers to Ex.no-11

Embed Size (px)

Citation preview

  • 8/10/2019 001 Answers to Ex.no-11

    1/14

    alif=ari-1/ 24osi=iterri

    i=1

    ( S t o p )

    Computer Practice I 1 Lab Manual

    . AIM: To wr i te a program to inser t an e lement to an a r ray in the g iven

    ....... position

    ALGORITHM

    Step-1 Sta rt the programStep-2 Ent er the s iz e of the arr ay

    Step-3 Ent er th e ele men ts of the arr ay

    Step-4 Pri nt th e ele men ts of the arr ay

    Step-5 Ente r the e lemen t to be inse r ted and i ts posi t ion in the

    array

    Step-6 Set a loo p up to the pos i t i on you ent er

    Step-7 Push the orde r of the pos i t i on by one, whic h are grea ter ,then the posi t ion you entered

    Step-8 Inse rt the eleme nt in the posi tio n ente red by youStep-9 Prin t the arra y afte r inse rti on of the eleme nt

    Step-10 Stop

    FLOWCHART

    / * I N S E R T I N G AN E L E M EN T S I N T O T H E V ECT O R * /#inelude

    main()

    Iint 41001,no,i,pos,item;

    pr in t f (" tnEn ter the s i ze o f the an array" );

  • 8/10/2019 001 Answers to Ex.no-11

    2/14

  • 8/10/2019 001 Answers to Ex.no-11

    3/14

    a=numiiinunifij

    --numtij

    nurniji=a

    Computer Practice I 3 Lab Manual

    Step-9 Afte r the execu t ion o f the inne r loop the ou te r loop i s execu tes

    S t e p - 1 0 P r i n t t h e a s c e n d i n g o r d e r o f t h e g i v e n a r r a y .

    S t e p - 1 1 P r i n t t h e d e s c e n d i n g o r d e r o f t h e g i v e n a r r a y . S t ep- 12 Sto p .

    *AS .I A N D D E S C E N D I N G O R D E R O F T H E G I V E N U 1 B E

    #include < stdio.h>

    main()

    Iint numil 00j, no,i , j ,a;

    print f ("Enter Upper Limit . . . " );

    seanf("%d" ,&no);

    prat ("Enter` the numbers") ;

    fora =0;i < no;i )

    scanf (` %d" ,&numf i j )

    0,1

  • 8/10/2019 001 Answers to Ex.no-11

    4/14

    Computer Practice I 4 Lab Manual

    numb:1=a;

    I

    p t in t f ( " 1nThe ascend in g order o f th e g iven number s" ) ;

    f o r (1 --=0; i

  • 8/10/2019 001 Answers to Ex.no-11

    5/14

    large = ajarsmall= al

    -01

    print largeisrnan

    s sn

    Computer Practice I 5 Lab Manual

    / / F I N D T H E L A R G E S T A N D S M A L L E S T O F T H E G I V E N A R R A Y

    #inelude

    main()

    I

    jut a[1001,i,small,large,no;

    p r i n t f ( " I n h o w m a n y n u m b e r s y o u w a n t t o f i n d . . . .

    scarf( `{%d",&no);

    p r i n t f ( " Ent er t he e l e me nt s o f th e a r r ay . . . . " ) ;fora =0;i

  • 8/10/2019 001 Answers to Ex.no-11

    6/14

    Computer Practice 6 Lab Manual

    f o r ( i = 1 ; i < no ; i 4 - ){

    i f ( af i l > l a rge)

    large = a/if ;

    el se i f (a f i l < smal l )

    small ----=a111;

    p r i n t f ( " I n T h e l a r g est o f t h e g i v en a r r a y i s %d " , l a r g e) ;

    p r i n t f r I n T h e sma l l e st o f t h e g i v en a r r a y i s %d " , sm a l l ) ;

    I

    SAMPLE OUTPUT:

    I n h o w m a n y n u t n b e r s y o u w a n t t o n d . . . . 5

    E n t er t h e el emen t s o f t h e a r r a y ..34 5 6 8 7 4 3

    Th e e l emen t s o f t h e a r r a y12 34 5 6 8 7 4 3

    T h e l a r g est o f t h e g i v en a r r a y i s 87

    Th e sma l l e st o f t h e g i v e n a r r a y i s 12

    4. AIM: To wri te a progra m to add two matr ice s .

    ALCORITII

    Step-1 Start the program. Step-2 E n t e r t h e r o w a n d c o l u m n o f t h e m a t r i x

    S t e p - 3 - E n t e r t h e e l e m e n t s o f t h e A m a t r i x .

    Step-4 E n t e r t h e e l e m e n t s o f t h e B m a t r i x ,

    Step-5 P r i n t t h e A m a t r i x i n t h e m a t r i x f o r m .

    Step-6 P r i n t t h e 1 3 m a t r i x i n t h e m a t r i x f o r m .

    Step-7 S e t a l o o p u p t o t h e r o w .

    Step-8 S e t a i n n e r l o o p u p t o t h e c o l u m n .

    Step-9 A d d t h e e l e m e n t s o f A a n d B i n c o l u m n w i s e a n d s t o r e t h e

    resul t in C matr ix .

    S t e p - 1 0 A f t e r t h e e x e c u t i o n o f t h e t w o l o o p s . P r i n t t h e v a l u e o f C

    matrix.

    Step-11 Stop.

  • 8/10/2019 001 Answers to Ex.no-11

    7/14

    Computer Practice I 7 Lab Manual

    for i = 0 to n >

    /Print("\n")!

    for j = 0 to n >

    t i l f i l =

    4.P r i n t O l i n

    CStop

    Star t )

    /Read m, rn, n

    for i= 0 to In

    for j = 0 to n

    Re a d a p t l y

    7 / F I N D T H E A D D I T I O N OF I W O M A T R I X E S#inc ludemain()

    I i n t a [ .51125 j ,025#25 ] ,4251125j , i , f ,m ,71;p r i n t f ( " En t e r t h e r ows and col u mn o f two ma t r i x e si n " ) ;scan f ( " %d %d" ,&m ,& n ) ;p t i n t f ( " i n E n t e r t h e el emen t s o f A mat r i x . .. " ) ;f o r ( i = 0 ; i

  • 8/10/2019 001 Answers to Ex.no-11

    8/14

    Computer Practice I 8 Lab Manual

    prin tf(" terod",a fil 11 1);1

    p r i n t f ( " i n Th e e l e men t s o f B ma t r i x " ) ;

    fora= 0;i < nt;i + +)

    Print f ("i n " );

    for(1=---04

  • 8/10/2019 001 Answers to Ex.no-11

    9/14

    Computer Practice I 9 Lab Manual

    S t e p - 7 P r i n t t h e e l e m e n t s o f t h e B m a t r i x i n m a t r i x f o r m

    S t e p - 8 S e t a l o o p u p t o r o w

    S t e p - 9 S e t a i n n e r l o o p u p t o c o l u m n

    S t e p - 1 0 S e t a n o t h e r i n n e r l o o p u p t o c o l u m n S t e p - 1 1 M u l t i p l y t h e A a n d B m a t r i x a n d s t o r e t h e e l e m e n t i n t h e C

    matrix

    Step-1 2 Print the resul tant matr ixStep-13 Stop

    0 CAA - RT

    PROGRAM

    / 7 MUL TPL ICAT I ON OF T WO MATR IX#include

    main()1

    int a12.511251,b12511251,c12511257,ij,k,r,s;int in, n;

    pr int f (" inEnter the Rows and Columns of A matri x. . ." );scan f("%d %d",&m,&n);pr i n t f (" inEnter the Ro ws and Colu mns o f B ma tr i x . . . " ) ;

  • 8/10/2019 001 Answers to Ex.no-11

    10/14

  • 8/10/2019 001 Answers to Ex.no-11

    11/14

    Computer Practice I 11 Lab Manual

    for(j=0;j

  • 8/10/2019 001 Answers to Ex.no-11

    12/14

    Computer Practice I12 Lab Manual

    pr in t pa l in drome/

    Stop

    )

    -

    Yes

    Yes

    print not a

    palindrome

    C s t o p

    I

    T O F I N D W H E T H E R T H E G I V E N S T R I N G I S P . A L I N D R O M E O R N O Tffinclude #includemain()I

    int len=0,i, j;char name[251;

    p r in t f (" Enter th e s t r ing . . ." ) ;scanf("%s",name);

    while(namellenj! =109len+ -;

    pr in t f (" Ingod" , l en); f o r ( i =0 , j = -

    1 e n - 1 ; i < l e n t 2; i j - - )I

    i f fnamerill =nameffl)I

    pr int f (" InThe given s t r ing i s no t a pal indrom");exit(0);

    I

  • 8/10/2019 001 Answers to Ex.no-11

    13/14

    ART

    c=c-FI

    i=

    c a s e i a ' , ' A I V ' E t , i i i , ; o11

    Computer Practice I 13 Lab Manual

    p r i n t f ( " t n Th e g i v en st r i n g i s a p al i n d r ome" ) ;

    SM/IPLE OUTPUT

    En t e r t h e St r i n g

    . ma l a ya l am

    9

    The g i ven s t r i n g i s a pa l i n d r ome

    7. A I M : T o w r i t e a p r o g r a m t o f i n d t h e n u m b e r o f c o n s o n a n t s a n d

    vowels present in the string.

    I t t e

    Step-1 Start the program

    Step-2 Enter the string

    Step-3 Construc t the swi th s ta tement Step-4 Pr in t t h e n u mb e r o f v o w e l s p r e s e n t i n t h e g iv e n s t r i n g

    Step-5 Pr in t t h e n u mb e r o f c o n s o n e n t s p r e s e n t i n t h e g iv e n s t r i n g

    Step-6 Stop

    C Start

    read str

    print v,

    Stop

    ssn

  • 8/10/2019 001 Answers to Ex.no-11

    14/14

    Computer Practice I 14 Lab Manual

    PROGRAM

    / /TO FIND THE No. VOWLES AND No. OF CONSONANTS IN A GIVEN STRING

    #includemain()I

    int v=0,c=-0,i=0;char str1251;

    printf("Enter the string... "1.scanf("%s",str);while(strfill =10')I

    switch(strfij)I

    default:

    Ii+ +;

    case 'a':

    case 'A':ease 'E.':

    casecase V':case 'II':case 'e':casecase V;case 'a':v+ +;break;

    c+ +;

    Iprintf("tnThe number of vowels is %d",v);printf("1nThe number of consonants is %d",c);getch();

    SAMPLE OUTPUT:

    Enter the str ing.. . RAJAThe number of vowels is 2

    The number of consonants is 2