Code Switching and Code Mixing in Indonesia Study in SociolinguisticsDeskripsi lengkap
Full description
Advanced Encryption Standard AES algorithm is one of the most common and widely used symmetric block cipher algorithm. This algorithm has its own particular structure to encrypt and decrypt sensitive data and is applied in hardware and software, all
Circle and Ellipse Drawing Algorithm
Linking words to improve writing.
LEX PROG
LEX PROG
Descripción completa
Full description
All basic c++ programs that a beginner would needFull description
C++ Programs Collection provided by http://www.loookinto.blogspot.com/ For More help in c++ programing check this forum http://programmersheaven.usersboard.com here you can post your doubts.
SAMPLE PROGRAMS: 1.AIM: To write a program to find the area and circumference of the circle. ALGORITHM: Step-1 Ste p-2 Step Step-3 -3
Stepep-4 Ste p-5
Start the program. Input the radius of the circle. Find Find the the area area and and circ circum umfe fere renc nce e of the the circ circle le usin using g the the formula Area=3.14*r*r Circumference=2*3.14*r Pri Print th the ar area an and th the ci circumf umferenc ence of of the the circl rcle S top
PROGRAM: /*TO FIND THE AREA AND CIRCUMFERENCE OF THE CIRCLE*/ #include main() { float rad,area,circum; printf(“\nEnter the radius of the circle”); scanf(“%f”,&rad); area=3.14*rad*rad; circum=2*3.14*rad; printf(“\nArea=%f”,area); printf(“\nCircumference=%f”,circum); } SAMPLE INPUT AND OUTPUT: Enter the radius of the circle 5 Area=78.500000 Circumference=31.400000
2. AIM: To write a program to insert an element in an array in the given position ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4 Step Step-5 -5 Ste p-6 Step Step-7 -7
Start the program Enter the size of the array Enter the elements of the array Print the elements of the array Ente Enter r the the elem elemen ent t to be inse insert rted ed and and its its posi positi tion on in the the array Set a lo loop up up to to the position you en enter Push Push the the orde order r of of the the posi positi tion on by one, one, whic which h are are grea greate ter, r, then the position you entered
Step-8 Stepep-9 Ste p-10
Insert the element in the position entered by you Pri Print the array after ter inse nsertio tion of the eleme ement S top
PROGRAM: /*INSERTING AN ELEMENTS INTO THE VECTOR*/ #include main() { int a[100],no,i,pos,item; printf(“\nEnter the size of the matrix”); scanf(“%d”,&no); printf(“\nEnter the elements of the matrix”); for(i=0;i=pos;i-) a[i]=a[i-1]; a[-pos]=item; printf(“\n”); printf(“\nArray after the insertion”); for(i=0;i
3.AIM: To write a program to print the ascending and descending order of the given array. ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4 Ste p-5 Step Step-6 -6
Start Enter Enter Set a Set a Chec Check k
the program the size of the array the elements of the array loop up to the array size minus one inner loop up to the size of the array whe wheth ther er the the nex next t arr array ay elem elemen ent t is is gre great ater er than than or not not
If greater than exchange their position If not greater th than th then go go to to the loop Afte After r the the exec execut utio ion n of the the inne inner r loop loop the the oute outer r loop loop is executed Prin Print t the the asce ascend ndin ing g orde order r of the the give given n arra array y Prin Print t the the desc descen endi ding ng orde order r of the the giv given en arra array y S top
PROGRAM: /*ASCENDING AND DESCENDING ORDER OF THE GIVEN NUMBERS*/ #include main() { int num[100],no,i,j,a; printf(“Enter Upper Limit...”); scanf(“%d”,&no); printf(“Enter the numbers”); for(i=0;i=0;j-) printf(“\n%d”,num[j]); } SAMPLE OUTPUT Enter the number how many number you want to sort 5 Enter the numbers 10 30 50 60 20 The ascending order of the given numbers 10 20 30 50 60 The descending number of the given numbers 60 50 30 20 10
4.AIM: To write a program to convert the binary number into decimal number ALGORITHM:
Ste p-1 Ste p-2 Ste p-3 Step Step-4 -4
Step Step-5 -5 Ste p-6
Start the program Enter the binary value Set a loop Conv Conver ert t the the bina binary ry numb number er into into deci decima mal l by by usi using ng stat statem emen ent t given below Find the digit decimal=decimal+(digit<
PROGRAM: //CONVERT BINARY NUMBER INTO DECIMAL NUMBER #include main() { int bnum,digit,decimal=0,bin,base=0; printf(“\nEnter the binary number...”); scanf(“%d”,&bnum); printf(“%d”,bnum); bin=bnum; while(bnum!=0) { digit=bnum%10; decimal=decimal+(digit<
5.AIM: To write a program to find the cosine value of the given x ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4 Step-5
Stepep-6 Ste p-7 PROGRAM:
Start the program Enter the value of X Convert X into radian Set a loop Find the value of cosine using the formula temp=temp*pow((double)(-1),(double)(2*i-1))*x*x/(2*i*(2*i-1)); sum=sum+temp; Aft After th the ex execut cution of of th the lo loop pr print th the co cosine value lue S top
// TO FIND THE COSINE VALUE #include #include main() { float x,a,sum,temp; int i,no=20,mul; printf(“\nEnter the value of x”); scanf(“%f”,&x); a=x; x=x*3.1412/180; temp=1;sum=1; for(i=1;i
6.AIM: To write a Program to find the exponent of the given
number
ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4
Step Step-5 -5 Ste p-6
Start the program Enter the x value and n value Set a loop up to n Find the exponent value of x temp=temp*x/i sum=sum+temp Afte After r the the exec execut utio ion n of of the the loop loop prin print t the the expo expone nent nt valu value e of of x S top
PROGRAM: //EXPONENTIAL SERIES #include main() { float x,temp=1,sum=1; int i,no; printf(“Enter the numbers”); scanf(“%f %d”,&x,&no); for(i=1;i
printf(“Exponent of x is %f\n”,sum); } SAMPLE OUTPUT: Enter the numbers 5 5 Exponent of x is 65.375000
7.AIM: To write a program to find the factorial of the given number ALGORITHM: Step-1 Ste p-2 Ste p-3
Start the program Ente r a numbe r Set a loop to find the factorial of the given number using the formula Fact=Fact*I Print the factorial of the given number Stop
Ste p-4 Ste p-5 PROGRAM:
//TO FIND THE FACTORIAL OF THE GIVEN NUMBER #include main() { int fact=1,i,num; printf(“Enter the number”); scanf(“%d”,&num); for(i=1;i<=num;i++) { fact=fact*i; } printf(“The factorial of %d is %d”,num,fact); }
SAMPLE INPUT AND OUTPUT: Enter the number 5 The factorial of 5 is 120
8.AIM: To write a program to convert the Celsius into Fahrenheit ALGORITHM: Ste p-1 Ste p-2 Step-3
Start the program. Enter the Celsius value. Calculate the Fahrenheit value by using the formula given below. Fahreheit=(1.8*Celsius)+32
Step-4 Ste p-5
Print the Fahrenheit value S top
PROGRAM: //CONVERT THE CELCIUS INTO FAHRENTEIET #include main() { float cel,faren; printf(“Enter the Celsius value...”); scanf(“%f”,&cel); faren=(1.8*cel)+32; printf(“The fahrenteiet value of the given %f celsius value is %f”,cel,faren); } SAMPLE INPUT AND OUTPUT Enter the Celsius value...45 The fahrenteiet value of the given 45.000000 celsius value is 113.000000
9.AIM: To write a program to generate the fibbonaci series ALGORITHM: Ste p-1 Ste p-2 Step Step-3 -3 Ste p-4 Ste p-5
Stepep-6 Stepep-7
Start the program Enter the number Chec Check k the the numb number er whet whethe her r the the numb number er is zero zero or not. not. If zero zero print Zero value. If not zero go further. Set a loop up to the given number. f ib=f ib+a; a=b; b=c; Eve Every in increm rement in th the lo loop pr prints the va value lue of of fi fib. Aft After th the ex execut cution of of the the loo loop sto stops th the pr program ram
PROGRAM: //TO PRINT THE FIBBONACI SERIES UPTO GIVEN NUMBERS #include main() { int num,fib=0,a=0,b=1,i; printf(“Enter the number”); scanf(“%d”,&num); printf(“\n FIBBONACI SERIES\n”); if(num==0) printf(“0”); else { for(i=0;i
b=fib; printf(“%d\t”,fib); } } } SAMPLE INPUT AND OUTPUT Enter the number 5 FIBONACCI SERIES 0 1 1 2 3 10.AIM: To write a program to store the data in a file and read the data from the file. ALGORITHM: Ste p-1 Ste p-2 Stepep-3 Ste p-4 Stepep-5 Ste p-6 Stepep-7 Ste p-8 Ste p-9
Start the program Initialize the file pointer Ope Open th the fil file in in the write ite mod mode usi using fi file po pointe nter Enter the data Sto Store th the da data in in th the fil file e us using th the pu putc() state atement Close the file Ope Open th the fi file in in the the read mode ode usi usin ng th the fi file po pointer Print the data in the file E nd
PROGRAM: //DATA FILE #include main() { FILE *fp; char c; fp=fopen(“Write”,”w”); printf(“Enter the text....”); while((c=getchar())!=EOF) putc(c,fp); fclose(fp); printf(“The entered data is....”); fp=fopen(“Write”,”r”); while((c=getc(fp))!=EOF) printf(“%c”,c); fclose(fp); } SAMPLE OUTPUT: Enter the text.... Welcome to ‘C’ language ^Z The entered data is.... Welcome to ‘C’ language
11.AIM: Program to illustrate functions without arguments and no return values.
Start the program Declare the function Call the function Enter the String Print the string End the program in the calling function
PROGRAM: //FUNCTIONS WITH OUT ARGUMENTS AND NO RETURN VALUES #include main() { void message(void); message(); } void message() { char str[100]; printf(“Enter a string........”); scanf(“%s”,str); printf(“WELCOME TO...%s”,str); } SAMPLE OUTPUT: Enter a string LAK WELCOME TO LAK
12.AIM: To write a program to illustrate function with arguments and no return value. ALGORITHM: Ste p-1 Ste p-2 Step Step-3 -3 Ste p-4 Ste p-5 Ste p-6
Start the program Enter the two numbers Call Call the the func functi tion on with with argu argume ment nts s pass passin ing g to the the call callin ing g function Add th the tw two nu numbers in in th the ca calling fu function Print the addition of two values End the program in the calling function
PROGRAM: //FUNCTIONS WITH ARGUMENTS BUT NO RETURN VALUES #include main() { int a,b; printf(“Enter two numbers....”); scanf(“%d%d”,&a,&b); add(a,b);
} add(int a,int b) { int c; c=a+b; printf(“The addition of two numbers %d and %d is %d”,a,b,c); } SAMPLE OUTPUT Enter two numbers....10 20 The addition of two numbers 10 and 20 is 30
13.AIM: Program to illustrate parameter passed to the function. ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4 Step Step-5 -5 Step Step-6 -6 Ste p-7 Step Step-8 -8 Ste p-9 Stepep-10
Start the program Enter the size of the array Enter the elements of the array Print the array elements Call Call the the fun funct ctio ion n wit with h bas base e add addre ress ss of the the arr array ay pass passed ed to it In the the cal calli ling ng func functi tion on gets gets the the bas base e add addre ress ss in the the poi point nter er variable Add the array elements Retu Return rn the the val value ue from from the the cal calli ling ng func functi tion on to the the var varia iabl ble e in in the called function Print the sum in the called function End End the the prog rogram in the mai main functio tion
PROGRAM: //illustrate parameter passed to the function #include main() { int a[10],i,no,sum=0; printf(“Enter the size of array...”); scanf(“%d”,&no); printf(“Enter the elements of the array...”); for(i=0;i
return(a); } SAMPLE OUTPUT: Enter the size of array... 5 Enter the elements of the array ... 1 2 3 4 5 1 2 3 4 5 The sum of 5 numbers is... 15
14.AIM: To write a program to illustrate a function with arguments values.
Start the program Enter the two numbers Cal Call th the fun functio tion wit with two two arg argument ents pas passed to it it Add th the tw two nu numbers in in th the ca calling fu function Retu Return rn the the add addit itio ion n val value ue to the the cal calle led d func functi tion on from from the the calling function Pri Print the additi ition value in the mai main fun functio tion E nd
PROGRAM: //FUNCTION WITH ARGUMENTS AND RETURN VALUES #include main() { int a,b,c; printf(“Enter the two numbers...”); scanf(“%d %d”,&a,&b); c=add(a,b); printf(“The addition of two numbers %d and %d is %d”,a,b,c); } add(int x,int y) { int z; z=x+y; return(z); } SAMPLE OUTPUT: Enter the two numbers... 5 6 The addition of two numbers 5 and 6 is 11
15.AIM: To write a program to find the largest and smallest of the given array. ALGORITHM:
Start the program Enter the size of array Enter the elements of the array Print the array elements Init Initia iali lize ze the the lar large ge and and sma small ll is equa equal l to to the the firs first t ele eleme ment nt of the array Set a loop up to the array size Che Check th the ne next el elemen ment gre greater ter then hen the larg arger. If greater then as sign next element to the large Chec Check k the the next next elem elemen ent t smal smalle ler r then then the the larg larger er. . If If smal smalle ler r then assign next element to the small Prin Print t the the valu value e of of lar large ge and and sma small ll afte after r the the exec execut utio ion n of of the the loop S top
PROGRAM: //FIND THE LARGEST AND SMALLEST OF THE GIVEN ARRAY #include main() { int a[100],i,small,large,no; printf(“In how many numbers you want to find....”); scanf(“%d”,&no); printf(“Enter the elements of the array....”); for(i=0;ilarge) large=a[i]; else if(a[i]
16.AIM: To write a program to give the addition of two matrixes.
Start the program Enter th the ro row an and column of of th the matrix Enter the elements of the A matrix Enter the elements of the B matrix Print the A matrix in the matrix form Print the B matrix in the matrix form Set a loop up to the row Set a inner loop up to the column Add Add th the ele elem ments nts of of A and B in in col colu umn wi wise an and st store th the result in C matrix Afte After r the the exec execut utio ion n of of the the two two loop loops. s. Prin Print t the the val value ue of C matrix S top
PROGRAM: // FIND THE ADDITI ITION OF TWO TWO MAT MATRIXES XES #include main() { int a[25][25],b[25][25],c[25][25],i,j,m,n; printf(“Enter the rows and column of two matrixes...\n”); scanf(“%d %d”,&m,&n); printf(“\nEnter the elements of A matrix...”); for(i=0;i
c[i][j]=a[i][j]+b[i][j]; printf(“\t%d”,c[i][j]); } } } SAMPLE OUTPUT: Enter the rows and column of two matrixes... 3 3 Enter the elements of A matrix... 1 2 3 4 5 6 7 8 9 Enter the elements of B matrix... 1 2 3 4 5 6 7 8 9 The elements of A matrix 1 2 3 4 5 6 7 8 9 The elements of B matrix 1 2 3 4 5 6 7 8 9 The addition of two matrixes 2 4 6 8 10 12 14 16 18
17.AIM: To write a program to multiply two matrixes. ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4 Ste p-5 Stepep-6 Stepep-7 Ste p-8 Ste p-9 Ste p-10 Step-11 Ste p-12 Ste p-13
Start the program Enter the row and column of the A matrix Enter the row and column of the B matrix Enter the elements of the A matrix Enter the elements of the B matrix Pri Print th the el elemen ments of of the A ma matrix in ma matrix rix form orm Pri Print th the el elemen ments of of the B ma matrix in ma matrix rix form orm Set a loop up to row Set a inner loop up to column Set an another in inner lo loop up up to to co column Multiply the A and B matrix and store the element in the C matrix Print th the re resultant ma matrix S top
PROGRAM: // MULTPLICATION OF TWO MATRIX #include main() { int a[25][25],b[25][25],c[25][25],i,j,k,r,s; int m,n; printf(“\nEnter the Rows and Columns of A matrix...”); scanf(“%d %d”,&m,&n); printf(“\nEnter the Rows and Columns of B matrix...”); scanf(“%d %d”,&r,&s);
if(m!=r) printf(“\nThe matrix cannot multiplied”); else { printf(“\nEnter the elements of A matrix”); for(i=0;i
1 2 3 4 5 6 7 8 9 The elements of B matrix 1 2 3 4 5 6 7 8 9 The multiplication of two matrixes 30 36 42 66 81 96 102 12 6 1 50
18.AIM: To find sum of Digits, Reverse and the given Number is Palindrome or not. ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4 Ste p-5 Ste p-6 Step Step-7 -7 Stepep-8 Stepep-9 Ste p-10
Start the program Enter the number Set a loop up upto th the nu number is is no not eq equal to to ze zero Find the digit of the number Find the sum of digit Find the reverse number Afte After r the the end end of the the loop loop prin print t the the sum sum and and reve revers rse e numb number er the digit Fin Find whethe ther the rev reverse numb umber is equa qual to the given ven number or not. If equal the number is palindrome If not equal ual the the give iven num number is not pal palindr ndrome S top
PROGRAM: /* PROGRAM TO FIND THE SUM AND REVERSE OF THE GIVEN NUMBER*/ #include main() { unsigned long int a,num,sum=0,rnum=0,rem; printf(“\nEnter the number...”); scanf(“%ld”,&num); a=num; while(num!=0) { rem=num%10; sum=sum+rem; rnum=rnum*10+rem; num=num/10; } printf(“\nThe sum of the digits of %ld is %ld\n”,a,sum); printf(“\nThe reverse number of the %ld is %ld”,a,rnum); if(a==rnum) printf(“\nThe given number is a palindrome”); else printf(“\nThe given number is not a palindrome”); } Sample output:
of
Enter the number...12321 The sum of the digits of 12321 is 9 The reverse number of the 12321 is 12321 The given number is a palindrom
19.AIM: To write a program to find the roots of the quadratic equation. ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Step Step-4 -4
Step Step-5 -5 Ste p-6
Start the program Enter the value of a, b, c Find th the va value of of d by us using th the fo formula D=b*b-4*a*c If D is is grea greate ter r then then or equa equal l to zero zero then then find find the the two two root roots s as root1=(-b+sqrt(d))/(2*a); root2=(-b-sqrt(d))/(2*a); Print the two roots If the the D is not not grea greate ter r the then n or or equa equal l to to zero zero then then prin print t the the statement the roots are imaginary. S top
PROGRAM: // To find the roots of the quadratic equation #include #include main() { int a,b,c,d; float root1,root2; printf(“Enter the values of a,b,c\n”); scanf(“%d %d %d”,&a,&b,&c); d=b*b-4*a*c; if(d>=0) { root1=(-b+sqrt(d))/(2*a); root2=(+b+sqrt(d))/(2*a); printf(“The roots of the values a=%d,b=%d,c=%d are\n %f %f”,a,b,c,root1, root2); } else printf(“The roots are imagenary”); } SAMPLE OUTPUT: Enter the values of a,b,c 1 0 -9 The roots of the values a=1,b=0,c=-9 are 3.000000 3.000000
20.AIM: To write a program to find the factorial of the given number using recursion
Start the program Enter the number Call Call the the recu recurs rsiv ive e func functi tion on pass passin ing g the the numb number er to the the recu recurs rsiv ive e func functi tion on as an argu argume ment nt. . If the the ent enter ered ed numb number er is equa equal l to to one one then then retu return rn one one to to mai main n function. If the the numb number er is less less grea greate ter r then then one one the then n call call recu recurs rsiv ive e Print the factorial value of the number. S top
PROGRAM: #include main() { int num,a; printf(“Enter the number”); scanf(“%d”,&num); a=recur(num); printf(“The factorial of the number %d is %d”,num,a); } recur(int no) { int fact=1; if(no==1) return(1); else fact=no*recur(no-1); } SAMPLE OUTPUT: Enter the number 5 The factorial of the number 5 is 120
21.AIM: To write a program to find whether the string is palindrome or not. ALGORITHM: Ste p-1 Ste p-2 Stepep-3 Ste p-4 Ste p-5 Step Step-6 -6 Step Step-7 -7 Step Step-8 -8 Ste p-9 PROGRAM:
Start the program Enter the string Fin Find th the st string lengt ngth us using th the st strlen( en() fu functio tion Print the string length Set a loop up up to to th the ha half of of th the st string le length Comp Compar are e eve every ry char charac acte ter r abo above ve the the mid middl dle e cha chara ract cter er with with the the below character of the middle character If any any cha chara ract cter er equa equal l pri print nts s the the give given n str strin ing g is is pal palin indr drom ome e If the the cha chara ract cter er is not not equ equal al then then prin print t the the give given n str strin ing g is is not a palindrome S top
//TO FIND WHETHER THE GIVEN STRING IS PALINDROME OR NOT #include #include main() { int len=0,i,j; char name[25]; printf(“Enter the string...”); scanf(“%s”,name); while(name[len]!=’\0') len++; printf(“\n%d”,len); for(i=0,j=len-1;i
22. AIM: To find the number of vowels and number of consonants in a given string. PROGRAM: //TO FIND THE NUMBER VOWLES AND NUMBER OF CONSONANTS IN A GIVEN STRING #include main() { int v=0,c=0,i=0; char str[25]; printf(“Enter the string...”); scanf(“%s”,str); while(str[i]!=’\0') { switch(str[i]) { case ‘a’: case ‘A’: case ‘E’: case ‘I’: case ‘O’: case ‘U’: case ‘e’: case ‘i’: case ‘o’: case ‘u’: v++; break; default: c++; } i++; }
printf(“\nThe number of vowels is %d”,v); printf(“\nThe number of consonants is %d”,c); getch(); } SAMPLE OUTPUT: Enter the string RAJA The number of vowels is 2 The number of consonants is 2
23.AIM: To write the program to transpose the given matrix. ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Stepep-4 Ste p-5 Ste p-6 Ste p-7 Ste p-8
Start the program Enter th the ro row an and column of of th the matrix Enter the elements of the matrix Pri Print th the el elemen ments of of the the matr atrix in in the the matr atrix fo format Set the loop up to row Set the inner loop up to column Print the matrix elements in the row wise S top
PROGRAM: //TRANSPOSE OF GIVEN MATRIX #include main() { int i,j,a[25][25],row,col; printf(“\nEnter the number of rows and column of matrix”); scanf(“%d%d”,&row,&col); printf(“\nEnter the elements of the matrix”); for(i=0;i
Enter the number of rows and column of matrix 3 3 Enter the elements of the matrix 1 2 3 4 5 6 7 8 9 The given matrix 1 2 3 4 5 6 7 8 9 The transpose of the given matrix 1 4 7 2 5 8 3 6 9
24.AIM: To write a program to find the sine value for the entered value. ALGORITHM Ste p-1 Ste p-2 Ste p-3 Ste p-4 Stepep-5 Step Step-6 -6 Ste p-7
Start the program Enter the values x and n Convert the value x in into ra radians Set a loop up to n Fin Find the val value of the the sine ine by using ing the form ormula Prin Print t the the valu value e of sine sine x afte after r the the exec execut utio ion n of the the loop loop s top
PROGRAM: // SINE SERIES #include #include main() { int no,i; float x,a,sum,b; printf(“Enter the numbers”); scanf(“%f %d”,&x,&no); b=x; x=x*3.141/180; a=x; sum=x; for(i=1;i
25.AIM:
To write a program to print the student name, roll no, average mark and their grades. ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4 Stepep-5 Ste p-6 Step Step-7 -7 Ste p-9
Start the program Initialize th the st structure va variable Enter the number of student Set a loop up to the number of student Ent Enter the studen dent nam name, roll no, average age mar marks Find their grades Prin Print t the the stud studen ent t name name, , roll roll no, no, aver averag age e and and thei their r grad grade e S top
PROGRAM: //STUDENT RECORD USING POINTER AND STRUCT #include main() { struct student { char name[25]; char regno[25]; int avg; char grade; } stud[50],*pt; int i,no; printf(“Enter the number of the students...”); scanf(“%d”,&no); for(i=0;iavg<30) pt->grade=’D’; else if(pt->avg<50) pt->grade=’C’; else if(pt->avg<70) pt->grade=’B’; else pt->grade=’A’; } printf(“\n”); printf(“NAME REGISTER-NO AVERAGE GRADE\n”); for(pt=stud;ptname,pt->regno);
printf(“%10d \t
%c\n”,pt->avg,pt->grade);
} } SAMPLE OUTPUT: Enter the number of the students 3 student[1] information: Enter the name MUNI Enter the roll no of the student 100 Enter the average value of the student 95 student[2] information: Enter the name LAK Enter the roll no of the student 200 Enter the average value of the student 55 student[3] information: Enter the name RAJA Enter the roll no of the student 300 Enter the average value of the student 25 NAME REG ISTER -NO AVER AGE G RADE MUNI 100 95 A LKA 200 55 B RAJA 300 25 D
26.AIM: To write a program to swap two number without using pointer ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Step Step-4 -4 Stepep-5 Ste p-6 Stepep-7 Ste p-8
Start the program Enter the two numbers Call the display function Pass Pass the the add addre ress ss of the the two two numb number ers s to to the the call callin ing g fun funct ctio ion n Get Get th the add addr ress in th the ca calling ing fun func ction in th the po pointer ter Swap th the number using temporary variable Pri Print the swampe mped val values in the mai main fun functio tion S top
PROGRAM: // SWAP THE NUMBER USING THE POINTER #include main() { int x,y; printf(“\nEnter the two numbers”); scanf(“ %d %d”,&x,&y); printf(“\nThe entered number for x and y are,x=%d\ty=%d”,x,y); display(&x,&y); printf(“\nAfter the swapping the value of,x=%d\ty=%d”,x,y); } display(int *a,int *b) { int t; t=*a;
*a=*b; *b=t; } SAMPLE OUTPUT: Enter the two numbers...10 20 The entered number for x and y are, x=10 y=20 After the swapping the value of, x=20 y=10
27.AIM: To write a program to find the string length and concatenation of string. ALGORITHM: Ste p-1 Ste p-2 Stepep-3 Stepep-4 Step Step-5 -5 Ste p-6 Ste p-7
Start the program Enter the string Fin Find th the st string lengt ngth us using th the fu functio tion st strlen( en() Pri Print the string ing leng ength of the the ente ntered strin ring conc concat aten enat atio ion n the the two two stri string ng usin using g the the fun funct ctio ion n str strca cat( t() ) Print the concatenated string S top
PROGRAM: // TO FIND THE STRING LENGTH OF THE STRING #include #include main() { char str1[50],str2[]=” WELCOME”; int len; printf(“Enter the string...”); scanf(“%s”,str1); printf(“\nThe string length of %s is %d”,str1,strlen(str1)); printf(“\nTheconcatenation string length is %d and its string is %s”,strlen(str1),strcat(str1,str2)); } SAMPLE OUTPUT: Enter the string... LAK The string length of lak is 3 The concatenation string length is 16 and its string is LAK WELCOME W
28.AIM: To write a program to print the pascal triangle ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4 Ste p-5 Ste p-6
Start the Enter the Construct Construct Pirnt the After the
prog ram number of lines a loop up to the given number another inner loop numb er execution of the loop
Ste p-7
S top
PROGRAM: //CONSTRUCT PASCAL TRIANGLE #include main() { int noline,i,j,temp; printf(“Enter the number of lines to print”); scanf(“%d”,&noline); for(i=1;i<=noline;i++) { for(j=1;j<=noline-i;j++) printf(“ “); temp=i; for(j=1;j<=i;j++) printf(“%4d”,temp++); temp=temp-2; for(j=1;j
29.AIM: To write a program to find whether the number is prime Or not. ALGORITHM: Step-1 Ste p-2 Ste p-3 Step Step-4 -4 Step Step-5 -5 Step Step-6 -6 Ste p-7
Start the program Enter the number set a loop up to number-1 Chec Check k the the numb number er is divi divide de by any any num numbe ber r othe other r tha than n one one and and the number itself If divi divide de abso absolu lute tely ly than than prin print t the the numb number er is not not a pri prime me If not not div divid ide e oth other er then then one one and and itse itself lf then then prin print t the the numb number er is prime. S top
PROGRAM: //FIND THE GIVEN NUMBER IS PRIME OR NOT #include main() {
int num,i=2; printf(“Enter the number...”); scanf(“%d”,&num); while(i<=num-1) { if(num%i==0) { printf(“The given number is not a prime number”); break; } i++; } if(i==num) printf(“The given number is a prime”); } SAMPLE OUTPUT: Enter the number...5 The given number is a prime
30.AIM: To write a program to find the reverse of the string. ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4 Step Step-5 -5 Stepep-6 Step Step-7 -7 Ste p-8
Start the program Enter the string length Print the string length Enter the string character by character Pass Pass the the leng length th of the the stri string ng to the the recu recurs rsiv ive e func functi tion on If the sting ing len length is is 1 th then print int the char haracter ter If the the stri string ng leng length th is grea greate ter r than than one one then then redu reduce ces s the the string length by one and call the recursive function. S top
PROGRAM: //REVERSE THE STRING USING THE RECURSION #include main() { int len; void rev(); printf(“Enter the string length”); scanf(“%d”,&len); printf(“\n%d”,len); printf(“\n”); rev(len); printf(“\n”); } void rev(len) int len; { char c; if(len==1)
{ c=getchar(); c=getchar(); putchar(c); } else { c=getchar(); c=getchar(); rev(-len); putchar(c); } return; } SAMPLE OUTPUT: Enter the string length 4 4 A M A R R A M A
31.AIM: To write a program to find the size of the data types. ALGORITHM: Ste p-1 Ste p-2 Step Step-3 -3 Ste p-4
Start the program Initialize the data types Prin Print t the the size size of the the dat data a typ types es usin using g the the stat statem emen ent t siz sizeo eof( f() ) S top
PROGRAM: //TO FIND THE SIZE OF DATAS #include main() { int i=10; float f=25.005; char name[]=”welcome”; printf(“\n The size of integer is %d”,sizeof(i)); printf(“\n The size of float is %d”,sizeof(f)); printf(“\n The size of character is %d”,sizeof(name)); }
SAMPLE OUTPUT: The size of integer is...2 The size of float is... 4 The size of character is...8
32.AIM: To find the sum and average of the given array
Start the program Enter the size of the array Enter the elements of the array Set a loop up to the size of the array Find the sum of the array Afte After r the the exec execut utio ion n of of the the loop loop. . Pri Print nt the the sum sum and and ave avera rage ge of the array S top
PROGRAM: //FIND THE SUM AND AVERAGE OF THE GIVEN NUMBERS #include main() { int a[100],i,no,sum=0; float avg=0; printf(“\nEnter the number of elements”); scanf(“%d”,&no); printf(“Enter the numbers”); for(i=0;i
33.AIM: To write a program to convert the string into upper case ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Step Step-4 -4 Stepep-5
Start the program Enter the string Set a loop up to the null character Prin Print t the the char charac acte ter r of of the the stri string ng in the the uppe upper r cas case e usi using ng toupper() function Aft After the execut cution of the the loo loop end end the prog rogram
PROGRAM:
//CONVERT THE LOWER CASE TO UPPER CASE LETTER
#include main() { int i=0; char str[100]; printf(“Enter the string”); scanf(“%s”,str); while(str[i]!=’\0') { printf(“%c”,toupper(str[i])); i++; } } Sample Ouput Enter the string GuRu GURU
34.AIM: To write a program to find the largest of the three numbers. ALGORITHM: Ste p-1 Ste p-2 Ste p-3 stepep-4 Ste p-5 Ste p-6 Ste p-7 Ste p-8
Start the program Enter the three numbers Assign large to first number Che Check th the ne next nu number ber is gr great eater th then th the la large. If greater then assign large to next number Compare the next number with large D o th e ste p-4 Print th the la larger value of the three number S top
PROGRAM: //TO FIND THE LARGEST OF THE THREE NUMBERS #include main() { int a,b,c,big; printf(“Enter the three numbers”); scanf(“%d %d %d”,&a,&b,&c); big=a; if(big
35.AIM: To write a program to find the standard deviation of the given array. ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Ste p-4 Stepep-5 Step Step-6 -6
Start the program Enter the array size Enter the elements of the array Print the Entered elements Cal Call th the fu functio tion to to ca calcu lculate ate sta stan ndard devi eviation ion Call Call the the ave avera rage ge func functi tion on from from the the sta stand ndar ard d dev devia iati tion on func functi tion on
PROGRAM: //COMPUTE STANDARD DEVIATION USING FUNCTION #include #include main() { int i,num; float dev,list[100]; float standev(); printf(“\nEnter the size of the list”); scanf(“%d”,&num); printf(“\nEnter the elements of the list”); for(i=0;i
Sample Output Enter the size of the list 5 Enter the elements of the list 1 2 3 4 5 Entered elements are 1.000000 2.000000 3.000000 4.000000 5.000000 Mean of 5 elements is 3.00 Standard Deviatiion of the list is 1.41421
36.AIM: To write a menu driven program to find 1. Factorial of the given number 2. Prime number or not 3. Even number or Odd number 4. E xit ALGORITHM: Ste p-1 Ste p-2 Ste p-3 Stepep-4 Ste p-5 Step-6 Ste p-7 Step Step-8 -8 Ste p-9 Step Step-1 -10 0 Step Step-1 -11 1 Step Step-1 -12 2 Step Step-1 -13 3 Step Step-1 -14 4 Step Step-1 -15 5 Stepep-16 Ste p-17
Start the program Enter the number Enter yo your ch choice using sw switch statement If you choos oose the cho choice 1. Find the fac factori orial set a loop up to the entered number Calculate factorial fact=fact*I Print the factorial value If you you cho choos ose e the the choi choice ce 2.Fi 2.Find nd whet whethe her r the the numb number er is prim prime e or or not set a loop up to number-1 Chec Check k the the numb number er is divi divide de by any any num numbe ber r oth other er than than one one and the number itself If divi divide de abso absolu lute tely ly then then prin print t the the numb number er is not not a pri prime me If not not div divid ide e oth other er than than one one and and itse itself lf then then prin print t the the numb number er is prime If you you cho choos ose e the the choi choice ce 3. Find Find whet whethe her r the the numb number er is odd odd or or even If the the numb number er is divi divide de by 2 the then n pri print nt the the numb number er is even even If the the num numbe ber r is is not not divi dividi ding ng by 2 the then n pri print nt the the num numbe ber r is is odd If you choos oose th the ch choice 4. 4.Exi Exit th the pro prog gram Continue the program
PROGRAM: // MENU DRIVEN PROGRAM #include main() { int num,o,fact=1,i; while(1) { printf(“\nEnter the number “); scanf(“%d”,&num);
printf(“\nchoose one of the options given below”); printf(“\n1.Factorial of the given number\n2.Prime number or not\n3.Odd or Even \n4.Exit”); scanf(“%d”,&o); switch(o) { case 1: for(i=1;i<=num;i++) fact=fact*i; printf(“The factorial of %d is %d”,num,fact); break; case 3: if(num%2==0) printf(“The given number is Even number”); else printf(“The given number is Odd number”); break; case 2: i=2; while(i<=num-1) { if(num%i==0) { printf(“The given number is not a prime number”); break; } i++; } if(i==num) printf(“The given number is a prime”); break; default: exit(0); } } } SAMPLE OUTPUT: Enter the number .. 5 Choose one of the options given below 1. Factorial of the given number 2. Prime number or not 3. Odd or Even 4. Exit 1 The factorial of 5 is 120 Enter the number..5 Choose one of the options given below 1.Factorial of the given number 2.Prime number or not 3.Odd or Even 4.Exit 2 The given number is a prime Enter the number...5 Choose one of the options given below
1.Factorial of the given number 2.Prime number or not 3.Odd or Even 4.Exit 4
Start the program Dec Declare are x, y and and z variabl ables as ‘in ‘int’ data type. for i=1 to less than 10, x = x+ 1 for y:=z to less than or equal to 10, y =y+z for z = 10 to less than or equal to 100, z=z+10 print the “Magic Square” print “x-z, x+z-y, x+y” print “x+y+z, x, x-y-z” print “x-y, x+y-z, x+z” Stop the program
PROGRAM #include #include main ( ) { int x, y, z; for (x=0; x<=1; x+=2) for (y=0; y<=1; y+=2) for (z=9; z<=10; z+=10) { printf ("\n\n Magic Square %d\n\n", 3+x); printf ("%d\t%d\t%d\n",x-z,x+z-y,x+y); printf ("%d\t%d\t%d\n",x+y+z,x,x-y-z); printf ("%d\t%d\t%d\n",x-y,x+y-z,x+z); getch(); } } Sample output Magic Square -9 9 3 13 1 -11 -1 -7 11
38.AIM: Program to print Triangle of Numbers. ALGORITHM Ste p-1 Stepep-2
Start the program Dec Declare are the the vari ariables les i, i, j, j, k, k, l and n as “i “int” da data ty type
Read N numbers of lines in a triangle Initialize l=1 for i=1, j=n-i to less than or equal to n for k=1 to less than or equal to j print " " for k=1 to less than or equal to ‘1’ print "i" is incremented by 2 Stop the program.
PROGRAM #include main( ) { int i, j, k, l, n; printf("Type N-no of lines in triangle \n") ; scanf("%d",&n); l=1; for (i=1, j=n-i; i<=n; i++, j--) { for (k=1; k<=j; k++) printf(" "); for (k=1; k<=l; k++) printf(" %d", i); printf("\n") ; l+=2; } } SAMPLE OUTPUT Type N-no of lines in triangle 3 1 2 2 2 3 3 3 3 3
39.AIM: Program to find whether a year is Leap year. ALGORITHM Ste p-1 Ste p-2 Ste p-3 Ste p-4 Step-4.1 Ste p-5 Step-5.1 Ste p-6 Step-6.1
PROGRAM #include main()
Start the program Declare year as int datatype Read the year Check if (ye&100) = 0 ye=/100; Check if (ye%4) = 0 Print “It is a leap year” e lse print “It is not a leap year”
{ int ye; printf ("Enter the year \n"); scanf("%d", &ye); if (ye%4==0) printf("It is a Leap Year \n"); else printf("It is Not a Leap Year\n"); } SAMPLE OUTPUT Enter the year 2000 It is a Leap Year
40. AIM: Program to print the following Triangle. 5 4 5 3 4 5 2 3 4 5 1 2 3 4 5 ALGORITHM Ste p-1 Ste p-2 Ste p-3 Ste p-4 Step-4.1 Ste p-5
Start the program Declare i, j and n as “int” data type Read the number of lines for i=n to gr greater th than or or equal to to ‘0’ for j=i to less than n print “y” Stop the program
PROGRAM #include main() { int i, j, n; printf("Enter number of lines\n"); scanf("%d", &n); printf("\n\n\n"); for (i=1;i<=n;i++) { for (j=1;j<=i;j++) printf("%-2d",j); printf("\n\n"); } } SAMPLE OUTPUT Enter number of lines 5 1 1 2 1 2 3 1 2 3 4
1 2 3 4 5
41.AIM: Write a program to read ‘n’ numbers and find the maximum and the minimum. ALGORITHM Ste p-1 Stepep-2 Ste p-3 Ste p-4 Ste p-5 Step-5.1 Ste p-6 Ste p-7 Step-7.1 Step-7.1.1 Step-7.2.1 Ste p-8 Ste p-9
Start the program Dec Declare are arr arra ay ta table[5 e[50], i, i, cn cnt, ma max an and mi min as as “i “int” data type Enter the number of elements in the array Enter the elements into the array for i=1 to less than or equal to ‘cnt’ Read the values from the console. Initialize max = min = table [1] for i=2 to less than or equal to ‘cnt’ check if (max < table [i]) max = table [i] min = table[i] print maximum value and minimum value Stop the program
PROGRAM #include main () { int table[50], i, cnt, max, min; clrscr(); printf ("Enter number of elements in the array\n"); scanf("%d", &cnt); printf("Enter the elements\n"); for (i=1; i<=cnt; i++) scanf("%d", &table[i]); max = min = table[1]; for (i=2; i<=cnt; i++) { if (max
table[i]) min = table[i]; } printf ("Maximum value = %d\n",max); printf ("Minimum value = %d",min); } SAMPLE OUTPUT Enter number of elements in the array 5 Enter the elements 1 4 2 3 5 Maximum value = 5 Minimum value = 1
42.AIM: Program to find the determine of 2 × 2 matrix.
Start the program Dec Declare are a tw two-di -dimensi nsional arra rray a[ a[2][2], 2],d, i and and j as as “int” data type. Enter any 2×2 matrix for i=0 to less than 2 for j=0 to less than 2 Read a[i][j] Ini Initial ialize d = a[ a[0][0 ][0] * a[1][ 1][1] - a[0][ 0][1] * a[1] [1][0]: print “Determinant of matrix” for i=0 to less than 2 print a[i][j] print “The Determinant value is” print “d”. Stop the program
PROGRAM #include main() { int a[2][2], d, i, j; printf ("Enter any 2x2 matrix\n"); for (i=0;i<2;i++) for (j=0;j<2;j++) scanf ("%d", &a[i][j]); d=a[0][0] * a[1][1] - a[0][1] * a[1][0]; printf ("--------------------------\n"); printf(" Matrix \n") ; printf ("--------------------------\n"); for (i=0;i<2;i++) { for (j=0;j<2;j++) printf("%-4d", a[i][j]); printf("\n"); } printf ("--------------------------\n"); printf ("\n The Determinant value is %-4d\n",d); }
SAMPLE OUTPUT Enter any 2x2 matrix 1 2 3 4 ---------------Matrix ---------------1 2 3 4 ---------------The Determinant value is -2
43. AIM: Program to check whether a matrix is an upper triangular. ALGORITHM Ste p-1 Stepep-2 Ste p-3 Ste p-4 Ste p-5 Step-5.1 Step-5.1.1 Ste p-6 Step-6.1 Step-6.1.1 Step-6.1.2 Ste p-7 Step-7.1 Ste p-8
Start the program Dec Declare are a two di dimensi nsional arra rray a[ a[10][10 [10], i, i, j, j, m, m, n and and flag=1 g=1 as as ‘i ‘int’ nt’ dat data a ty type. Enter the order of matrix Enter the matrix rowwise for i=0 to less than or equal to ‘m’ for j=0 to less than or equal to ‘n’ Read a [i][j] for i=0 to less than or equal to ‘m’ for j=0 to less than or equal to ‘n’ check if (a[i][j]!=0) Print “The given matrix is not an upper triangular” Initialize flag=0 Check if (flag) print “The given matrix is an upper triangular” Stop the program.
PROGRAM #include main() { int i,j,a[10][10],m,n,flag=1; printf("Enter the order of the matrix (m,n)....."); scanf("%d%d", &m, &n); printf("\nEnter the matrix row wise....."); for (i=0; i
44.
AIM: Program to demonistrate Macros with arguments.
Start the program Define square(x) as ((x)*(x)) D efin e for -loo p loop (index, max) as for (index=0; index
PROGRAM #include #define square(x) ((x)*(x)) #define loop(index, max) for(index=0; index < max; index++) #define max(x, y) (((x)>(y))? (x):(y)) main() { int a, b, i=0, n, large, vec[10], sq[10]; printf("Program to compute : \n"); printf("1. largest element in the array.\n"); printf("2. square of each array element.\n\n"); printf("Enter Size of the array..... "); scanf("%d", &n); printf("\nEnter %d elements of the array\n", n); loop(i,n) scanf ("%d", &vec[i]); loop(i, n) printf("%5d", vec[i]); large =0; loop(i,n) { sq[i] = square(vec[i]); large = max(large, vec[i]); }
printf("\n\nLargest array element is : %5d", large); printf("\nElement Square \n"); printf ("----------------- \n"); loop(i,n) printf("%5d %8d\n", vec[i], sq[i]); } SAMPLE OUTPUT Program to compute : 1. largest element in the array. 2. square of each array element. Enter Size of the array..... 5 Enter 5 elements of the array 1 2 3 4 5 1 2 3 4 5 Largest array element is : 5 Element Square ------------------------1 1 2 4 3 9 4 16 5 25
45. AIM: Program to delete duplicates in a Vector ALGORITHM Ste p-1 Stepep-2
Start the program Dec Declare are the vari ariables les i, j, k, n, num and flag=0 and declare array a(50) as ‘Float’ data type. Ste p-3 Enter the size of vector Ste p-4 Initialize nu num=n Ste p-5 Enter vector elements Step-5.1 for i=0 to less than ‘n’ Read a[i] Ste p-6 Print vector elements Step-6.1 for i=0 to less than ‘n’ print a[i] Ste p-7 Removing duplicates Step-7.1 for i=0 to less than ‘n-1’ Step-7.1.1 for j = i+1 to less than ‘n’ StepStep-7. 7.1.1 1.1 Check Check if if (a[i (a[i]=a ]=a[j [j]) ]) n=nn=n-1 1 Stepep-7.1.1 1.1 fla flag = 1 Ste p-7.1 .1 j = j -1 Ste p-8 Check if (flag==0) Print “No duplicates found in vector” Ste p-9 E lse Print “Vector has no. of duplicates and print it” Step-10 Print “Vector after deleting duplicates” Step-10.1 for i=0 to less than n print”a[i] Ste p-11 Stop the program.
PROGRAM
#include main() { int i,j,k,n, num, flag=0; float a[50]; printf("Size of vector?"); scanf("%d", &n); num = n; printf("\nEnter Vector elements ?\n"); for (i=0; i
46. AIM: Program to insert an element into the Vector ALGORITHM
Start the program Dec Declare are the the vari ariables les i, i, j, j, k, k, n and po pos as as “i “int” nt” and and a[50], item as ‘float’ data type. Enter the size of vector Enter the elements into the vector Step-4.1 for i=0 to less than n Read and stored in a[i] for i=0 to less than ‘n’ Step-5.1 Print the vector elements a[i] Read the element to be inserted and prin t Enter the position of insertion Increment n by 1 for k=n to gr greater th than or or equal to to pos Step-9.1 a[k] = a[k-1] a[--pos] = item print “V “Vector af after in insertion” for i=0 to less than n Step-12.1 print a[i] Stop the Program
PROGRAM #include main() { int i,k,n, pos; float a[50], item; printf("Enter Size of Array : "); scanf("%d", &n); printf("\nEnter Array Elements : "); for (i=0; i=pos;k--) a[k] = a[k-1]; a[--pos] = item; printf("\nArray of Elements after insertion :\n"); for (i=0;i
Size of Array : 5 Array Elements : 1 2 3 5 6 New Element to be Inserted : 4 Position of Insertion : 4 of Elements after insertion : 1.00 2.00 3.00 4.00
47. AIM:
5.00
6.00
Program to print the upper and lower Triangle of the matrix ALGORITHM Ste p-1 Ste p-2 Ste p-3 Ste p-4 Step-4.1 Step-4.1.1 Ste p-5 Step-5.1 Ste p-6 Step-6.1 Step-6.1.1 Step-6.1.2 Ste p-7 Step-7.1 Step-7.1.1 Step-7.1.2 Ste p-8
Start the program Declare a tw two di dimensional ar array a[ a[10][10], i, j, m and n as “int” data type. Enter th the si size of of ma matrix an and pr print th that si size Enter the elements into the matrix for i=0 to less than n for j = 0%y to less than m Read a[i][j] for i=0 to less than ‘n’ for j=0 to less than ‘m’ print ‘a[i][j]’ for i=0 to less than ‘n’ for j=0 to less than ‘m’ if (ij) print “a[i][j] Lower Triangular Matrix” for i=0 to less than ‘n’ for j=0 to less than ‘n’ check if (i<=j) Print “The upper triangular matrix a[i][j]” Check if (i>j) Print “ ” S top
PROGRAM #include main() { int a[10][10], i, j, m, n; printf("Enter Row and Column of the Matrix : "); scanf("%d %d", &n, &m); printf("\nEnter Elements of matrix : "); for(i=0; i=j) printf("%5d",a[i][j]); if(ij) printf("") ; } printf("\n"); } } SAMPLE OUTPUT
Enter Enter Lower 1 3 Upper 1
Row and Column of the Matrix : 2 2 Elements of matrix : 1 2 3 4 Triangular Matrix : 4 Triangular Matrix : 2 4
48. AIM: Program for Binary search using Recursion ALGORITHM: Step- 1 Step-2 Step- 3 Step- 4 Step- 5 Step- 6 Step- 7 Step- 8 Step- 9 Step- 10 Step- 11
Start the program Decl eclare an an ar array a[ a[50] 50], i, i, n and and lo loc as as ‘i ‘int’ data ata typ type e Declare bi bin( ) function as ‘int’ data type Enter the size of matrix for i=0 to less than ‘n’ Step-5.1 Read and placed in a[i] for i=0 to less than ‘n’ Step-6.1 print ‘a(i) Enter element to be searched Assign loc=bin(a,o,n) Check if (loc==0) Step-9.1 Print “unsuccessful search %d not found” el se Step Step-1 -10. 0.1 1 Prin Print t “Suc “Succe cess ssfu ful l sear search ch fou found nd”. ”. Stop the program
Glo Global decla clarati ation of an array ray b(50 (50) low and hig high Decl Declar are e mid mid as ‘sta ‘stati tic c int int’ ’ of of loc local al decl declar arat atio ion n and and ‘i’ ‘i’ as as ‘int’ data type. m id=( low+h igh) check if (key
PROGRAM #include int key; main() { int a[50], i, n, loc; int bin(int *,int,int); printf("Enter the size of the array : ");
scanf("%d", &n); printf("\nEnter Array elements (Ascending Order) :\n\n"); for (i=0; ib[mid]) { low = mid+1; bin(b,low,high); } else if(key==b[mid]) return(mid+1); } else return(0); } SAMPLE OUTPUT Enter the size of the array : 5 Enter Array elements (Ascending Order) : 1 2 3 4 5 Enter Element to be Searched : 4 Successful search. 4 found at position 4.
49.
AIM: Program to Find substring of a given string
ALGORITHM Ste p-1 Step Step-2 -2 Ste p-3
Start the program Decl Declar are e main mainst str[ r[50 50], ], subs substr tr[5 [50] 0] as ‘cha ‘char’ r’ data data type type and and count, pos, i, j, len and num as ‘int’ data type Enter the main string
for len=0 to mainstr(len)!=’\0’ print “It’s length” Enter th the st starting po position of of substring Enter number of characters in substring check if (pos<=0 or Count<=0 or pos>len) print “Entracted string is Empty” e lse if (pos+count>len) print “Characters to be extracted exceed Length” number = len-pos+1 else num=count j=0 for i = --pos to less than or equal to pos+num-1 substr[j] = mainstr[i] j = j+1 print “S “Substring” Stop the program
PROGRAM #include main() { char mainstr[50], substr[50]; int count, pos, i, j, len, num; printf("Enter the main string \n"); gets (mainstr); for (len = 0; mainstr[len] != '\0'; len++); printf ("It's length is : %d \n", len); printf("\nStarting position of substring ? \n"); scanf("%d", &pos); printf("\nNumber of Characters in substring ? \n"); scanf("%d", &count); if (pos <=0 || count <=0 || pos > len) printf ("\n\nExtracted string is EMPTY \n"); else { if (pos+count-1 > len) { printf("\n\nCharacters to be extracted exceed length \n"); num = len-pos+1; } else num = count; j=0; for (i=--pos;i<=pos+num-1; i++) { substr[j] = mainstr[i]; j++; } substr[j]='\0'; printf("\n\nSubstring is : %s\n", substr); } getch();
} SAMPLE OUTPUT Enter the main string muni rathnam It's length is : 12 Starting position of substring ? 1 Number of Characters in substring ? 4 Substring is : muni
50.
AIM: Program to Replace A portion of string ALGORITHM St ep-1 Step Step-2 -2
St ep-3 St ep-4 Step-4.1 Step tep-5 St ep-6 St ep-7 St ep-8 Step-8.1 St ep-9 Step-9.1 Step-9.1.1 Step-9.2 St ep-10 Step-10.1 Step-10.2 Step-10.3 Step-10.3.1 Step-10.3.2 Step-10.4 Step-10.5 Step-10.6 Step-10.6.1 Step-10.6.2 Step Step-1 -10. 0.7 7
Step-10.8 Step-11 Step-12
PROGRAM #include main() {
Star t th e pro gram Decl Declar are e main mainst str[ r[50 50], ], reps repstr tr[5 [50] 0], , save save[5 [50] 0] as ‘Cha ‘Char’ r’ data type and i, j, k, pos, num, last, last, len1, len2, len as ‘int’ data type. Ente r th e mai n str ing. for le len1=0 to ma mainstr[len1]! = ‘\0’ Print “The length of the string” Enter posi osition from wher here it is to be repla placed Enter number of of characters to to be re replaced Enter replacing string for (l (len2=0 to repstr(len2)! = ‘\0’ print the length; len2 Check if (pos>len1) for (i=0) to less than len2 mainstr[len1+i-1] = repstr[i] len = len1+len2 else last = pos + len2-1 j = 0 for i = pos+num-1 to less than len1 save[j] = mainstr[i] j++ len = j j = 0 for i = --pos to less than last mainstr[i] = repstr[j] j++ for for i=0 i=0 to less less than than len len Step-10.7.1 mainstr[last] = save[i] Step-10.7.2 Last++ for i = last to less than len1 Step-10.8.1 mainstr[i] = “ ” Print REPLACED String Stop the program
char mainstr[50], repstr[50], save[50]; int i, j, k, pos, num, last, len1, len2, len; printf("Enter main string : "); scanf("%[^\n]", mainstr); for(len1=0; mainstr[len1] != '\0'; len1++); printf("\nLength is %d\n", len1); printf("\nPosition from where it is to be replaced ? : "); scanf("%d", &pos); printf("\n\nNumber of characters to be replaced? : "); scanf("%d", &num); printf("\n\nEnter replacement string : "); %s", repstr); for (len2=0; repstr[len2] != '\0'; len2++); printf("\nLength is %d \n", len2); if (pos > len) { for (i=0; i
SAMPLE OUTPUT Enter main string : muni rathnam Length is 12 Position from where it is to be replaced ? : 1 Number of characters to be replaced? : 4
Enter replacement string : mani Length is 4 REPLACED string is : mani rathnam