SlideShare uma empresa Scribd logo
1 de 103
Baixar para ler offline
KONGU ENGINEERING COLLEGE
(Autonomous)
PERUNDURAI, ERODE- 638 052
2020 - 2021
20CSL11
PROBLEM SOLVING AND PROGRAMMING LABORATORY
Name : NEERAJ M
Roll No : 20CSR137
Branch : COMPUTER SCIENCE AND ENGINEERING
Semester : ODD SEMESTER
Year : FIRST YEAR
Section : C
2
INDEX
Serial
No.
Experiment
Date
Name of the Experiment Marks
Signature of
the Staff
1 08-01-2021 Sequential Structures
2 29-01-2021 Selective Structures
3 05-02-2021 Repetitive Structures
4 12-02-2021
Different Types of Operators in
Sequential Structures
5 19-02-2021
Different Formatting Options For
Input And Output
6 26-02-2021 Decision Making Statements
7 05-03-2021 Repetitive Control Statements
8 05-03-2021
One-Dimensional And Two-
Dimensional Numeric Array
9 05-03-2021 Modular Programming Concepts
10 12-05-2021
Character -String Operations With
And Without Built-in Functions
11 12-05-2021 Use Of Pointers
12 12-05-2021 Use Of User Defined Data Types
3
EXE NO: 1
DATE : 08/01/2021
SEQUENTIAL STRUCTURES
1. CUT-OFF:
Algorithm:
Step 1: Start the program
Step 2: Read marks of Phy, Che and Math.
Step 3: Compute sum of Phy and Che and divide it by 2.
Step 4: Add the result with Math.
Step 5: Store the result in the variable Cut_off.
Step 6: Print the value of Cut_off.
Step 7: End of a program.
Flow Chart:
4
2. SWAPPING OF TWO VARIABLES:
A.EXCHANGING TWO VARIABLES WITH TEMPORARY VARIABLE:
Algorithm:
Step 1. Start the program.
Step 2. Read the value of a and b.
Step 3. Print the both values of a and b before swapping.
Step 4. Create a temporary variable named c.
Step 5. Assign the value of a in c and b in a, then c in a.
Step 6. Now, print both the values of and b after swapping.
Step 7. End of the program.
Flow Chart:
5
B.EXCHANGING TWO VARIABLES WITHOUT TEMPORARY VARIABLE:
Algorithm:
Step 1. Start the program.
Step 2. Read the value of a and b.
Step 3. Print the both values of a and b before swapping.
Step 4. Assign a equals a+b, b equals a-b and a equals a-b.
Step 5. Now, print both the values of and b after swapping.
Step 6. End of the program.
Flow Chart:
6
3. FRUIT STALL:
Algorithm:
Step 1. Start the program.
Step 2. Read the values of how many kg of apple and orange.
Step 3. Assign apple equals apple*180 and orange equals orange*80.
Step 4. Now, add apple and orange.
Step 5. Store the result in amount.
Step 6. Print the value of amount.
Step 7. End of the program.
Flowchart:
7
EXE NO: 2
DATE : 29/01/2021
SELECTIVE STRUCTURES
1. QUADRATIC EQUATION:
Algorithm:
Step 1. Start the program.
Step 2. Read the values of A, B and C.
Step 3. Assign discriminant equals (B*B)-(4*A*C).
Step 4. If discriminant >0 is true, go to step 5, otherwise go to step 6.
Step 5. Print the roots are real and distinct and go to step 9.
Step 6. If discriminant <0 is true, go to step 7, otherwise go to step 8.
Step 7. Print the roots are imaginary and go to step 9.
Step 8. Print the roots are real and equal.
Step 9. Stop the program.
8
Flowchart:
9
2. TNEB BILL:
Algorithm:
Step 1. Start the program.
Step 2. Read the value of units from the user.
Step 3. If units <=100 is true, go to step 4, otherwise go to step 5.
Step 4. Assign bill is 0 and go to step 13.
Step 5. If [(units>100) and (units<=200)] is true, go to step 6, otherwise go to step 8.
Step 6. Subtract 100 from the units and multiply by 1.5 and add 20 to it.
Step 7. Store the result in the bill and go to step 13.
Step 8. If [(units>200) and (units<=500)] is true, go to step 9, otherwise go to step 11.
Step 9. Subtract 200 from the units and multiply units by 3 and add 230 with it.
Step 10. Store the result in the bill and go to step 13.
Step 11. Subtract 500 from the units and multiply units by 6.6 and add 1780 with it.
Step 12. Store the result in the bill.
Step 13. Print the value of bill.
Step 14. Stop the program.
10
Flowchart:
11
3. GRADE FOR A SUBJECT:
Algorithm:
Step 1. Start the program.
Step 2. Read the value of PSP mark from the user.
Step 3. If ((PSP>90) and (PSP<=100)) is true, go to step 4, otherwise go to step 5.
Step 4. Print “Your grade is O” and go to step 14.
Step 5. If ((PSP>80) and (PSP<91)) is true, go to step 6, otherwise go to step 7.
Step 6. Print “Your grade is A++” and go to step 14.
Step 7. If ((PSP>70) and (PSP<81)) is true, go to step 8, otherwise go to step 9.
Step 8. Print “Your grade is A” and go to step 14.
Step 9. If ((PSP>60) and (PSP<71)) is true, go to step 10, otherwise go to step 11.
Step 10. Print “Your grade is B++” and go to step 14.
Step 11. If ((PSP>=50) and (PSP<=60)) is true, go to step 12, otherwise go to step 13.
Step 12. Print “Your grade is B” and go to step 14.
Step 13. Print “Your grade is RA – Reappear for Exam”.
Step 14. Stop the program.
12
Flowchart:
13
EXE : 3
DATE : 05-02-2021
REPETITIVE STRUCTURES
1. FIBONACCI SEQUENCE
Algorithm:
Step 1. Start the program.
Step 2. Read n_terms from the user.
Step 3. Assign i is 1, fib_1 is 0 and fib_2 is 1.
Step 4. Print “Fibonacci Series”.
Step 5. While (i<=n_terms) is true, go to step 6, otherwise go to step 10.
Step 6. Add fib_1 and fib_2 and store the result in fib_next.
Step 7. Print the value of fib_1.
Step 8. Assign fib_2 in fib_1 and fib_next in fib_2.
Step 9. Add i by 1 and store it in i and go to step 5.
Step 10. Stop the program.
14
Flowchart:
15
2. FACTORIAL
Algorithm:
Step 1. Start the program.
Step 2. Read the value of num.
Step 3. Assign fact is 1.
Step 4. While (num>0) is true, go to step 1, otherwise go to step 7.
Step 5. Multiply num with fact and store it in fact.
Step 6. Subtract num by 1 and store it in num and go to step 4.
Step 7. Print the value of fact.
Step 8. Stop the program.
16
Flowchart:
17
3. NUMBERS AND SQUARES
Algorithm:
Step 1. Start the program.
Step 2. Read num form user.
Step 3. Assign i is 1 and sum is 0.
Step 4. Print “Number Square” and “=================”.
Step 5. While (i<=num) is true, go to step 6, otherwise go to step 10.
Step 6. Multiply i by i and store it in sqr.
Step 7. Add sum and sqr and store it in sum.
Step 8. Print the value of i and sqr using one tab space between them.
Step 9. Add i by 1 and store it in i and go to step 5.
Step 10. Print the value of sum.
Step 11. Stop the program.
18
Flowchart:
19
4. REVERSING THE DIGIT
Algorithm:
Step 1. Start the program.
Step 2. Read the value of num from the user.
Step 3. Assign rev is 0.
Step 4. Print the value of num.
Step 5. While (num>0) is true, go to step 6, otherwise go to step 10.
Step 6. Multiply rev by 10 and store it in rev.
Step 7. Compute num mod 10 and add the result with rev and store it in rev.
Step 8. Divide num by 10 and round down using floor () function.
Step 9. Store the result in num and go to step 5.
Step 10. Print the value of rev.
Step 11. Stop the program.
20
Flowchart:
21
DATE : 12-02-2021
EX.NO : 04
Different types of operators IN SEQUENTIAL STRUCTURES
AIM:
To create an algorithm, flowchart and C program for the usage of different types of
operator.
ALGORITHM:
Step 1. Start the program.
Step 2. Read the values of a, b, c and d.//Arithmetic operator
Step 3. Add a and b and store it in c.
Step 4. Print the value of c.
Step 5. Subtract a and b and store it in c.
Step 6. Print the value of c.
Step 7. Multiply a and b and store it in c.
Step 8. Print the value of c.
Step 9. Divide a and b and store it in c.
Step 10. Print the value of c.
Step 11. Do a mod b and store it in c.
Step 12. Print the value of c.
Step 13. Do the pre-increment of d and store it in d.//Increment operator
Step 14. Print the value of d.
Step 15. Do the post-increment of d and store it in d.
Step 16. Print the value of d.
Step 17. Do the pre-decrement of d and store it in d.//Decrement operator
Step 18. Print the value of d.
Step 19. Do the post-decrement of d and store it in d.
Step 20. Print the value of d.
Step 21. Do (a>b&&a==b) and store the result in c.//Logical operator
Step 22. Print the value of c.
Step 23. Do (a>b&&b>1) and store the result in c.
Step 24. Print the value of c.
Step 25. Do (a>b||a==b) and store the result in c.
Step 26. Print the value of c.
Step 27. Do (a<b||a==b) and store the result in c.
Step 28. Print the value of c.
Step 29. Do (!a>b) and store the result in c.
22
Step 30. Print the value of c.
Step 31. Check whether a is equal to b and store the result in c.//Relational operator
Step 32. Print the value of c.
Step 33. Check whether a is greater than b and store the result in c.
Step 34. Print the value of c.
Step 35. Check whether a is less than b and store the result in c.
Step 36. Print the value of c.
Step 37. Check whether a is greater than or equal to b and store the result in c.
Step 38. Print the value of c.
Step 39. Check whether a is less than or equal to b and store the result in c.
Step 40. Print the value of c.
Step 41. Check whether a is not equal to b and store the result in c.
Step 42. Print the value of c.
Step 43. Print “Check a is even or odd using ternary operator”.//Ternary Operator.
Step 44. If a mod 2 is equal to 0, then print “It is even”, otherwise print ”It is odd” using
the variable c to store.
Step 45. End of the program.
23
FLOWCHART:
24
25
26
PROGRAM:
#include<stdio.h>
int main(){
int a=10,b=5,c,d=20;
printf("nValue of A = %dnValue of B = %d",a,b);
printf("ntArithmetic Operatorsn");
//Arithmetic operators
c=a+b;
printf("nSum (a+b) = %d",c);
c=a-b;
printf("nDifference(a-b) = %d",c);
c=a*b;
printf("nProduct (a*b) = %d",c);
c=a/b;
printf("nQuotient (a/b) = %d",c);
c=a%b;
printf("nModulous (a%%b) = %d",c);
printf("nnValue of d : %d",d);
d=++d;
// Increment or decrement operator
printf("nPreincrement(++d) =%d",d);
d=d++;
printf("nPost increment(d++) =%d",d);
d=d--;
printf("nPost decrement(d--) =%d",d);
d=--d;
printf("nPre decrement(--d) =%d",d);
printf("nn t Logical operatorsn");
//Logical Operators
c=a>b&&a==b;
printf("nAnd (a>b and a==b) = %d",c);
c=a>b&&b>1;
printf("nAnd (a>b and b>1) = %d",c);
c=a>b||a==b;
printf("nOr (a>b or a==b) = %d",c);
c=a<b||a==b;
printf("nOr (a<b or a==b) = %d",c);
c=!a>b;
printf("nNot (not a>b) = %d",c);
//Relational operators
27
printf("nn t Relational Operatorsn");
c=a==b;
printf("nEqual (a==b) = %d",c);
c=a>b;
printf("nGreater than(a>b) = %d",c);
c=a<b;
printf("nLess than (a<b) = %d",c);
c=a>=b;
printf("nGreater than or equal to(a>=b) = %d",c);
c=a<=b;
printf("nLess than or equal to (a<=b) = %d",c);
c=a!=b;
printf("nNot equal to(a!=b) = %d",c);
//Ternary Operator
printf("nn tTernary Operator n");
printf("nCheck whether the a is even or odd");
c=(a%2==0)?printf("nA is Even number"):printf("nA is Odd number");
return 0;
}
OUTPUT:
Value of A = 10
Value of B = 5
Arithmetic Operators
Sum (a+b) = 15
Difference(a-b) = 5
Product (a*b) = 50
Quotient (a/b) = 2
Modulous (a%b) = 0
Value of d : 20
Preincrement(++d) =21
Post increment(d++) =21
Post decrement(d--) =21
Pre decrement(--d) =20
Logical operators
28
And (a>b and a==b) = 0
And (a>b and b>1) = 1
Or (a>b or a==b) = 1
Or (a<b or a==b) = 0
Not (not a>b) = 0
Relational Operators
Equal (a==b) = 0
Greater than(a>b) = 1
Less than (a<b) = 0
Greater than or equal to(a>=b) = 1
Less than or equal to (a<=b) = 0
Not equal to(a!=b) = 1
Ternary Operator
Check whether the a is even or odd
A is Even number
RESULT:
This above code has executed successfully.
29
EX.NO : 05
DATE : 19-02-2021
DIFFERENT FORMATTING OPTIONS FOR INPUT AND OUTPUT
AIM:
To create an algorithm, flowchart and program for different formatting options for input
and output.
ALGORITHM:
Algorithm A: Different Formatting options
Step 1. Start the program.
Step 2. Use %d (Integer) to print the value 12345.
Step 3. Use %04d (Integer) to print the value 49.
Step 4. Use %i (Integer) to print the value 49.
Step 5. Use %lf (Double) to print the value 25.369852.
Step 6. Use %.2lf (Double) to print the value 25.369852.
Step 7. Use %le (Double exponential) to print the value 25.369852.
Step 8. Use %lg (Double as same) to print the value 2536.3.
Step 9. Use %.2Lf (Long Double) to print the value 25.369852.
Step 10. Use %Le ( Long Double exponential) to print the value 25.369852.
Step 11. Use %Lg (Long Double as same) to print the value 2536.3.
Step 12. Use %f (float) to print the value 25.369852.
Step 13. Use %.2f (float) to print the value 25.369852.
Step 14. Use %e (float exponential) to print the value 25.369852.
Step 15. Use %g (float as same) to print the value 2536.3.
Step 16. Use %x (Hexa decimal) to print the value 256.
Step 17. Use %o (octal) to print the value 256.
Step 18. Use %u (unsigned value) to print the value 150.
Step 19. Use %% to print %.
Step 20. Use %hd (Short signed) to print value 32767.
Step 21. Use %hu (short unsigned) to print value 65535.
Step 22. Use %d (integer signed) to print value 32767.
Step 23. Use %u (integer unsigned) to print value 65535.
Step 24. Use %ld (long signed) to print value 2147483647.
Step 25. Use %lu (long unsigned) to print value 4294967295.
Step 26. Use %lld (long long signed) to print value 9223372036854775807.
Step 27. Use %llu (long long unsigned) to print value 18446744073709551615.
Step 28. End the program.
30
Algorithm B: gets() and puts()
Step 1. Start the program.
Step 2. Initialize str[100] using char.
Step 3. Read the value of str using gets().
Step 4. Print the value of str using puts().
Step 5. End of the program.
Algorithm C: Single Word using scanf() and printf()
Step 1. Start the program.
Step 2. Initialize str[100] using char.
Step 3. Read the value of str using scanf().
Step 4. Print the value of str using printf().
Step 5. End of the program.
Algorithm D: fgetc(stdin) and fputc()
Step 1. Start the program.
Step 2. Initialize c using char.
Step 3. Read the value of c using fgetc().
Step 4. Print the value of c using fputc().
Step 5. End of the program.
Algorithm E: getchar() and putchar()
Step 1. Start the program.
Step 2. Initialize c using char.
Step 3. Read the value of c using getchar().
Step 4. Print the value of c using putchar().
Step 5. End of the program.
C PROGRAM:
Program A: Different Formatting options
#include<stdio.h>
void main()
{
printf("nInteger 1 :%d",12345);
printf("nInteger 2 :%04d",49);
printf("nInteger 3 :%i",49);
printf("nDouble 1 :%lf",25.369852);
printf("nDouble 2 :%.2lf",25.369852);
31
printf("nDouble in exponential :%le",25.365);
printf("nDouble as same precision :%lg",25.3);
printf("nLong Double 1 :%Lf",25.369852);
printf("nLong Double 2 :%.2Lf",25.369852);
printf("nLong Double in exponential :%Le",25.365);
printf("nLong Double as same precision :%Lg",25.3);
printf("nFloat 1 :%f",25.369852);
printf("nFloat 2 :%.2f",25.369852);
printf("nFloat in exponential :%e",25.365);
printf("nFloat as same precision :%g",25.3);
printf("nHexadecimal Number : %x",256);
printf("nOctal :%o",256);
printf("nUnsigned Value :%u",150);
printf("nPrint Percentage sign :%%",10);
printf("nMy name :%s","Raja");
printf("nShort 1:%hd",32767);
printf("nShort(unsigned):%hu",65535);
printf("nInteger(Signed) :%d",32767);
printf("nInteger (Unsigned) :%u",65535);
printf("nLong (signed):%ld",2147483647);
printf("nLong (unsigned):%lu",4294967295);
printf("nLong long (signed):%lld",9223372036854775807);
printf("nLong long (unsigned):%llu",18446744073709551615);
}
Program B: gets() and puts()
//gets() and puts()
#include<stdio.h>
void main()
{
char str[100];
printf("nEnter a String :");
gets(str);
printf("nString :");
puts(str);
}
32
Program C: Single Word using scanf() and printf()
//printf() annd scanf()
#include<stdio.h>
void main()
{
char str[100];
printf("nEnter a Single Word :");
scanf("%s",str);
printf("nSingle Word :%s",str);
}
Program D: fgetc(stdin) and fputc()
//fgetc(stdin) and fputc(stdout)
#include<stdio.h>
#include<ctype.h>
void main()
{
char c;
printf("Enter a Lower-Case Character :");
c=fgetc(stdin);
printf("n You entered :");
fputc(toupper(c),stdout);
}
Program E: getchar() and putchar()
//getchar() and putchar()
#include <stdio.h>
int main( )
{
char c;
printf( "Enter a character :");
c = getchar( );
printf( "nYou entered: ");
putchar( c );
return 0;
}
33
OUTPUT:
Output A: Different Formatting options
Integer 1 :12345
Integer 2 :0049
Integer 3 :49
Double 1 :25.369852
Double 2 :25.37
Double in exponential :2.536500e+001
Double as same precision :25.3
Long Double 1 :25.369852
Long Double 2 :25.37
Long Double in exponential :2.536500e+001
Long Double as same precision :25.3
Float 1 :25.369852
Float 2 :25.37
Float in exponential :2.536500e+001
Float as same precision :25.3
Hexadecimal Number : 100
Octal :400
Unsigned Value :150
Print Percentage sign :%
My name :Raja
Short 1:32767
Short(unsigned):65535
Integer(Signed) :32767
Integer (Unsigned) :65535
Long (signed):2147483647
Long (unsigned):4294967295
Long long (signed):9223372036854775807
Long long (unsigned):18446744073709551615
Output B: gets() and puts()
Enter a String :hi i am a cse student
String :hi i am a cse student
34
Output C(i): Single Word using scanf() and printf()
Enter a Single Word :VIVO
Single Word :VIVO
Output C(ii): Single Word using scanf() and printf()
Enter a Single Word :VIVO VSE
Single Word :VIVO
Output D(i): fgetc(stdin) and fputc()
Enter a Lower-Case Character :n
You entered :N
Output D(ii): fgetc(stdin) and fputc()
Enter a Lower-Case Character :hello
You entered :H
Output E: getchar() and putchar()
Enter a character :s
You entered: s
RESULT:
The above code is executed successfully.
35
EX. NO : 6
DATE : 26-02-2021
DECISION MAKING STATEMENTS
Aim:
To create an algorithm, flowchart and C program for decision making statements like ‘if’,
‘else if’, ‘switch’, conditional and unconditional ‘goto’.
Algorithm:
Algorithm A: IF ELSE
Step 1. Start the program.
Step 2. Read copy from the user.
Step 3. If (copy<=100), then go to step 4, otherwise go to step 5.
Step 4. Set rate is 1 and go to step 6.
Step 5. Set rate is 0.6.
Step 6. Multiply copy and rate.
Step 7. Store the result in amount.
Step 8. Print the value of amount.
Step 9. Stop the program.
Algorithm B: ELSE IF
Step 1. Start the program.
Step 2. Read the values for days and copy from the user and initialize cd_fees is 100.
Step 3. If (days<=90), then go to step 4, otherwise go to step 5.
Step 4. Set reg_fee is 100 and go to step 8.
Step 5. If (days>90 && days<=150), then go to step 6, otherwise go to step 7.
Step 6. Set reg_fee is150 and go to step 8.
Step 7. Set reg_fee is 1150.
Step 8. Multiply copy by 10 and store it in copy_fees.
Step 9. Add copy_fees, reg_fee and cd_fees and store it in total.
Step 10. Print(“FEES RECEIPT”).
Step 11. Print the value of reg_fee, copy_fees, cd_fees and total.
Step 12. Stop the program.
36
Algorithm C: SWITCH
Main program:
Step 1. Start the program.
Step 2. Initialize amount with 500000 and def_pin=1302.
Step 3. Assign end= check_pin() function.
Step 4. If (end==0), then go to step ,otherwise go to step 22.
Step 5. Print “1.CHECK BALANCE 2.WITHDRAWL 3.DEPOSIT 4.CHANGE PIN
5.QUIT).
Step 6. Read the choice.
Step 7. If (choice==1), then go to step 8 , otherwise go to step 9.
Step 8. Print the value of amount and go to step 17.
Step 9. If Choice==2, then go to step 10, otherwise go to step 11.
Step 10. Call withdrawl(&withdraw,&amount) and go to step 17.
Step 11. If Choice==3, then go to step 12, otherwise go to step 13.
Step 12. Call add_amount(&deposit,&amount) and go to step 17.
Step 13. If Choice==4, then go to step 14, otherwise go to step 15.
Step 14. Call change_pin() and go to step 17.
Step 15. If Choice==5, then go to step 22, otherwise go to step 16.
Step 16. Print “INVALID CHOICE”.
Step 17. Print “DO YOU WISH TO HAVE ANOTHER TRANSACTION (Y/N)”.
Step 18. Read the value of transaction from user.
Step 19. If (transaction == 'n'|| transaction == 'N'),then go to step 21 ,otherwise go to step
20.
Step 20. Repeat step 5.
Step 21. Print “THANKS FOR USING OUR SERVICE”.
Step 22. Stop the program.
Let check_pin():
Step 1. Start the program.
Step 2. Initialize i is 1 and end is 1.
Step 3. Read the value of pin.
Step 4. If (pin !=def_pin), then go to step 5, otherwise go to step 6.
Step 5. Print “PLEASE ENTER VALID PASSWORD” and goto step7.
Step 6. Use break to terminate loop.
Step 7. Print “REMAINING ATTEMPTS “ AND VALUE OF 5-i.
Step 8. Increment i by 1.
Step 9. Repeat step 3 untill i<=5.
Step 10. If i==6, then go to step 11, otherwise go to step 13.
37
Step 11. Print “YOUR CARD IS BLOOKED. CONTACT BRAANCH FOR
DETAILS. “.
Step 12. ASSIGN END IS 0.
Step 13. Return the value of end.
Step 14. Stop the program.
Let withdrawl(unsigned long *withdraw,unsigned long *amount):
Step 1. Start the program.
Step 2. Read the value of *withdraw.
Step 3. If (*withdraw % 100 != 0), then go to step 4, otherwise go to step 5.
Step 4. Print “PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100” and
go to step 10.
Step 5. If (*withdraw >(*amount - 500)), then go to step 6, otherwise go to step 7.
Step 6. Print “INSUFFICIENT BALANCE” and go to step 10.
Step 7. Subtract *withdraw from *amount and store it in *amount.
Step 8. Print “PLEASE COLLECT CASH YOUR CURRENT BALANCE IS
Rs.”.
Step 9. Print the value of *amount.
Step 10. Stop the program.
Let add_amount(unsigned long *deposit,unsigned long *amount):
Step 1. Start the program.
Step 2. Read the value of *deposit.
Step 3. Add *amount and *deposit and store it in *amount.
Step 4. Print the value of *amount.
Step 5. Stop the program.
Let change_pin():
Step 1. Start the program.
Step 2. Print “ENTER YOUR OLD PIN”.
Step 3. Read the value as pin.
Step 4. If (pin==def_pin), then go to step 5, otherwise go to step 15.
Step 5. Print “ENTER YOUR NEW PIN”.
Step 6. Read the value as pin_1.
Step 7. Print “ENTER YOUR NEW PIN”.
Step 8. Read the value as pin_2.
Step 9. If (pin_1==pin_2),then goto step 10, otherwise goto step 11.
Step 10. Assign pin_1 in def_pin and go to step 12.
Step 11. Assign pin in def_pin.
Step 12. If (def_pin==pin_1), then go to step 13, otherwise go to step 14.
Step 13. Print “YOUR PIN IS UPDATED” and go to step 17.
38
Step 14. Print “PIN MISMATCH” and go to step 17.
Step 15. Print “PLEASE ENTER YOUR OLD PIN CORRECTLY”.
Step 16. Call change_pin().
Step 17. Stop the program.
Algorithm D: CONDITIONAL GOTO
Step 1. Start the program.
Step 2. Read the percentage of battery.
Step 3. If (battery<=15), then go to step 4, otherwise go to step 5.
Step 4. Goto level(step no:7 ).
Step 5. Print (“Battery Saver is OFF”).
Step 6. Return the value 0 (i.e. go to step no : 8).
Step 7. Level:
Print (“Battery Saver is ON”).
Step 8. Stop the program.
Algorithm E: UNCONDITIONAL GOTO
Step 1. Start the program.
Step 2. Declare val as char.
Step 3. Read the value of val as lowercase letter from the user.
Step 4. Goto check:
Step 5. Print “These lines are not executed”.
Step 6. Print “These lines are skipped”.
Step 7. Check:
Print the value using toupper(val).
Step 8. Stop the program.
39
Flowchart:
Flowchart A: IF ELSE
40
Flowchart B: ELSE IF
41
42
Flowchart C: SWITCH
43
Check_pin() :
44
Switch():
45
Print_service():
46
Withdrawl():
47
Add_amount():
48
Change_pin():
49
C program:
Program A: IF ELSE
#include<stdio.h>
int main()
{
int amount,copy;
float rate;
printf("nENTER NUMBER OF COPIES OF XEROX : ");
scanf("%d",&copy);
if (copy<=100)
rate=1;
else
rate=0.6;
amount=copy*rate;
printf("nnThe amount you have to pay is %d",amount);
return 0;
}
Program B: ELSE IF
#include<stdio.h>//fees calculating program
int main()
{
short days,copy;
int reg_fee,copy_fee,CD_fee=100,total_fees;
printf("ntt TAMIL NADU MARRIAGE REGISTRATIONn");
printf("ntEnter how many number of days after your marriage? ");
scanf("%hd",&days);
printf("ntEnter how many Certified Copies do you want? ");
scanf("%hd",&copy);
if (days<=90)
reg_fee=100;
else if(days>90 && days<=150)
reg_fee=150;
else
reg_fee=1150;
copy_fee=copy*10;
total_fees=reg_fee+copy_fee+CD_fee;
printf("nnttFEES RECEIPTn");
printf("ntRegistration Fees = Rs.%d/-",reg_fee);
50
printf("ntCertified Copy Feest = Rs.%d/-",copy_fee);
printf("ntCD Fees = Rs.%d/-",CD_fee);
printf("nt t ***************");
printf("ntTotal Fees = Rs.%d/-",total_fees);
return 0;
}
Program C: SWITCH
// ATM SERVICES USING SWITCH
#include<stdio.h>
int check_pin();
void withdrawl(unsigned long *,unsigned long *);
void add_amount(unsigned long *,unsigned long *);
void change_pin();
unsigned int pin, def_pin=1302;
short end;
int main()
{
short choice,k;
unsigned long amount=500000,deposit,withdraw;
char transaction;
end=check_pin();
if (end==0)
return 0;
do
{
printf("n********Welcome To ATM Services********");
printf("n1.Check Balance n2.Cash Withdrawln3.Deposit Cashn4.Change
Pinn5.Quit nEnter your Choice :");
scanf("%hd",&choice);
switch(choice)
{
case 1: //Balance
printf("n YOUR BALANCE IN Rs : %lu/- ", amount);
break;
case 2: //Withdrawl
withdrawl(&withdraw,&amount);
break;
case 3: //Deposit
add_amount(&deposit,&amount);
break;
51
case 4: //Change Pin
change_pin();
break;
case 5:
printf("nn THANKS FOR USING OUR ATM SERVICE");
return 0;
default:
printf("nInvalid Choice...");
}
printf("nnn DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): n");
fflush(stdin);
scanf("%c", &transaction);
k=(transaction == 'n'|| transaction == 'N')?0:1;
}while(k);
printf("nn THANKS FOR USING OUR ATM SERVICE");
return 0;
}
//check pin
int check_pin()
{
int i=1;
end=1;
for (;i<=5;++i)
{
printf("nENTER YOUR SECRET PIN NUMBER:");
scanf("%u", &pin);
if (pin !=def_pin)
printf("nPLEASE ENTER VALID PASSWORDn");
else
break;
printf("nREMAINING ATTEMPTS = %d",5-i);
}
if (i==6)
{
printf("nn YOUR CARD IS BLOCKED n CONTACT BRANCH FOR
FURTHER DETAILSn THANK YOU");
end=0;
}
52
return end;
}
//Withdrawl function
void withdrawl(unsigned long *withdraw,unsigned long *amount)
{
printf("n ENTER THE AMOUNT TO WITHDRAW: ");
scanf("%lu", &*withdraw);
if (*withdraw % 100 != 0)
printf("n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100");
else if (*withdraw >(*amount - 500))
printf("n INSUFFICENT BALANCE");
else
{
*amount = *amount - *withdraw;
printf("nn PLEASE COLLECT CASH");
printf("n YOUR CURRENT BALANCE IS Rs.%lu/-", *amount);
}
}
//Deposit function
void add_amount(unsigned long *deposit,unsigned long *amount)
{
printf("n ENTER THE AMOUNT TO DEPOSIT Rs.");
scanf("%lu", &*deposit);
*amount = *amount + *deposit;
printf("YOUR BALANCE IS Rs.%lu/-", *amount);
}
//change pin
void change_pin()
{
int pin_1,pin_2;
printf("nENTER YOUR OLD PIN : ");
scanf("%u",&pin);
if (pin==def_pin)
{
printf("nENTER YOUR NEW PIN : ");
scanf("%d",&pin_1);
53
printf("nRE-ENTER YOUR NEW PIN : ");
scanf("%d",&pin_2);
def_pin=(pin_1==pin_2)?pin_1:pin;
if (def_pin==pin_1)
printf("n YOUR PIN IS UPDATED");
else
printf("nPIN MISMATCH...");
}
else
{
printf("nPLEASE, ENTER YOUR OLD PIN CORRECTLY");
change_pin();
}
}
Program D: CONDITIONAL GOTO
#include<stdio.h>
int main()
{
int battery;
printf("Enter the percentage of your phone : ");
scanf("%d",&battery);
if (battery<=15)
goto level;
else
printf("nBattery Saver is OFF ");
return 0;
level:
printf("nBattery Saver is ON ");
}
Program E: UNCONDITIONAL GOTO
#include<stdio.h>
#include<ctype.h>
int main()
{
char value_1;
printf("Enter a lowercase letter : ");
scanf("%c",&value_1);
goto check;
printf("These lines are not executed");
54
printf("These lines are skipped");
check:
printf("nnLowercase to Uppercase n %c ->%c" ,value_1, toupper(value_1));
return 0;
}
Output:
Output A(i): IF ELSE
ENTER NUMBER OF COPIES OF XEROX : 60
The amount you have to pay is Rs.60
Output A(ii): IF ELSE
ENTER NUMBER OF COPIES OF XEROX : 300
The amount you have to pay is Rs.180
Output B(i): ELSE IF
TAMIL NADU MARRIAGE REGISTRATION
Enter how many number of days after your marriage? 50
Enter how many Certified Copies do you want? 3
FEES RECEIPT
Registration Fees = Rs.100/-
Certified Copy Fees = Rs.30/-
CD Fees = Rs.100/-
***************
Total Fees = Rs.230/-
55
Output B(ii): ELSE IF
TAMIL NADU MARRIAGE REGISTRATION
Enter how many number of days after your marriage? 96
Enter how many Certified Copies do you want? 3
FEES RECEIPT
Registration Fees = Rs.150/-
Certified Copy Fees = Rs.30/-
CD Fees = Rs.100/-
***************
Total Fees = Rs.280/-
Output B(iii): ELSE IF
TAMIL NADU MARRIAGE REGISTRATION
Enter how many number of days after your marriage? 250
Enter how many Certified Copies do you want? 3
FEES RECEIPT
Registration Fees = Rs.1150/-
Certified Copy Fees = Rs.30/-
CD Fees = Rs.100/-
***************
Total Fees = Rs.1280/-
56
Output C(i): SWITCH
ENTER YOUR SECRET PIN NUMBER:1302
********Welcome To ATM Services********
1.Check Balance
2.Cash Withdrawl
3.Deposit Cash
4.Change Pin
5.Quit
Enter your Choice :1
YOUR BALANCE IN Rs : 500000/-
DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n):
y
********Welcome To ATM Services********
1.Check Balance
2.Cash Withdrawl
3.Deposit Cash
4.Change Pin
5.Quit
Enter your Choice :2
ENTER THE AMOUNT TO WITHDRAW: 500
PLEASE COLLECT CASH
YOUR CURRENT BALANCE IS Rs.499500/-
DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n):
y
********Welcome To ATM Services********
1.Check Balance
2.Cash Withdrawl
3.Deposit Cash
4.Change Pin
57
5.Quit
Enter your Choice :3
ENTER THE AMOUNT TO DEPOSIT Rs.1000
YOUR BALANCE IS Rs.500500/-
DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n):
y
********Welcome To ATM Services********
1.Check Balance
2.Cash Withdrawl
3.Deposit Cash
4.Change Pin
5.Quit
Enter your Choice :4
ENTER YOUR OLD PIN : 1302
ENTER YOUR NEW PIN : 1756
RE-ENTER YOUR NEW PIN : 1756
YOUR PIN IS UPDATED
DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n):
n
THANKS FOR USING OUR ATM SERVICE
Output C(ii): SWITCH
ENTER YOUR SECRET PIN NUMBER:1756
PLEASE ENTER VALID PASSWORD
REMAINING ATTEMPTS = 4
ENTER YOUR SECRET PIN NUMBER:5564
58
PLEASE ENTER VALID PASSWORD
REMAINING ATTEMPTS = 3
ENTER YOUR SECRET PIN NUMBER:4589
PLEASE ENTER VALID PASSWORD
REMAINING ATTEMPTS = 2
ENTER YOUR SECRET PIN NUMBER:7856
PLEASE ENTER VALID PASSWORD
REMAINING ATTEMPTS = 1
ENTER YOUR SECRET PIN NUMBER:7458
PLEASE ENTER VALID PASSWORD
REMAINING ATTEMPTS = 0
YOUR CARD IS BLOCKED
CONTACT BRANCH FOR FURTHER DETAILS
THANK YOU
Output C(iii): SWITCH
ENTER YOUR SECRET PIN NUMBER:1302
********Welcome To ATM Services********
1.Check Balance
2.Cash Withdrawl
3.Deposit Cash
4.Change Pin
5.Quit
Enter your Choice :4
ENTER YOUR OLD PIN : 1569
PLEASE, ENTER YOUR OLD PIN CORRECTLY
ENTER YOUR OLD PIN : 1302
ENTER YOUR NEW PIN : 1458
59
RE-ENTER YOUR NEW PIN : 1459
PIN MISMATCH...
DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n):
y
********Welcome To ATM Services********
1.Check Balance
2.Cash Withdrawl
3.Deposit Cash
4.Change Pin
5.Quit
Enter your Choice :2
ENTER THE AMOUNT TO WITHDRAW: 5300
PLEASE COLLECT CASH
YOUR CURRENT BALANCE IS Rs.494700/-
DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n):
n
THANKS FOR USING OUR ATM SERVICE
Output D (i): CONDITIONAL GOTO
Enter the percentage of your phone : 5
Battery Saver is ON
Output D (ii): CONDITIONAL GOTO
Enter the percentage of your phone : 55
Battery Saver is OFF
60
Output E (i): UNCONDITIONAL GOTO
Enter a lowercase letter : g
Lowercase to Uppercase
g ->G
Output E (ii): UNCONDITIONAL GOTO
Enter a lowercase letter : G
Lowercase to Uppercase
G ->G
result:
The above code has executed successfully and algorithm and flow chart were drawn.
61
EXP NO : 07
DATE : 05-03-2021
REPETITIVE CONTROL STATEMENTS
AIM:
To create an algorithm, flowchart and c program for repetitive control statements like
‘for’, ‘while’ and ‘do while’.
ALGORITHM:
ALGORITHM A (FOR LOOP):
Step 1. Start the Program.
Step 2. Declare the variables n, count, c and initialize i is 3.
Step 3. Read the value of n from the user.
Step 4. If (n>=1) is true, then print “First n Prime numbers are : 2”.
Step 5. Set the value of count is 2.
Step 6. If (count<=n) is true, then go to step 7, otherwise go to step 15.
Step 7. Set the value of c is 2.
Step 8. If (c<=i-1) is true, then go to step 9, otherwise go to step 12.
Step 9. If (i%c==0) is true, then use the break statement to exit.
Step 10. Increment the value of c by 1.
Step 11. Repeat step 8.
Step 12. If (c==i) is true, then print the value of i and and increment the value of count.
Step 13. Increment the value of i by 1.
Step 14. Repeat step 6.
Step 15. End the program.
ALGORITHM B (WHILE LOOP):
Step 1. Start the Program.
Step 2. Declare variables column, max_row and initialize row is 1.
Step 3. Read the value of max_row.
Step 4. Print “ASCENDING ORDER”.
Step 5. If (row<=max_row), then go to step 6, otherwise go to step 14.
Step 6. Set the value of column is 1.
Step 7. If (column<=row) is true then go to step 8, otherwise go to step 11.
Step 8. Print the character of ‘A’+(coloumn-1).
Step 9. Increment the value of column by 1.
Step 10. Repeat the step 7.
Step 11. Increment the value of row by 1.
Step 12. Print the new line.
62
Step 13. Repeat step 5.
Step 14. Print “DESCENDING ORDER”.
Step 15. If (row<=max_row), then go to step 16, otherwise go to step 24.
Step 16. Set the value of column is 1.
Step 17. If (column<=row) is true then go to step 18, otherwise go to step 21.
Step 18. Print the character of ‘A’+(row-column).
Step 19. Increment the value of column by 1.
Step 20. Repeat the step 17.
Step 21. Increment the value of row by 1.
Step 22. Print the new line.
Step 23. Repeat step 15.
Step 24. End the Program.
ALGORITHM C (DO WHILE LOOP):
Step 1. Start the program.
Step 2. Declare variables year as integer, k as integer, choice as character.
Step 3. Read the value of year from user.
Step 4. If (year%4==0 && year%100!=0 ||year%400==0) is true, then print “It is a leap
year”, otherwise print “It is not a leap year”.
Step 5. Print “Do you wish to check another year?(y/n)”.
Step 6. Read the value of choice from user.
Step 7. If (choice == 'n'|| choice == 'N') is true, then assign k is 0, otherwise k is 1.
Step 8. Repeat the step 3 if (k==1).
Step 9. End the program.
63
FLOWCHART:
FLOWCHART A (FOR LOOP):
64
FLOWCHART B (WHILE LOOP):
65
66
FLOWCHART C (DO WHILE LOOP):
67
PROGRAM:
PROGRAM A (FOR LOOP):
//Program to find Prime numbers
#include<stdio.h>
int main()
{
int n, i = 3, count, c;
printf("Enter the number of prime numbers to printn");
scanf("%d", &n);
if (n >= 1)
printf("First %d prime numbers are:n2n",n);
for (count = 2; count <= n;)
{
for (c = 2; c<= i-1; c++)
{
if (i%c == 0)
break;
}
if (c == i)
{
printf("%dn", i);
count++;
}
i++;
}
return 0;
}
PROGRAM B (WHILE LOOP):
//Program to print the pattern of Alphabets by entering number of rows
#include<stdio.h>
int main()
{
int row=1,coloumn,max_row;
printf("nEnter how many number of rows?");
scanf("%d",&max_row);
printf("nAscending Ordern");
while (row<=max_row)
{
68
coloumn=1;
while (coloumn<=row)
{
printf("%c",'A'+(coloumn-1));
coloumn++;
}
++row;
printf("n");
}
printf("nDescending Ordern");
row=1;
while (row<=max_row)
{
coloumn=1;
while (coloumn<=row)
{
printf("%c",'A'+(row-coloumn));
coloumn++;
}
++row;
printf("n");
}
return 0;
}
PROGRAM C (DO WHILE LOOP):
//Program to find whether it is a leap year or not
#include<stdio.h>
int main()
{
int year,k;
char choice;
do
{
printf("nEnter the year : ");
scanf("%d",&year);
if (year%4==0 && year%100!=0 ||year%400==0)
printf("n%d is a leap year",year);
else
printf("n%d is a not leap year",year);
printf("nnn DO U WISH TO CHECK ANOTHER YEAR?(y/n): n");
69
fflush(stdin);
scanf("%c", &choice);
k=(choice == 'n'|| choice == 'N')?0:1;
}while(k);
return 0;
}
OUTPUT:
OUTPUT A (FOR LOOP):
Enter the number of prime numbers to print
10
First 10 prime numbers are:
2
3
5
7
11
13
17
19
23
29
OUTPUT B (WHILE LOOP):
Enter how many number of rows?6
Ascending Order
A
AB
ABC
ABCD
ABCDE
ABCDEF
Descending Order
A
BA
CBA
DCBA
EDCBA
FEDCBA
70
OUTPUT C (DO WHILE LOOP):
Enter the year : 2020
2020 is a leap year
DO U WISH TO CHECK ANOTHER YEAR?(y/n):
y
Enter the year : 1600
1600 is a leap year
DO U WISH TO CHECK ANOTHER YEAR?(y/n):
y
Enter the year : 1800
1800 is a not leap year
DO U WISH TO CHECK ANOTHER YEAR?(y/n):
n
RESULT:
Above code has executed successfully.
71
EXP NO : 08
DATE : 05-03-2021
ONE-DIMENSIONAL AND TWO-DIMENSIONAL ARRAY
AIM:
To create an algorithm and program for one-dimensional and two-dimensional array.
ALGORITHM:
Algorithm A (One-Dimensional Array):
Step 1. Start the program.
Step 2. Declare num[10] and initialize i is 0,even is 0 and odd is 0.
Step 3. If (i<10) is true then go to step 4, otherwise go to step 8.
Step 4. Read the value of num[i].
Step 5. If (num[i]%2==0) is true, the increment the value of even by 1, otherwise
increment the value of odd by 1.
Step 6. Increment the value of i by 1.
Step 7. Repeat the step 3.
Step 8. Print the value of odd and even.
Step 9. End the program.
Algorithm B (Two-Dimensional Array):
Step 1. Start the program.
Step 2. Declaring i,j,k,result[10][10], a[10][10], b[10][10] as global variable.
Step 3. Declare row1, row2, column1 and column2.
Step 4. Read the values of row1 and column1.
Step 5. Call the function with passing arguments
get_Matrix_Elements(a,row1,coloumn1).
Step 6. Read the values of row2 and column2.
Step 7. Call the function with passing arguments
get_Matrix_Elements(b,row2,coloumn2).
Step 8. If (row1==row2 && coloumn1==coloumn2) is true, then go to step 9, otherwise
go to step 13.
Step 9. Print “Sum of two matrices”.
Step 10. Calls the functions with passing arguments find (row1, column1, 11).
Step 11. Print “Difference of two matrices”.
Step 12. Call the function with passing arguments find (row1, column1, 12) and go to step
14.
Step 13. Print “Addition and subtraction is not possible for this order”.
Step 14. If (coloumn1==row2) is true, then go to step 15, otherwise go to step 17.
Step 15. Print “Multiplication of two matrices:”.
72
Step 16. Call the function with passing arguments
a. find(row1,coloumn2,coloumn1);
b. find(row1,coloumn2,13); and go to step 18.
Step 17. Print “Multiplication is not possible”.
Step 18. Print “Matrix A”.
Step 19. Call the function with passing arguments find(row1,coloumn1,14);.
Step 20. Print “Transpose of A”.
Step 21. Call the function with passing arguments
a. find(row1,coloumn1,15);
b. find(coloumn1,row1,13);
Step 22. Print “matrix B”.
Step 23. Call the function with passing arguments find(row2,coloumn2,16);.
Step 24. Print “Transpose of B”.
Step 25. Call the function with passing arguments
a. find(row2,coloumn2,17);
b. find(coloumn2,row2,13);
Step 26. End the program.
void get_Matrix_Elements(int matrix[][10], int row, int coloumn) :
Step 1. Start the program.
Step 2. Print “Enter elements of matrix”.
Step 3. Set the value of i is 0.
Step 4. If (i<row) is true, then go to step 5, otherwise go to step 12.
Step 5. Set the value of j is 0.
Step 6. If (j<column) is true, then go to step 7, otherwise go to step 10.
Step 7. Read the value of matrix[i][j].
Step 8. Increment the value of j by 1.
Step 9. Repeat the step 6.
Step 10. Increment the value of i by 1.
Step 11. Repeat the step 4.
Step 12. End the program.
void find(int row,int column,int n):
Step 1. Start the program.
Step 2. Set the value of i is 0.
Step 3. If (i<row) is true, then go to step 4, otherwise go to step 31.
Step 4. Set the value of j is 0.
Step 5. If (j<column) is true, then go to step 6, otherwise go to step 28.
Step 6. If (n==11) is true, then go to step 7, otherwise go to step 8.
Step 7. Print (a[i][j] + b[i][j]) and go to step 26.
73
Step 8. If (n==12) is true, then go to step 9, otherwise go to step 10.
Step 9. Print (a[i][j] - b[i][j]) and go to step 26.
Step 10. If (n==13) is true, then go to step 11,otherwise go to step 12.
Step 11. Print (result[i][j]) and go to step 26.
Step 12. If (n==14) is true, then go to step 13,otherwise go to step 14.
Step 13. Print (a[i][j]) and go to step 26.
Step 14. If (n==15) is true, then go to step 15,otherwise go to step 16.
Step 15. Assign Result[j][i] is equal to a[i][j] and go to step 26.
Step 16. If (n==16) is true, then go to step 17,otherwise go to step 18.
Step 17. Print (b[i][j]) and go to step 26.
Step 18. If (n==17) is true, then go to step 19,otherwise go to step 20.
Step 19. Assign Result[j][i] is equal to b[i][j] and go to step 26.
Step 20. Set the value of k is 0.
Step 21. If (k<n) is true, then go to step 22, otherwise go to step 26.
Step 22. Multiply a[i][k] and b[k][j], and add result[i][j].
Step 23. Store the result in result[i][j].
Step 24. Increment the value of k by 1.
Step 25. Repeat the step 21.
Step 26. Increment the value of j by 1.
Step 27. Repeat the step 5.
Step 28. Print new line.
Step 29. Increment the value of i by 1.
Step 30. Repeat the step 3.
Step 31. End the program.
PROGRAM:
Program A (One-Dimensional Array):
//Program to find how many even and odd numbers of 10 numbers
#include<stdio.h>
int main()
{
int num[10],even=0,odd=0,i;
for(i=0;i<10;i++)
{
printf("nEnter number %d : ",i+1);
scanf("%d",&num[i]);
if (num[i]%2==0)
++even;
else
++odd;
74
}
printf("n There are %d Even Numbers",even);
printf("n There are %d Odd Numbers",odd);
return 0;
}
Program B (Two-Dimensional Array):
#include <stdio.h>
void get_Matrix_Elements(int matrix[][10], int row, int column);
void find(int row,int coloumn,int n);
int i,j,k,result[10][10], a[10][10], b[10][10];
int main()
{
int row1,row2,coloumn2,coloumn1;
printf("Enter rows and column for the first matrix: ");
scanf("%d %d", &row1, &coloumn1);
get_Matrix_Elements(a,row1,coloumn1);//Elements of 1st matrix
printf("Enter rows and column for the second matrix: ");
scanf("%d %d", &row2, &coloumn2);
get_Matrix_Elements(b,row2,coloumn2);//Elements of 2nd matrix
if (row1==row2 && coloumn1==coloumn2)
{
printf("nSum of two matrices: n");
find(row1,coloumn1,11);
printf("nDifference of two matrices: n");
find(row1,coloumn1,12);
}
else
printf("nAddition and Subtraction is not possible for this ordern");
if (coloumn1==row2)
{
printf("nMultiplication of two matrices: n");
find(row1,coloumn2,coloumn1);
find(row1,coloumn2,13);
}
else
printf("nMultiplication is not possiblen");
printf("nMatrix A:n");
find(row1,coloumn1,14);
printf("nTranspose of A:n");
find(row1,coloumn1,15);
75
find(coloumn1,row1,13);
printf("nMatrix B:n");
find(row2,coloumn2,16);
printf("nTranspose of B:n");
find(row2,coloumn2,17);
find(coloumn2,row2,13);
return 0;
}
void get_Matrix_Elements(int matrix[][10], int row, int coloumn)
{
printf("nEnter elements of matrix:n");
for (i = 0; i<row; ++i)
{
for (j = 0; j<coloumn; ++j)
{
printf("Enter element a%d%d: ", i+1, j+1);
scanf("%d", &matrix[i][j]);
}
}
}
void find(int row,int coloumn,int n)
{
for (i = 0; i<row; ++i)
{
for (j = 0; j<coloumn; ++j)
{
switch(n)
{
case 11:
printf("%d ", a[i][j] + b[i][j]);//ADD
break;
case 12:
printf("%d ", a[i][j] - b[i][j]);//SUB
break;
case 13:
printf("%d ", result[i][j]);//Display
break;
case 14:
printf("%d ", a[i][j]);//Matrix A
break;
76
case 15:
result[j][i]=a[i][j];//Transpose A
break;
case 16:
printf("%d ", b[i][j]);//Matrix B
break;
case 17:
result[j][i]=b[i][j];//Transpose B
break;
default:
for(k=0;k<n;k++)
result[i][j]+=a[i][k]*b[k][j];//Multiplication
}
}
printf("n");
}
}
OUTPUT:
Output A (One-Dimensional Array):
Enter number 1 : 1
Enter number 2 : 2
Enter number 3 : 3
Enter number 4 : 4
Enter number 5 : 5
Enter number 6 : 6
Enter number 7 : 7
Enter number 8 : 8
Enter number 9 : 9
Enter number 10 : 10
77
There are 5 Even Numbers
There are 5 Odd Numbers
Output B (Two-Dimensional Array) (i):
Enter rows and column for the first matrix: 2
2
Enter elements of matrix:
Enter element a11: 3
Enter element a12: 3
Enter element a21: 3
Enter element a22: 3
Enter rows and column for the second matrix: 2
2
Enter elements of matrix:
Enter element a11: 3
Enter element a12: 3
Enter element a21: 3
Enter element a22: 3
Sum of two matrices:
6 6
6 6
Difference of two matrices:
0 0
0 0
Multiplication of two matrices:
18 18
18 18
Matrix A:
3 3
3 3
Transpose of A:
78
3 3
3 3
Matrix B:
3 3
3 3
Transpose of B:
3 3
3 3
Output B (Two-Dimensional Array) (ii):
Enter rows and column for the first matrix: 2
3
Enter elements of matrix:
Enter element a11: 2
Enter element a12: 3
Enter element a13: 4
Enter element a21: 5
Enter element a22: 6
Enter element a23: 6
Enter rows and column for the second matrix: 3
2
Enter elements of matrix:
Enter element a11: 2
Enter element a12: 2
Enter element a21: 2
Enter element a22: 5
Enter element a31: 6
Enter element a32: 8
Addition and Subtraction is not possible for this order
Multiplication of two matrices:
79
34 51
58 88
Matrix A:
2 3 4
5 6 6
Transpose of A:
2 5
3 6
4 6
Matrix B:
2 2
2 5
6 8
Transpose of B:
2 2 6
2 5 8
Output B (Two-Dimensional Array) (iii):
Enter rows and column for the first matrix: 2
3
Enter elements of matrix:
Enter element a11: 1
Enter element a12: 2
Enter element a13: 3
Enter element a21: 4
Enter element a22: 5
Enter element a23: 6
Enter rows and column for the second matrix: 2
2
80
Enter elements of matrix:
Enter element a11: 1
Enter element a12: 2
Enter element a21: 3
Enter element a22: 4
Addition and Subtraction is not possible for this order
Multiplication is not possible
Matrix A:
1 2 3
4 5 6
Transpose of A:
1 4
2 5
3 6
Matrix B:
1 2
3 4
Transpose of B:
1 3
2 4
RESULT:
Above code has executed successfully.
81
EXP-NO : 09
DATE : 05-03-2021
MODULAR PROGRAMMING CONCEPTS
AIM:
To create an algorithm and program for built-in functions and user defined functions.
ALGORITHM:
ALGORITHM A (BUILT-IN FUNCTIONS):
Step 1. Start the program.
Step 2. Declare ceo[25] as char and len as int and initialize mn is 16 as double.
Step 3. Initialize str[]=”cprogram”, cho[]=”open” and c=’s’.
Step 4. Copy the str to ceo using strcpy() function.
Step 5. Print the value of str and ceo.
Step 6. Calculate string length using strlen() for ceo and store it in len.
Step 7. Print the value of len.
Step 8. Concatenate the two strings using strcat() to join cho and str.
Step 9. Print the string cho.
Step 10. Compare two strings using strcmp() of str and ceo and store it in len.
Step 11. Print the value of len.
Step 12. Print uppercase letter of variable c using toupper() function.
Step 13. Print the lowercase letter of variable c using tolower() function.
Step 14. Using sqrt() function, print the square root of mn variable.
Step 15. End the program.
ALGORITHM B (USER DEFINED FUNCTIONS):
Step 1. Start the program.
Step 2. Declare name[25][25], age[25], salary[25]as global variable.
Step 3. Declare the variable named number.
Step 4. Read the value of number.
Step 5. Call get_detail() function with passing number.
Step 6. Call display() function with passing number.
Step 7. End the program.
int get_details(int number);
Step 1. Start the program.
Step 2. Initialize i is 0.
Step 3. If (i<number) is true, then go to step 4, otherwise go to step 7.
Step 4. Read the value of name[i], age[i] and salary[i].
Step 5. Increment the value of i by 1.
Step 6. Repeat the step 3.
82
Step 7. End the program.
void display (int number)
Step 1. Start the program.
Step 2. Initialize i is 0.
Step 3. Print “Name Age Salary Annual_income” with horizontal space.
Step 4. If (i<number) is true, then go to step 5, otherwise go to step 7.
Step 5. Print the value of name[i], age[i], salary[i] and (salary[i])*12.
Step 6. Repeat the step 4.
Step 7. End the program.
PROGRAM:
PROGRAM A (BUILT-IN FUNCTIONS):
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
char str[]="cprogram",ceo[25],cho[]="open",c='s';
int len;
double mn=16;
strcpy(ceo,str);
printf("Original string : %s",str);
printf("nCopied String :%s",ceo);
len=strlen(ceo);
printf("nLength of copied string : %d",len);
strcat(cho,str);
printf("nConcatenated String : %s",cho);
len=strcmp(str,ceo);
printf("nCompare string : %d",len);
printf("nvariable c to uppercase :%c",toupper(c));
printf("nvariable c to lowercase :%c",tolower(c));
printf("nSquareroot of mn : %.2lf",sqrt(mn));
return 0;
}
PROGRAM B (USER DEFINED FUNCTIONS):
#include<stdio.h>
int get_details(int number);
void display(int number);
char name[25][25];
83
short age[25];
double salary[25];
int main()
{
short number;
printf("Enter how many persons : ");
scanf("%hd",&number);
get_details(number);
display(number);
}
int get_details(int number)
{
int i=0;
for(;i<number;i++)
{
printf("nEnter name of %d person : ",i+1);
scanf("%s",name[i]);
printf("nEnter the age : ");
scanf("%hd",&age[i]);
printf("nEnter the salary : ");
scanf("%lf",&salary[i]);
}
}
void display (int number)
{
int i=0;
printf("nNametAgetSalaryttAnnual_Income");
for(;i<number;i++)
{
printf("n%st %hdt %lft %lf",name[i],age[i],salary[i],salary[i]*12);
}
}
OUTPUT:
OUTPUT A (BUILT-IN FUNCTIONS):
Original string : cprogram
Copied String :cprogram
Length of copied string : 8
Concatenated String : opencprogram
Compare string : 0
84
variable c to uppercase :S
variable c to lowercase :s
Squareroot of mn : 4.00
OUTPUT B (USER DEFINED FUNCTIONS):
Enter how many persons : 4
Enter name of 1 person : Ram
Enter the age : 23
Enter the salary : 20000
Enter name of 2 person : Ravi
Enter the age : 32
Enter the salary :
29565
Enter name of 3 person : Raju
Enter the age : 31
Enter the salary : 65000
Enter name of 4 person : Ragu
Enter the age : 26
Enter the salary : 85500
Name Age Salary Annual_Income
Ram 23 20000.000000 240000.000000
Ravi 32 29565.000000 354780.000000
Raju 31 65000.000000 780000.000000
Ragu 26 85500.000000 1026000.000000
RESULT:
Above code has executed successfully.
85
EX.NO : 10
DATE : 12-03-2021
CHARACTER - STRING OPERATIONS WITH AND WITHOUT BUILT-IN
FUNCTIONS
AIM:
To create a algorithm, program and output for character and string operations with and
without built-in library functions.
ALGORITHM:
Step 1. Start the program.
Step 2. Declare the char variable chr with value ‘s’ and also declare pointer variable *p
with value as “CHATUS”.
Step 3. Read the value of str1 and str2.
Step 4. Print to output screen “Using Built in Functions”.
Step 5. Copy the str1 and str2 to ceo and cto respectively using strlen() function.
Step 6. Print the value of str1 and ceo as original string and copied string.
Step 7. Using strlen() function, find length of string of ceo and store it in len.
Step 8. Print the value of len.
Step 9. Join the strings str1 and str2 using strcat() function.
Step 10. Print the value of str1.
Step 11. Compare two strings str1 and str2, using strcmp() function and store result in len.
Step 12. Print the value of len.
Step 13. Convert a lowercase to uppercase for a character using toupper() function for chr.
Step 14. Print the value of chr.
Step 15. Convert a uppercase to lowercase for a character using tolower() function for chr.
Step 16. Print the value of chr.
Step 17. Print to output screen “Without Using Built in Functions”.
Step 18. Call the function str_cpy(user1,ceo) and pass the values of user1 and ceo. Go to
step 34.
Step 19. Call the function str_cpy(user2,cto) and pass the values of user2 and cto. Go to
step 34.
Step 20. Print the value of ceo and user1.
Step 21. Call the function str_len(user1) and pass the value of user1. Go to step 39.
Step 22. Store the returned value in len.
Step 23. Print the valu of len.
Step 24. Call the function str_cat(user1,p) and pass the values of user1 and p. Go to step
42.
86
Step 25. Print the value of user1.
Step 26. Call the function str_cmp(user2,cto) and pass the values of user2 and cto. Go to
step 45.
Step 27. Store the returned value in len.
Step 28. Print the value of len.
Step 29. Call the function to_upper(chr) and pass the values of chr. Go to step 49.
Step 30. Print the value of chr.
Step 31. Call the function to_lower(chr) and pass the values of chr. Go to step 52.
Step 32. Print the value of chr.
Step 33. End the program.
Step 34. Declare i is 0.
Step 35. If (ceo[i]!='0') is true, then go to step 36, otherwise go to step 38.
Step 36. Assign user[i] equals to ceo[i].
Step 37. Increment the value of i and repeat the step 35.
Step 38. Assign user[i] equals to ‘0’ and go to next step of calling function (here end of
str_cpy() function).
Step 39. Declare a is 0.
Step 40. If (user[a]!='0') is true, then increment the value of a, otherwise return a.
Step 41. Repeat step 40, until condition fails and go to next step of calling function (here
end of str_len() function).
Step 42. Declare i and j is 0 and set i is equals to str_len(user1) (i.e., go to step 39).
Step 43. If (ceo[j]!='0') is true, then assign user[i] is equal to ceo[j] and increment value
of i and j, otherwise set user[i] is ‘0’.
Step 44. Repeat step 43, until the condition fails and go to next step of calling function
(here end of str_cat() function).
Step 45. Declare i is 0.
Step 46. If (str1[i]==str2[i] && str1[i]=='0') is true, then increment the value of i.
Step 47. Repeat step 46 untill condition fails.
Step 48. If (str1[i]==str2[i]) is true, then return 0, otherwise return 1 and go to next step of
calling function (here end of str_cmp() function).
Step 49. If (c>=97 && c<=122) is true, then do the following steps, otherwise go to step
51.
Step 50. Subtract 32 from c and store it in c.
Step 51. Go to next step of calling function (here end of to_upper() function).
Step 52. If (c>=65 && c<=90) is true, then do the following steps, otherwise go to step 51.
Step 53. Add 32 with c and store it in c.
Step 54. Go to next step of calling function (here end of to_lower() function).
87
PROGRAM:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void str_cpy(char user1[],char ceo[]);
void str_cat(char user1[],char ceo[]);
int str_len(char user[]);
int str_cmp(char str1[], char str2[]);
int to_upper(char c);
int to_lower(char c);
int main()
{
char str1[25],str2[25],ceo[25],cto[25],user1[25],user2[25],chr='s';
char *p="CHATUS";
int len,i;
printf("nEnter string 1 : ");
scanf("%s",str1);
printf("nEnter String 2 : ");
scanf("%s",str2);
printf("nntUsing Built In Functionsn "); //using buil-in functions
strcpy(ceo,str1);
strcpy(cto,str2);
printf("nnOriginal string 1: %s",str1);
printf("nCopied String of 1 :%s",ceo);
len=strlen(ceo);
printf("nLength of copied string : %d",len);
strcat(str1,str2);
printf("nConcatenated String : %s",str1);
len=strcmp(str2,cto);
printf("nCompare string : %d",len);
printf("nvariable chr to uppercase :%c",toupper(chr));
printf("nvariable chr to lowercase :%c",tolower(chr));
printf("nntWithout Built In Functions n");//not using buil-in functions
str_cpy(user1,ceo);
str_cpy(user2,cto);
printf("nnOriginal string : %s",ceo);
printf("nCopied String :%s",user1);
len=str_len(user1);
printf("nLength of copied string : %d",len);
88
str_cat(user1,p);
printf("nConcatenated String : %s",user1);
len=str_cmp(user2,cto);
printf("nCompare string : %d",len);
printf("nvariable chr to uppercase :%c",to_upper(chr));
printf("nvariable chr to lowercase :%c",to_lower(chr));
}
int to_upper(char c)
{
if (c>=97 && c<=122)
c=c-32;
}
int to_lower(char c)
{
if (c>=65 && c<=90)
c=c+32;
}
int str_cmp(char str1[], char str2[])
{
int i;
for (i=0;str1[i]==str2[i] && str1[i]=='0';++i);
if (str1[i]==str2[i])
return 0;
else
return 1;
}
void str_cat(char user1[],char ceo[])
{
int i,j;
i=str_len(user1);
for (j=0; ceo[j]!='0';++j,++i)
user1[i]=ceo[j];
user1[i]='0';
}
int str_len(char user[])
{
int a=0;
for (;user[a]!='0';++a);
return a;
}
89
void str_cpy(char user1[],char ceo[])
{
int i=0;
for(;ceo[i]!='0';i++)
user1[i]=ceo[i];
user1[i]='0';
}
OUTPUT:
Enter string 1 : Whatsapp
Enter String 2 : Instagram
Using Built In Functions
Original string 1: Whatsapp
Copied String of 1 :Whatsapp
Length of copied string : 8
Concatenated String : WhatsappInstagram
Compare string : 0
variable chr to uppercase :S
variable chr to lowercase :s
Without Built In Functions
Original string : Whatsapp
Copied String :Whatsapp
Length of copied string : 8
Concatenated String : WhatsappCHATUS
Compare string : 0
variable chr to uppercase :S
variable chr to lowercase :s
RESULT:
Thus, the above code has executed successfully.
90
EX.NO: 11
DATE : 12-03-2021
USE OF POINTERS
AIM:
To create a algorithm, program and output to illustrate the use of pointers.
ALGORITHM:
Step 1. Start the program.
Step 2. Initialize petrol is 86.3 and diesel is 70.2.
Step 3. Print to output screen “Before Passing values”.
Step 4. Print the value of petrol and diesel.
Step 5. Call the change(&petrol,&diesel) function and pass the addresses of petrol and
diesel and go to step 9.
Step 6. Print to output screen “After Passing values”.
Step 7. Print the value of petrol and diesel.
Step 8. End the program.
Step 9. Declare the pointer variables petrol and diesel.
Step 10. Add 13.5 to the *petrol.
Step 11. Add 15.7 to the *diesel.
Step 12. End of the change() function.
PROGRAM:
#include<stdio.h>
void change(float *petrol, float *diesel);
int main()
{
float petrol=86.3,diesel=70.2;
printf("nBefore Passing values ");
printf("nPetrol Price = Rs.%.2f/-",petrol);
printf("nDiesel Price = Rs.%.2f/-",diesel);
//Passing address of petrol and diesel
change(&petrol,&diesel);
printf("nAfter Passing values ");
91
printf("nPetrol Price = Rs.%.2f/-",petrol);
printf("nDiesel Price = Rs.%.2f/-",diesel);
return 0;
}
void change(float *petrol, float *diesel)
{
//Increment the value of Petrol
*petrol=*petrol+13.5;
//Increment the value of diesel
*diesel=*diesel+15.7;
}
OUTPUT:
Before Passing values
Petrol Price = Rs.86.30/-
Diesel Price = Rs.70.20/-
After Passing values
Petrol Price = Rs.99.80/-
Diesel Price = Rs.85.90/-
RESULT:
Thus the above code has executed successfully.
92
EX.NO : 12
DATE : 12-03-2021
USE OF USER DEFINED DATA TYPES
AIM:
To create an algorithm, program and output for the user defined data types.
ALGORITHM:
ALGORITHM A : STRUCTURE
Step 1. Start the program.
Step 2. Create a structure date which has the following members.
Step 3. Day,month,year of type unsigned integer and end of structure date.
Step 4. Create a structure student which has the following members.
Step 5. Rollno[10] and name[30]] as a type of char and cutoff of float and age as short.
Step 6. Create a structure variable for structure date as dob.
Step 7. End of the structure student with variable a[50].
Step 8. Read the value of n as how many number of students.
Step 9. Initialize i is 0.
Step 10. If (i<n) is true, do the following steps, otherwise go to step 15.
Step 11. Read the value of a[i].roll_no, a[i].name, a[i].age and a[i].cut_off.
Step 12. Call the function date_of_birth(i) and pass the value of i. go to step 20.
Step 13. Increment the value of i.
Step 14. Repeat step 10.
Step 15. Print to output screen” nnROLL_NO tNAME ttDATE-OF-BIRTH tAGE
tCUTT-OFFn”.
Step 16. Set i is 0.
Step 17. If (i<n) is true, do the following steps, otherwise go to step 19.
Step 18. Print the values of
a[i].roll_no,a[i].name,a[i].dob.day,a[i].dob.month,a[i].dob.year,a[i].age,a[i].cut_off with
horizontal spaces. Repeat step 17.
Step 19. End the program.
Step 20. Declare date, year and month.
Step 21. Read the values of a[i].dob.day, a[i].dob.month, a[i].dob.year.
Step 22. Assign year is a[i].dob.year, month is a[i].dob.month and date as a[i].dob.day.
Step 23. If (year>1970 && year<=2021), then do following steps, otherwise go to step 27.
Step 24. If (year%4==0 && year%100!=0 ||year%400==0), then do the step 25, otherwise
do step 26.
93
Step 25. Call CHECK(date,month,i,1) function by passing values of date, month and i and
1(go to step 29). After executing, go to step 28.
Step 26. Call CHECK(date,month,i,1) function by passing values of date, month and i and
2(go to step 29). After executing, go to step 28.
Step 27. Print “Invalid Year” and call the function date_of_birth(i) (i.e., go to step 20).
Step 28. End of date_of_birth(i) function.
Step 29. If (month==1 || month==3 || month==5 || month==7 || month==8 ||month==10 ||
month==12) is true, then go to step 30, otherwise go to step 31.
Step 30. Assign month is 1 and go to step 33.
Step 31. If (month==4 || month==6 || month==9 || month==11) is true, then go to step 32,
otherwise go to step 33.
Step 32. Assign month is 3.
Step 33. If (month==1), then do following steps, otherwise go to step 37.
Step 34. If (!(day>0 && day<=31)) is true, then do following, otherwise go to step 51.
Step 35. Print “Invalid Date”.
Step 36. Call date_of_birth(i) function (i.e., go to step 20).
Step 37. If (month==2), then do following steps, otherwise go to step 45.
Step 38. If (j==1) is true, then do following steps, otherwise go to step 42.
Step 39. If (!(day>0 && day<=29)) is true, then do following, otherwise go to step 51.
Step 40. Print “Invalid Date”.
Step 41. Call date_of_birth(i) function (i.e., go to step 20).
Step 42. If (!(day>0 && day<=28)) is true, then do following, otherwise go to step 51.
Step 43. Print “Invalid Date”.
Step 44. Call date_of_birth(i) function (i.e., go to step 20).
Step 45. If (month==3) is true, then do following, otherwise go to step 49.
Step 46. If (!(day>0 && day<=29)) is true, then do following, otherwise go to step 51.
Step 47. Print “Invalid Date”.
Step 48. Call date_of_birth(i) function (i.e., go to step 20).
Step 49. Print “Invalid month”.
Step 50. Call date_of_birth(i) function (i.e., go to step 20).
Step 51. End of CHECK () function.
ALGORITHM B : UNION
Step 1. Start the program.
Step 2. Declare the union name as view with members val_1 as integer, val_2 as float and
val_3[30] as char.
Step 3. End the union with variable name data.
Step 4. Print “Assigning and printing the union data one by one”.
Step 5. Assign data.val_1 as 512.
Step 6. Print the value of val_1.
94
Step 7. Assign data.val_1 as 12.56.
Step 8. Print the value of val_2.
Step 9. Use strcpy() function to copy “HelloC” to data.val_3.
Step 10. Print the value of val_3.
Step 11. Print “Try to print the value of val_1 and val_2”.
Step 12. Print the value of val_1.
Step 13. Print the value of val_2.
Step 14. Print “Printing the lastly stored value”.
Step 15. Print the value of val_3.
Step 16. End of the program.
ALGORITHM C : ENUMERATED TYPE
Step 1. Start the program.
Step 2. Create an enum channel_no with sun, vijay equals 6, ktv, zee equals 9, vasanth
,hdmusic.
Step 3. Print channel no of sun.
Step 4. Print channel no of vijay.
Step 5. Print channel no of ktv.
Step 6. Print channel no of zee.
Step 7. Print channel no of vasanth.
Step 8. Print channel no of hdmusic.
Step 9. End the program.
ALGORITHM D : TYPEDEF
Step 1. Start the program.
Step 2. Using typedef, long long int as NUM.
Step 3. Initialize aadhar_num[50],phone_num[50] as type NUM.
Step 4. Declare i and n.
Step 5. Read the value of n.
Step 6. Set i is 0.
Step 7. If (i<n) is true, then go to step 8, otherwise go to step 11.
Step 8. Read the value of aadhar_num[i],phone_num[i].
Step 9. Increment the value of i by 1.
Step 10. Repeat the step 7.
Step 11. Print “Entered Details : “.
Step 12. Print “S.no AadharNumber PhoneNumber” with horizontal spaces.
Step 13. Set i is 0.
Step 14. If (i<n) is true, then go to step 15, otherwise go to step 18.
Step 15. Print the value of aadhar_num[i],phone_num[i].
Step 16. Increment the value of i by 1.
95
Step 17. Repeat step 14.
Step 18. End the program.
PROGRAM:
PROGRAM A : STRUCTURE
#include<stdio.h>
void date_of_birth(short i);
void CHECK(int day,int month,short i,int j);
struct date
{
unsigned int day;
unsigned int month;
unsigned int year;
};
struct Student
{
char roll_no[10],name[30];
float cut_off;
short age;
struct date dob;
}a[50];
int main()
{
short i,n;
printf("nEnter how many number of students (Max:50) : ");
scanf("%hd",&n);
for (i=0;i<n;i++)
{
printf("nEnter Roll Number of student %hd : ",i+1);
scanf("%s",&a[i].roll_no);
printf("nEnter Name of student %hd : ",i+1);
scanf("%s",a[i].name);
date_of_birth(i);
printf("nEnter Age of student %hd : ",i+1);
scanf("%hd",&a[i].age);
printf("nEnter Cutt-Off of student %hd : ",i+1);
scanf("%f",&a[i].cut_off);
}
printf("nnROLL_NO tNAME ttDATE-OF-BIRTH tAGE tCUTT-OFFn");
for (i=0;i<n;i++)
96
{
printf("n%s t%s tt%u-%u-%u t%hd
t%.2f",a[i].roll_no,a[i].name,a[i].dob.day,a[i].dob.month,a[i].dob.year,a[i].age,a[i].cut_off);
}
return 0;
}
void date_of_birth(short i)
{
int date,year,month;
printf("nEnter Date of birth of student %hd (dd/mm/yy) n(year must greater than 1970
and less than or equal to 2021)n : ",i+1);
scanf("%u %u %u",&a[i].dob.day,&a[i].dob.month,&a[i].dob.year);
year=a[i].dob.year;
month=a[i].dob.month;
date=a[i].dob.day;
if (year>1970 && year<=2021)
{
if (year%4==0 && year%100!=0 ||year%400==0)
CHECK(date,month,i,1);
else
CHECK(date,month,i,2);
}
else
{
printf("nINVALID YEAR t TRY AGAIN");
date_of_birth(i);
}
}
void CHECK(int day,int month,short i,int j)
{
if (month==1 || month==3 || month==5 || month==7 || month==8 ||month==10 ||
month==12)
month=1;
else if (month==4 || month==6 || month==9 || month==11)
month=3;
switch(month)
{
case 1:
if (!(day>0 && day<=31))
{
97
printf("nINVALID DATE t TRY AGAIN");
date_of_birth(i);
}
break;
case 2:
if (j==1)
{
if (!(day>0 && day<=29))
{
printf("nINVALID DATE t TRY AGAIN");
date_of_birth(i);
}
}
else
{
if (!(day>0 && day<=28))
{
printf("nINVALID DATE t TRY AGAIN");
date_of_birth(i);
}
}
break;
case 3:
if (!(day>0 && day<=30))
{
printf("nINVALID DATE t TRY AGAIN");
date_of_birth(i);
}
break;
default:
printf("nINVALID MONTH t TRY AGAIN");
date_of_birth(i);
}
}
98
PROGRAM B : UNION
#include<stdio.h>
#include<string.h>
union view
{
int val_1;
float val_2;
char val_3[30];
}data;
int main()
{
printf("nAssigning and printing the union data one by one ");
data.val_1=512;
printf("nVal_1 = %d",data.val_1);
data.val_2=12.56;
printf("nVal_2 = %f",data.val_2);
strcpy(data.val_3,"HelloC");
printf("nVal_3 = %s",data.val_3);
printf("nTry to print the value of val_1 and val_2");
printf("nVal_1 = %d",data.val_1);
printf("nVal_2 = %f",data.val_2);
printf("nPrinting the lastly stored value ");
printf("nVal_3 = %s",data.val_3);
return 0;
}
PROGRAM C : ENUMERATED TYPE
#include<stdio.h>
enum channel_no{ sun,vijay=6,ktv,zee=9,vasanth,hdmusic};
int main()
{
printf("nChannel no of Sun_ch = %d",sun);
printf("nChannel no of Vijay_ch = %d",vijay);
printf("nChannel no of KTV_ch = %d",ktv);
printf("nChannel no of Zee_ch = %d",zee);
printf("nChannel no of Vasanth_ch = %d",vasanth);
printf("nChannel no of hdmusic_ch = %d",hdmusic);
}
99
PROGRAM D : TYPEDEF
#include<stdio.h>
typedef long long int NUM;
int main()
{
NUM aadhar_num[50],phone_num[50];
int i,n;
printf("nEnter number of students : ");
scanf("%d",&n);
for (i=0;i<n;i++)
{
printf("nEnter Aadhar number of student %d : ",i+1);
scanf("%lld",&aadhar_num[i]);
printf("nEnter Phone number of student %d : ",i+1);
scanf("%lld",&phone_num[i]);
}
printf("nnEntered Details are : n");
printf("nS.No tAadharNumber tPhoneNumber");
for (i=0;i<n;i++)
printf("n%d t%lld t%lld ",i+1,aadhar_num[i],phone_num[i]);
return 0;
}
OUTPUT:
OUTPUT A : STRUCTURE
Enter how many number of students (Max:50) : 5
Enter Roll Number of student 1 : 20CSR137
Enter Name of student 1 : RAJA
Enter Date of birth of student 1 (dd/mm/yy)
(year must greater than 1970 and less than or equal to 2021)
: 25
3
2001
100
Enter Age of student 1 : 19
Enter Cutt-Off of student 1 : 180.3
Enter Roll Number of student 2 : 20CSR138
Enter Name of student 2 : RAVI
Enter Date of birth of student 2 (dd/mm/yy)
(year must greater than 1970 and less than or equal to 2021)
: 1
1
2001
Enter Age of student 2 : 19
Enter Cutt-Off of student 2 : 179.8
Enter Roll Number of student 3 : 20CSR139
Enter Name of student 3 : RAGU
Enter Date of birth of student 3 (dd/mm/yy)
(year must greater than 1970 and less than or equal to 2021)
: 14
2
2002
Enter Age of student 3 : 19
Enter Cutt-Off of student 3 : 185.6
Enter Roll Number of student 4 : 20CCSR140
Enter Name of student 4 : RANI
Enter Date of birth of student 4 (dd/mm/yy)
(year must greater than 1970 and less than or equal to 2021)
: 25
05
101
2002
Enter Age of student 4 : 19
Enter Cutt-Off of student 4 : 170.9
Enter Roll Number of student 5 : 20CSR141
Enter Name of student 5 : SANJU
Enter Date of birth of student 5 (dd/mm/yy)
(year must greater than 1970 and less than or equal to 2021)
: 12
8
2002
Enter Age of student 5 : 19
Enter Cutt-Off of student 5 : 185.3
ROLL_NO NAME DATE-OF-BIRTH AGE CUTT-OFF
20CSR137 RAJA 25-3-2001 19 180.30
20CSR138 RAVI 1-1-2001 19 179.80
20CSR139 RAGU 14-2-2002 19 185.60
20CCSR140 RANI 25-5-2002 19 170.90
20CSR141 SANJU 12-8-2002 19 185.30
OUTPUT B : UNION
Assigning and printing the union data one by one
Val_1 = 512
Val_2 = 12.560000
Val_3 = HelloC
Try to print the value of val_1 and val_2
Val_1 = 1819043144
Val_2 = 1143139122437582500000000000.000000
Printing the lastly stored value
Val_3 = HelloC
102
OUTPUT C : ENUMERATED TYPE
Channel no of Sun_ch = 0
Channel no of Vijay_ch = 6
Channel no of KTV_ch = 7
Channel no of Zee_ch = 9
Channel no of Vasanth_ch = 10
Channel no of hdmusic_ch = 11
OUTPUT D : TYPEDEF
Enter number of students : 4
Enter Aadhar number of student 1 : 679712345678
Enter Phone number of student 1 : 9361742589
Enter Aadhar number of student 2 : 789654123321
Enter Phone number of student 2 : 7458963214
Enter Aadhar number of student 3 : 639852147852
Enter Phone number of student 3 : 8523697410
Enter Aadhar number of student 4 : 623145897753
Enter Phone number of student 4 : 8760306138
Entered Details are :
S.No AadharNumber PhoneNumber
1 679712345678 9361742589
2 789654123321 7458963214
3 639852147852 8523697410
4 623145897753 8760306138
RESULT:
Thus the above code has executed successfully.
103

Mais conteúdo relacionado

Mais procurados

Python programs - first semester computer lab manual (polytechnics)
Python programs - first semester computer lab manual (polytechnics)Python programs - first semester computer lab manual (polytechnics)
Python programs - first semester computer lab manual (polytechnics)SHAMJITH KM
 
Graph theory narsingh deo
Graph theory narsingh deoGraph theory narsingh deo
Graph theory narsingh deoUmang Gupta
 
Instruction codes and computer registers
Instruction codes and computer registersInstruction codes and computer registers
Instruction codes and computer registersSanjeev Patel
 
Microprocessor Part 2
Microprocessor    Part 2Microprocessor    Part 2
Microprocessor Part 2Sajan Agrawal
 
Register organization, stack
Register organization, stackRegister organization, stack
Register organization, stackAsif Iqbal
 
IO Techniques in Computer Organization
IO Techniques in Computer OrganizationIO Techniques in Computer Organization
IO Techniques in Computer OrganizationOm Prakash
 
How to add system calls to OS/161
How to add system calls to OS/161How to add system calls to OS/161
How to add system calls to OS/161Xiao Qin
 
IRJET- Design and Verification of APB Protocol by using System Verilog and Un...
IRJET- Design and Verification of APB Protocol by using System Verilog and Un...IRJET- Design and Verification of APB Protocol by using System Verilog and Un...
IRJET- Design and Verification of APB Protocol by using System Verilog and Un...IRJET Journal
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Urvashi Singh
 
CS304PC:Computer Organization and Architecture Session 11 general register or...
CS304PC:Computer Organization and Architecture Session 11 general register or...CS304PC:Computer Organization and Architecture Session 11 general register or...
CS304PC:Computer Organization and Architecture Session 11 general register or...Asst.prof M.Gokilavani
 
3.programmable interrupt controller 8259
3.programmable interrupt controller 82593.programmable interrupt controller 8259
3.programmable interrupt controller 8259MdFazleRabbi18
 

Mais procurados (20)

DMA presentation [By- Digvijay]
DMA presentation [By- Digvijay]DMA presentation [By- Digvijay]
DMA presentation [By- Digvijay]
 
Python programs - first semester computer lab manual (polytechnics)
Python programs - first semester computer lab manual (polytechnics)Python programs - first semester computer lab manual (polytechnics)
Python programs - first semester computer lab manual (polytechnics)
 
Graph theory narsingh deo
Graph theory narsingh deoGraph theory narsingh deo
Graph theory narsingh deo
 
The IEEE 1149.1 Boundary-scan test standard
The IEEE 1149.1 Boundary-scan test standardThe IEEE 1149.1 Boundary-scan test standard
The IEEE 1149.1 Boundary-scan test standard
 
Instruction codes and computer registers
Instruction codes and computer registersInstruction codes and computer registers
Instruction codes and computer registers
 
Microprocessor Part 2
Microprocessor    Part 2Microprocessor    Part 2
Microprocessor Part 2
 
Register organization, stack
Register organization, stackRegister organization, stack
Register organization, stack
 
Verilog tutorial
Verilog tutorialVerilog tutorial
Verilog tutorial
 
Verilog hdl
Verilog hdlVerilog hdl
Verilog hdl
 
IO Techniques in Computer Organization
IO Techniques in Computer OrganizationIO Techniques in Computer Organization
IO Techniques in Computer Organization
 
How to add system calls to OS/161
How to add system calls to OS/161How to add system calls to OS/161
How to add system calls to OS/161
 
IRJET- Design and Verification of APB Protocol by using System Verilog and Un...
IRJET- Design and Verification of APB Protocol by using System Verilog and Un...IRJET- Design and Verification of APB Protocol by using System Verilog and Un...
IRJET- Design and Verification of APB Protocol by using System Verilog and Un...
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086
 
8086 Microprocessor
8086 Microprocessor8086 Microprocessor
8086 Microprocessor
 
Interrupt
InterruptInterrupt
Interrupt
 
CS304PC:Computer Organization and Architecture Session 11 general register or...
CS304PC:Computer Organization and Architecture Session 11 general register or...CS304PC:Computer Organization and Architecture Session 11 general register or...
CS304PC:Computer Organization and Architecture Session 11 general register or...
 
Memory Reference instruction
Memory Reference instructionMemory Reference instruction
Memory Reference instruction
 
8253,8254
8253,8254 8253,8254
8253,8254
 
3.programmable interrupt controller 8259
3.programmable interrupt controller 82593.programmable interrupt controller 8259
3.programmable interrupt controller 8259
 
Unit vi
Unit viUnit vi
Unit vi
 

Semelhante a PSP LAB MANUAL.pdf

Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in cBUBT
 
Lecture_Activities_4.1_to_4.7.pdf.pdf
Lecture_Activities_4.1_to_4.7.pdf.pdfLecture_Activities_4.1_to_4.7.pdf.pdf
Lecture_Activities_4.1_to_4.7.pdf.pdfNancySantos49
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEWshyamuopeight
 
Unit 3 Foc
Unit  3 FocUnit  3 Foc
Unit 3 FocJAYA
 
UNIT I - Algorithmic Problem Solving.pptx
UNIT I - Algorithmic Problem Solving.pptxUNIT I - Algorithmic Problem Solving.pptx
UNIT I - Algorithmic Problem Solving.pptxPradeepkumar964266
 
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTSALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTSKate Campbell
 
DSA Lesson 2 - Algorithm and Flowcharting.pdf
DSA Lesson 2 - Algorithm and Flowcharting.pdfDSA Lesson 2 - Algorithm and Flowcharting.pdf
DSA Lesson 2 - Algorithm and Flowcharting.pdfROWELL MARQUINA
 
25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manualkamesh dagia
 
Scilab as a calculator
Scilab as a calculatorScilab as a calculator
Scilab as a calculatorScilab
 
Lesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfLesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfROWELL MARQUINA
 
presentation_python_11_1569171345_375360.pptx
presentation_python_11_1569171345_375360.pptxpresentation_python_11_1569171345_375360.pptx
presentation_python_11_1569171345_375360.pptxGAURAVRATHORE86
 
Isc computer project final upload last
Isc computer project final upload lastIsc computer project final upload last
Isc computer project final upload lastArunav Ray
 

Semelhante a PSP LAB MANUAL.pdf (20)

C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in c
 
Lecture_Activities_4.1_to_4.7.pdf.pdf
Lecture_Activities_4.1_to_4.7.pdf.pdfLecture_Activities_4.1_to_4.7.pdf.pdf
Lecture_Activities_4.1_to_4.7.pdf.pdf
 
03b loops
03b   loops03b   loops
03b loops
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEW
 
our c prog work
our c prog workour c prog work
our c prog work
 
Unit 3 Foc
Unit  3 FocUnit  3 Foc
Unit 3 Foc
 
UNIT I - Algorithmic Problem Solving.pptx
UNIT I - Algorithmic Problem Solving.pptxUNIT I - Algorithmic Problem Solving.pptx
UNIT I - Algorithmic Problem Solving.pptx
 
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTSALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
 
LMmanual.pdf
LMmanual.pdfLMmanual.pdf
LMmanual.pdf
 
c programing
c programingc programing
c programing
 
Mathcad
MathcadMathcad
Mathcad
 
DSA Lesson 2 - Algorithm and Flowcharting.pdf
DSA Lesson 2 - Algorithm and Flowcharting.pdfDSA Lesson 2 - Algorithm and Flowcharting.pdf
DSA Lesson 2 - Algorithm and Flowcharting.pdf
 
25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual
 
Scilab as a calculator
Scilab as a calculatorScilab as a calculator
Scilab as a calculator
 
Aguirre.Module2.Problemset.pdf
Aguirre.Module2.Problemset.pdfAguirre.Module2.Problemset.pdf
Aguirre.Module2.Problemset.pdf
 
Cp manual final
Cp manual finalCp manual final
Cp manual final
 
Lesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfLesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdf
 
presentation_python_11_1569171345_375360.pptx
presentation_python_11_1569171345_375360.pptxpresentation_python_11_1569171345_375360.pptx
presentation_python_11_1569171345_375360.pptx
 
Isc computer project final upload last
Isc computer project final upload lastIsc computer project final upload last
Isc computer project final upload last
 

Mais de Selvaraj Seerangan

Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...Selvaraj Seerangan
 
END SEM _ Design Thinking _ 16 Templates.pptx
END SEM _ Design Thinking _ 16 Templates.pptxEND SEM _ Design Thinking _ 16 Templates.pptx
END SEM _ Design Thinking _ 16 Templates.pptxSelvaraj Seerangan
 
Design Thinking _ Complete Templates.pptx
Design Thinking _ Complete Templates.pptxDesign Thinking _ Complete Templates.pptx
Design Thinking _ Complete Templates.pptxSelvaraj Seerangan
 
CAT 3 _ List of Templates.pptx
CAT 3 _ List of Templates.pptxCAT 3 _ List of Templates.pptx
CAT 3 _ List of Templates.pptxSelvaraj Seerangan
 
[PPT] _ Unit 3 _ Experiment.pptx
[PPT] _ Unit 3 _ Experiment.pptx[PPT] _ Unit 3 _ Experiment.pptx
[PPT] _ Unit 3 _ Experiment.pptxSelvaraj Seerangan
 
CAT 2 _ List of Templates.pptx
CAT 2 _ List of Templates.pptxCAT 2 _ List of Templates.pptx
CAT 2 _ List of Templates.pptxSelvaraj Seerangan
 
Design Thinking - Empathize Phase
Design Thinking - Empathize PhaseDesign Thinking - Empathize Phase
Design Thinking - Empathize PhaseSelvaraj Seerangan
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdfSelvaraj Seerangan
 
CAT 1 _ List of Templates.pptx
CAT 1 _ List of Templates.pptxCAT 1 _ List of Templates.pptx
CAT 1 _ List of Templates.pptxSelvaraj Seerangan
 
[PPT] _ UNIT 1 _ COMPLETE.pptx
[PPT] _ UNIT 1 _ COMPLETE.pptx[PPT] _ UNIT 1 _ COMPLETE.pptx
[PPT] _ UNIT 1 _ COMPLETE.pptxSelvaraj Seerangan
 
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdfSelvaraj Seerangan
 
[PPT] _ Unit 2 _ Complete PPT.pptx
[PPT] _ Unit 2 _ Complete PPT.pptx[PPT] _ Unit 2 _ Complete PPT.pptx
[PPT] _ Unit 2 _ Complete PPT.pptxSelvaraj Seerangan
 

Mais de Selvaraj Seerangan (20)

Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
 
Unit 5 _ Fog Computing .pdf
Unit 5 _ Fog Computing .pdfUnit 5 _ Fog Computing .pdf
Unit 5 _ Fog Computing .pdf
 
CAT III Answer Key.pdf
CAT III Answer Key.pdfCAT III Answer Key.pdf
CAT III Answer Key.pdf
 
END SEM _ Design Thinking _ 16 Templates.pptx
END SEM _ Design Thinking _ 16 Templates.pptxEND SEM _ Design Thinking _ 16 Templates.pptx
END SEM _ Design Thinking _ 16 Templates.pptx
 
Design Thinking _ Complete Templates.pptx
Design Thinking _ Complete Templates.pptxDesign Thinking _ Complete Templates.pptx
Design Thinking _ Complete Templates.pptx
 
CAT 3 _ List of Templates.pptx
CAT 3 _ List of Templates.pptxCAT 3 _ List of Templates.pptx
CAT 3 _ List of Templates.pptx
 
[PPT] _ Unit 5 _ Evolve.pptx
[PPT] _ Unit 5 _ Evolve.pptx[PPT] _ Unit 5 _ Evolve.pptx
[PPT] _ Unit 5 _ Evolve.pptx
 
[PPT] _ Unit 4 _ Engage.pptx
[PPT] _ Unit 4 _ Engage.pptx[PPT] _ Unit 4 _ Engage.pptx
[PPT] _ Unit 4 _ Engage.pptx
 
[PPT] _ Unit 3 _ Experiment.pptx
[PPT] _ Unit 3 _ Experiment.pptx[PPT] _ Unit 3 _ Experiment.pptx
[PPT] _ Unit 3 _ Experiment.pptx
 
CAT 2 _ List of Templates.pptx
CAT 2 _ List of Templates.pptxCAT 2 _ List of Templates.pptx
CAT 2 _ List of Templates.pptx
 
Design Thinking - Empathize Phase
Design Thinking - Empathize PhaseDesign Thinking - Empathize Phase
Design Thinking - Empathize Phase
 
CAT-II Answer Key.pdf
CAT-II Answer Key.pdfCAT-II Answer Key.pdf
CAT-II Answer Key.pdf
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
 
DS LAB MANUAL.pdf
DS LAB MANUAL.pdfDS LAB MANUAL.pdf
DS LAB MANUAL.pdf
 
CAT 1 _ List of Templates.pptx
CAT 1 _ List of Templates.pptxCAT 1 _ List of Templates.pptx
CAT 1 _ List of Templates.pptx
 
[PPT] _ UNIT 1 _ COMPLETE.pptx
[PPT] _ UNIT 1 _ COMPLETE.pptx[PPT] _ UNIT 1 _ COMPLETE.pptx
[PPT] _ UNIT 1 _ COMPLETE.pptx
 
CAT-1 Answer Key.doc
CAT-1 Answer Key.docCAT-1 Answer Key.doc
CAT-1 Answer Key.doc
 
Unit 3 Complete.pptx
Unit 3 Complete.pptxUnit 3 Complete.pptx
Unit 3 Complete.pptx
 
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
 
[PPT] _ Unit 2 _ Complete PPT.pptx
[PPT] _ Unit 2 _ Complete PPT.pptx[PPT] _ Unit 2 _ Complete PPT.pptx
[PPT] _ Unit 2 _ Complete PPT.pptx
 

Último

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 

Último (20)

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 

PSP LAB MANUAL.pdf

  • 1. KONGU ENGINEERING COLLEGE (Autonomous) PERUNDURAI, ERODE- 638 052 2020 - 2021 20CSL11 PROBLEM SOLVING AND PROGRAMMING LABORATORY Name : NEERAJ M Roll No : 20CSR137 Branch : COMPUTER SCIENCE AND ENGINEERING Semester : ODD SEMESTER Year : FIRST YEAR Section : C
  • 2. 2 INDEX Serial No. Experiment Date Name of the Experiment Marks Signature of the Staff 1 08-01-2021 Sequential Structures 2 29-01-2021 Selective Structures 3 05-02-2021 Repetitive Structures 4 12-02-2021 Different Types of Operators in Sequential Structures 5 19-02-2021 Different Formatting Options For Input And Output 6 26-02-2021 Decision Making Statements 7 05-03-2021 Repetitive Control Statements 8 05-03-2021 One-Dimensional And Two- Dimensional Numeric Array 9 05-03-2021 Modular Programming Concepts 10 12-05-2021 Character -String Operations With And Without Built-in Functions 11 12-05-2021 Use Of Pointers 12 12-05-2021 Use Of User Defined Data Types
  • 3. 3 EXE NO: 1 DATE : 08/01/2021 SEQUENTIAL STRUCTURES 1. CUT-OFF: Algorithm: Step 1: Start the program Step 2: Read marks of Phy, Che and Math. Step 3: Compute sum of Phy and Che and divide it by 2. Step 4: Add the result with Math. Step 5: Store the result in the variable Cut_off. Step 6: Print the value of Cut_off. Step 7: End of a program. Flow Chart:
  • 4. 4 2. SWAPPING OF TWO VARIABLES: A.EXCHANGING TWO VARIABLES WITH TEMPORARY VARIABLE: Algorithm: Step 1. Start the program. Step 2. Read the value of a and b. Step 3. Print the both values of a and b before swapping. Step 4. Create a temporary variable named c. Step 5. Assign the value of a in c and b in a, then c in a. Step 6. Now, print both the values of and b after swapping. Step 7. End of the program. Flow Chart:
  • 5. 5 B.EXCHANGING TWO VARIABLES WITHOUT TEMPORARY VARIABLE: Algorithm: Step 1. Start the program. Step 2. Read the value of a and b. Step 3. Print the both values of a and b before swapping. Step 4. Assign a equals a+b, b equals a-b and a equals a-b. Step 5. Now, print both the values of and b after swapping. Step 6. End of the program. Flow Chart:
  • 6. 6 3. FRUIT STALL: Algorithm: Step 1. Start the program. Step 2. Read the values of how many kg of apple and orange. Step 3. Assign apple equals apple*180 and orange equals orange*80. Step 4. Now, add apple and orange. Step 5. Store the result in amount. Step 6. Print the value of amount. Step 7. End of the program. Flowchart:
  • 7. 7 EXE NO: 2 DATE : 29/01/2021 SELECTIVE STRUCTURES 1. QUADRATIC EQUATION: Algorithm: Step 1. Start the program. Step 2. Read the values of A, B and C. Step 3. Assign discriminant equals (B*B)-(4*A*C). Step 4. If discriminant >0 is true, go to step 5, otherwise go to step 6. Step 5. Print the roots are real and distinct and go to step 9. Step 6. If discriminant <0 is true, go to step 7, otherwise go to step 8. Step 7. Print the roots are imaginary and go to step 9. Step 8. Print the roots are real and equal. Step 9. Stop the program.
  • 9. 9 2. TNEB BILL: Algorithm: Step 1. Start the program. Step 2. Read the value of units from the user. Step 3. If units <=100 is true, go to step 4, otherwise go to step 5. Step 4. Assign bill is 0 and go to step 13. Step 5. If [(units>100) and (units<=200)] is true, go to step 6, otherwise go to step 8. Step 6. Subtract 100 from the units and multiply by 1.5 and add 20 to it. Step 7. Store the result in the bill and go to step 13. Step 8. If [(units>200) and (units<=500)] is true, go to step 9, otherwise go to step 11. Step 9. Subtract 200 from the units and multiply units by 3 and add 230 with it. Step 10. Store the result in the bill and go to step 13. Step 11. Subtract 500 from the units and multiply units by 6.6 and add 1780 with it. Step 12. Store the result in the bill. Step 13. Print the value of bill. Step 14. Stop the program.
  • 11. 11 3. GRADE FOR A SUBJECT: Algorithm: Step 1. Start the program. Step 2. Read the value of PSP mark from the user. Step 3. If ((PSP>90) and (PSP<=100)) is true, go to step 4, otherwise go to step 5. Step 4. Print “Your grade is O” and go to step 14. Step 5. If ((PSP>80) and (PSP<91)) is true, go to step 6, otherwise go to step 7. Step 6. Print “Your grade is A++” and go to step 14. Step 7. If ((PSP>70) and (PSP<81)) is true, go to step 8, otherwise go to step 9. Step 8. Print “Your grade is A” and go to step 14. Step 9. If ((PSP>60) and (PSP<71)) is true, go to step 10, otherwise go to step 11. Step 10. Print “Your grade is B++” and go to step 14. Step 11. If ((PSP>=50) and (PSP<=60)) is true, go to step 12, otherwise go to step 13. Step 12. Print “Your grade is B” and go to step 14. Step 13. Print “Your grade is RA – Reappear for Exam”. Step 14. Stop the program.
  • 13. 13 EXE : 3 DATE : 05-02-2021 REPETITIVE STRUCTURES 1. FIBONACCI SEQUENCE Algorithm: Step 1. Start the program. Step 2. Read n_terms from the user. Step 3. Assign i is 1, fib_1 is 0 and fib_2 is 1. Step 4. Print “Fibonacci Series”. Step 5. While (i<=n_terms) is true, go to step 6, otherwise go to step 10. Step 6. Add fib_1 and fib_2 and store the result in fib_next. Step 7. Print the value of fib_1. Step 8. Assign fib_2 in fib_1 and fib_next in fib_2. Step 9. Add i by 1 and store it in i and go to step 5. Step 10. Stop the program.
  • 15. 15 2. FACTORIAL Algorithm: Step 1. Start the program. Step 2. Read the value of num. Step 3. Assign fact is 1. Step 4. While (num>0) is true, go to step 1, otherwise go to step 7. Step 5. Multiply num with fact and store it in fact. Step 6. Subtract num by 1 and store it in num and go to step 4. Step 7. Print the value of fact. Step 8. Stop the program.
  • 17. 17 3. NUMBERS AND SQUARES Algorithm: Step 1. Start the program. Step 2. Read num form user. Step 3. Assign i is 1 and sum is 0. Step 4. Print “Number Square” and “=================”. Step 5. While (i<=num) is true, go to step 6, otherwise go to step 10. Step 6. Multiply i by i and store it in sqr. Step 7. Add sum and sqr and store it in sum. Step 8. Print the value of i and sqr using one tab space between them. Step 9. Add i by 1 and store it in i and go to step 5. Step 10. Print the value of sum. Step 11. Stop the program.
  • 19. 19 4. REVERSING THE DIGIT Algorithm: Step 1. Start the program. Step 2. Read the value of num from the user. Step 3. Assign rev is 0. Step 4. Print the value of num. Step 5. While (num>0) is true, go to step 6, otherwise go to step 10. Step 6. Multiply rev by 10 and store it in rev. Step 7. Compute num mod 10 and add the result with rev and store it in rev. Step 8. Divide num by 10 and round down using floor () function. Step 9. Store the result in num and go to step 5. Step 10. Print the value of rev. Step 11. Stop the program.
  • 21. 21 DATE : 12-02-2021 EX.NO : 04 Different types of operators IN SEQUENTIAL STRUCTURES AIM: To create an algorithm, flowchart and C program for the usage of different types of operator. ALGORITHM: Step 1. Start the program. Step 2. Read the values of a, b, c and d.//Arithmetic operator Step 3. Add a and b and store it in c. Step 4. Print the value of c. Step 5. Subtract a and b and store it in c. Step 6. Print the value of c. Step 7. Multiply a and b and store it in c. Step 8. Print the value of c. Step 9. Divide a and b and store it in c. Step 10. Print the value of c. Step 11. Do a mod b and store it in c. Step 12. Print the value of c. Step 13. Do the pre-increment of d and store it in d.//Increment operator Step 14. Print the value of d. Step 15. Do the post-increment of d and store it in d. Step 16. Print the value of d. Step 17. Do the pre-decrement of d and store it in d.//Decrement operator Step 18. Print the value of d. Step 19. Do the post-decrement of d and store it in d. Step 20. Print the value of d. Step 21. Do (a>b&&a==b) and store the result in c.//Logical operator Step 22. Print the value of c. Step 23. Do (a>b&&b>1) and store the result in c. Step 24. Print the value of c. Step 25. Do (a>b||a==b) and store the result in c. Step 26. Print the value of c. Step 27. Do (a<b||a==b) and store the result in c. Step 28. Print the value of c. Step 29. Do (!a>b) and store the result in c.
  • 22. 22 Step 30. Print the value of c. Step 31. Check whether a is equal to b and store the result in c.//Relational operator Step 32. Print the value of c. Step 33. Check whether a is greater than b and store the result in c. Step 34. Print the value of c. Step 35. Check whether a is less than b and store the result in c. Step 36. Print the value of c. Step 37. Check whether a is greater than or equal to b and store the result in c. Step 38. Print the value of c. Step 39. Check whether a is less than or equal to b and store the result in c. Step 40. Print the value of c. Step 41. Check whether a is not equal to b and store the result in c. Step 42. Print the value of c. Step 43. Print “Check a is even or odd using ternary operator”.//Ternary Operator. Step 44. If a mod 2 is equal to 0, then print “It is even”, otherwise print ”It is odd” using the variable c to store. Step 45. End of the program.
  • 24. 24
  • 25. 25
  • 26. 26 PROGRAM: #include<stdio.h> int main(){ int a=10,b=5,c,d=20; printf("nValue of A = %dnValue of B = %d",a,b); printf("ntArithmetic Operatorsn"); //Arithmetic operators c=a+b; printf("nSum (a+b) = %d",c); c=a-b; printf("nDifference(a-b) = %d",c); c=a*b; printf("nProduct (a*b) = %d",c); c=a/b; printf("nQuotient (a/b) = %d",c); c=a%b; printf("nModulous (a%%b) = %d",c); printf("nnValue of d : %d",d); d=++d; // Increment or decrement operator printf("nPreincrement(++d) =%d",d); d=d++; printf("nPost increment(d++) =%d",d); d=d--; printf("nPost decrement(d--) =%d",d); d=--d; printf("nPre decrement(--d) =%d",d); printf("nn t Logical operatorsn"); //Logical Operators c=a>b&&a==b; printf("nAnd (a>b and a==b) = %d",c); c=a>b&&b>1; printf("nAnd (a>b and b>1) = %d",c); c=a>b||a==b; printf("nOr (a>b or a==b) = %d",c); c=a<b||a==b; printf("nOr (a<b or a==b) = %d",c); c=!a>b; printf("nNot (not a>b) = %d",c); //Relational operators
  • 27. 27 printf("nn t Relational Operatorsn"); c=a==b; printf("nEqual (a==b) = %d",c); c=a>b; printf("nGreater than(a>b) = %d",c); c=a<b; printf("nLess than (a<b) = %d",c); c=a>=b; printf("nGreater than or equal to(a>=b) = %d",c); c=a<=b; printf("nLess than or equal to (a<=b) = %d",c); c=a!=b; printf("nNot equal to(a!=b) = %d",c); //Ternary Operator printf("nn tTernary Operator n"); printf("nCheck whether the a is even or odd"); c=(a%2==0)?printf("nA is Even number"):printf("nA is Odd number"); return 0; } OUTPUT: Value of A = 10 Value of B = 5 Arithmetic Operators Sum (a+b) = 15 Difference(a-b) = 5 Product (a*b) = 50 Quotient (a/b) = 2 Modulous (a%b) = 0 Value of d : 20 Preincrement(++d) =21 Post increment(d++) =21 Post decrement(d--) =21 Pre decrement(--d) =20 Logical operators
  • 28. 28 And (a>b and a==b) = 0 And (a>b and b>1) = 1 Or (a>b or a==b) = 1 Or (a<b or a==b) = 0 Not (not a>b) = 0 Relational Operators Equal (a==b) = 0 Greater than(a>b) = 1 Less than (a<b) = 0 Greater than or equal to(a>=b) = 1 Less than or equal to (a<=b) = 0 Not equal to(a!=b) = 1 Ternary Operator Check whether the a is even or odd A is Even number RESULT: This above code has executed successfully.
  • 29. 29 EX.NO : 05 DATE : 19-02-2021 DIFFERENT FORMATTING OPTIONS FOR INPUT AND OUTPUT AIM: To create an algorithm, flowchart and program for different formatting options for input and output. ALGORITHM: Algorithm A: Different Formatting options Step 1. Start the program. Step 2. Use %d (Integer) to print the value 12345. Step 3. Use %04d (Integer) to print the value 49. Step 4. Use %i (Integer) to print the value 49. Step 5. Use %lf (Double) to print the value 25.369852. Step 6. Use %.2lf (Double) to print the value 25.369852. Step 7. Use %le (Double exponential) to print the value 25.369852. Step 8. Use %lg (Double as same) to print the value 2536.3. Step 9. Use %.2Lf (Long Double) to print the value 25.369852. Step 10. Use %Le ( Long Double exponential) to print the value 25.369852. Step 11. Use %Lg (Long Double as same) to print the value 2536.3. Step 12. Use %f (float) to print the value 25.369852. Step 13. Use %.2f (float) to print the value 25.369852. Step 14. Use %e (float exponential) to print the value 25.369852. Step 15. Use %g (float as same) to print the value 2536.3. Step 16. Use %x (Hexa decimal) to print the value 256. Step 17. Use %o (octal) to print the value 256. Step 18. Use %u (unsigned value) to print the value 150. Step 19. Use %% to print %. Step 20. Use %hd (Short signed) to print value 32767. Step 21. Use %hu (short unsigned) to print value 65535. Step 22. Use %d (integer signed) to print value 32767. Step 23. Use %u (integer unsigned) to print value 65535. Step 24. Use %ld (long signed) to print value 2147483647. Step 25. Use %lu (long unsigned) to print value 4294967295. Step 26. Use %lld (long long signed) to print value 9223372036854775807. Step 27. Use %llu (long long unsigned) to print value 18446744073709551615. Step 28. End the program.
  • 30. 30 Algorithm B: gets() and puts() Step 1. Start the program. Step 2. Initialize str[100] using char. Step 3. Read the value of str using gets(). Step 4. Print the value of str using puts(). Step 5. End of the program. Algorithm C: Single Word using scanf() and printf() Step 1. Start the program. Step 2. Initialize str[100] using char. Step 3. Read the value of str using scanf(). Step 4. Print the value of str using printf(). Step 5. End of the program. Algorithm D: fgetc(stdin) and fputc() Step 1. Start the program. Step 2. Initialize c using char. Step 3. Read the value of c using fgetc(). Step 4. Print the value of c using fputc(). Step 5. End of the program. Algorithm E: getchar() and putchar() Step 1. Start the program. Step 2. Initialize c using char. Step 3. Read the value of c using getchar(). Step 4. Print the value of c using putchar(). Step 5. End of the program. C PROGRAM: Program A: Different Formatting options #include<stdio.h> void main() { printf("nInteger 1 :%d",12345); printf("nInteger 2 :%04d",49); printf("nInteger 3 :%i",49); printf("nDouble 1 :%lf",25.369852); printf("nDouble 2 :%.2lf",25.369852);
  • 31. 31 printf("nDouble in exponential :%le",25.365); printf("nDouble as same precision :%lg",25.3); printf("nLong Double 1 :%Lf",25.369852); printf("nLong Double 2 :%.2Lf",25.369852); printf("nLong Double in exponential :%Le",25.365); printf("nLong Double as same precision :%Lg",25.3); printf("nFloat 1 :%f",25.369852); printf("nFloat 2 :%.2f",25.369852); printf("nFloat in exponential :%e",25.365); printf("nFloat as same precision :%g",25.3); printf("nHexadecimal Number : %x",256); printf("nOctal :%o",256); printf("nUnsigned Value :%u",150); printf("nPrint Percentage sign :%%",10); printf("nMy name :%s","Raja"); printf("nShort 1:%hd",32767); printf("nShort(unsigned):%hu",65535); printf("nInteger(Signed) :%d",32767); printf("nInteger (Unsigned) :%u",65535); printf("nLong (signed):%ld",2147483647); printf("nLong (unsigned):%lu",4294967295); printf("nLong long (signed):%lld",9223372036854775807); printf("nLong long (unsigned):%llu",18446744073709551615); } Program B: gets() and puts() //gets() and puts() #include<stdio.h> void main() { char str[100]; printf("nEnter a String :"); gets(str); printf("nString :"); puts(str); }
  • 32. 32 Program C: Single Word using scanf() and printf() //printf() annd scanf() #include<stdio.h> void main() { char str[100]; printf("nEnter a Single Word :"); scanf("%s",str); printf("nSingle Word :%s",str); } Program D: fgetc(stdin) and fputc() //fgetc(stdin) and fputc(stdout) #include<stdio.h> #include<ctype.h> void main() { char c; printf("Enter a Lower-Case Character :"); c=fgetc(stdin); printf("n You entered :"); fputc(toupper(c),stdout); } Program E: getchar() and putchar() //getchar() and putchar() #include <stdio.h> int main( ) { char c; printf( "Enter a character :"); c = getchar( ); printf( "nYou entered: "); putchar( c ); return 0; }
  • 33. 33 OUTPUT: Output A: Different Formatting options Integer 1 :12345 Integer 2 :0049 Integer 3 :49 Double 1 :25.369852 Double 2 :25.37 Double in exponential :2.536500e+001 Double as same precision :25.3 Long Double 1 :25.369852 Long Double 2 :25.37 Long Double in exponential :2.536500e+001 Long Double as same precision :25.3 Float 1 :25.369852 Float 2 :25.37 Float in exponential :2.536500e+001 Float as same precision :25.3 Hexadecimal Number : 100 Octal :400 Unsigned Value :150 Print Percentage sign :% My name :Raja Short 1:32767 Short(unsigned):65535 Integer(Signed) :32767 Integer (Unsigned) :65535 Long (signed):2147483647 Long (unsigned):4294967295 Long long (signed):9223372036854775807 Long long (unsigned):18446744073709551615 Output B: gets() and puts() Enter a String :hi i am a cse student String :hi i am a cse student
  • 34. 34 Output C(i): Single Word using scanf() and printf() Enter a Single Word :VIVO Single Word :VIVO Output C(ii): Single Word using scanf() and printf() Enter a Single Word :VIVO VSE Single Word :VIVO Output D(i): fgetc(stdin) and fputc() Enter a Lower-Case Character :n You entered :N Output D(ii): fgetc(stdin) and fputc() Enter a Lower-Case Character :hello You entered :H Output E: getchar() and putchar() Enter a character :s You entered: s RESULT: The above code is executed successfully.
  • 35. 35 EX. NO : 6 DATE : 26-02-2021 DECISION MAKING STATEMENTS Aim: To create an algorithm, flowchart and C program for decision making statements like ‘if’, ‘else if’, ‘switch’, conditional and unconditional ‘goto’. Algorithm: Algorithm A: IF ELSE Step 1. Start the program. Step 2. Read copy from the user. Step 3. If (copy<=100), then go to step 4, otherwise go to step 5. Step 4. Set rate is 1 and go to step 6. Step 5. Set rate is 0.6. Step 6. Multiply copy and rate. Step 7. Store the result in amount. Step 8. Print the value of amount. Step 9. Stop the program. Algorithm B: ELSE IF Step 1. Start the program. Step 2. Read the values for days and copy from the user and initialize cd_fees is 100. Step 3. If (days<=90), then go to step 4, otherwise go to step 5. Step 4. Set reg_fee is 100 and go to step 8. Step 5. If (days>90 && days<=150), then go to step 6, otherwise go to step 7. Step 6. Set reg_fee is150 and go to step 8. Step 7. Set reg_fee is 1150. Step 8. Multiply copy by 10 and store it in copy_fees. Step 9. Add copy_fees, reg_fee and cd_fees and store it in total. Step 10. Print(“FEES RECEIPT”). Step 11. Print the value of reg_fee, copy_fees, cd_fees and total. Step 12. Stop the program.
  • 36. 36 Algorithm C: SWITCH Main program: Step 1. Start the program. Step 2. Initialize amount with 500000 and def_pin=1302. Step 3. Assign end= check_pin() function. Step 4. If (end==0), then go to step ,otherwise go to step 22. Step 5. Print “1.CHECK BALANCE 2.WITHDRAWL 3.DEPOSIT 4.CHANGE PIN 5.QUIT). Step 6. Read the choice. Step 7. If (choice==1), then go to step 8 , otherwise go to step 9. Step 8. Print the value of amount and go to step 17. Step 9. If Choice==2, then go to step 10, otherwise go to step 11. Step 10. Call withdrawl(&withdraw,&amount) and go to step 17. Step 11. If Choice==3, then go to step 12, otherwise go to step 13. Step 12. Call add_amount(&deposit,&amount) and go to step 17. Step 13. If Choice==4, then go to step 14, otherwise go to step 15. Step 14. Call change_pin() and go to step 17. Step 15. If Choice==5, then go to step 22, otherwise go to step 16. Step 16. Print “INVALID CHOICE”. Step 17. Print “DO YOU WISH TO HAVE ANOTHER TRANSACTION (Y/N)”. Step 18. Read the value of transaction from user. Step 19. If (transaction == 'n'|| transaction == 'N'),then go to step 21 ,otherwise go to step 20. Step 20. Repeat step 5. Step 21. Print “THANKS FOR USING OUR SERVICE”. Step 22. Stop the program. Let check_pin(): Step 1. Start the program. Step 2. Initialize i is 1 and end is 1. Step 3. Read the value of pin. Step 4. If (pin !=def_pin), then go to step 5, otherwise go to step 6. Step 5. Print “PLEASE ENTER VALID PASSWORD” and goto step7. Step 6. Use break to terminate loop. Step 7. Print “REMAINING ATTEMPTS “ AND VALUE OF 5-i. Step 8. Increment i by 1. Step 9. Repeat step 3 untill i<=5. Step 10. If i==6, then go to step 11, otherwise go to step 13.
  • 37. 37 Step 11. Print “YOUR CARD IS BLOOKED. CONTACT BRAANCH FOR DETAILS. “. Step 12. ASSIGN END IS 0. Step 13. Return the value of end. Step 14. Stop the program. Let withdrawl(unsigned long *withdraw,unsigned long *amount): Step 1. Start the program. Step 2. Read the value of *withdraw. Step 3. If (*withdraw % 100 != 0), then go to step 4, otherwise go to step 5. Step 4. Print “PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100” and go to step 10. Step 5. If (*withdraw >(*amount - 500)), then go to step 6, otherwise go to step 7. Step 6. Print “INSUFFICIENT BALANCE” and go to step 10. Step 7. Subtract *withdraw from *amount and store it in *amount. Step 8. Print “PLEASE COLLECT CASH YOUR CURRENT BALANCE IS Rs.”. Step 9. Print the value of *amount. Step 10. Stop the program. Let add_amount(unsigned long *deposit,unsigned long *amount): Step 1. Start the program. Step 2. Read the value of *deposit. Step 3. Add *amount and *deposit and store it in *amount. Step 4. Print the value of *amount. Step 5. Stop the program. Let change_pin(): Step 1. Start the program. Step 2. Print “ENTER YOUR OLD PIN”. Step 3. Read the value as pin. Step 4. If (pin==def_pin), then go to step 5, otherwise go to step 15. Step 5. Print “ENTER YOUR NEW PIN”. Step 6. Read the value as pin_1. Step 7. Print “ENTER YOUR NEW PIN”. Step 8. Read the value as pin_2. Step 9. If (pin_1==pin_2),then goto step 10, otherwise goto step 11. Step 10. Assign pin_1 in def_pin and go to step 12. Step 11. Assign pin in def_pin. Step 12. If (def_pin==pin_1), then go to step 13, otherwise go to step 14. Step 13. Print “YOUR PIN IS UPDATED” and go to step 17.
  • 38. 38 Step 14. Print “PIN MISMATCH” and go to step 17. Step 15. Print “PLEASE ENTER YOUR OLD PIN CORRECTLY”. Step 16. Call change_pin(). Step 17. Stop the program. Algorithm D: CONDITIONAL GOTO Step 1. Start the program. Step 2. Read the percentage of battery. Step 3. If (battery<=15), then go to step 4, otherwise go to step 5. Step 4. Goto level(step no:7 ). Step 5. Print (“Battery Saver is OFF”). Step 6. Return the value 0 (i.e. go to step no : 8). Step 7. Level: Print (“Battery Saver is ON”). Step 8. Stop the program. Algorithm E: UNCONDITIONAL GOTO Step 1. Start the program. Step 2. Declare val as char. Step 3. Read the value of val as lowercase letter from the user. Step 4. Goto check: Step 5. Print “These lines are not executed”. Step 6. Print “These lines are skipped”. Step 7. Check: Print the value using toupper(val). Step 8. Stop the program.
  • 41. 41
  • 49. 49 C program: Program A: IF ELSE #include<stdio.h> int main() { int amount,copy; float rate; printf("nENTER NUMBER OF COPIES OF XEROX : "); scanf("%d",&copy); if (copy<=100) rate=1; else rate=0.6; amount=copy*rate; printf("nnThe amount you have to pay is %d",amount); return 0; } Program B: ELSE IF #include<stdio.h>//fees calculating program int main() { short days,copy; int reg_fee,copy_fee,CD_fee=100,total_fees; printf("ntt TAMIL NADU MARRIAGE REGISTRATIONn"); printf("ntEnter how many number of days after your marriage? "); scanf("%hd",&days); printf("ntEnter how many Certified Copies do you want? "); scanf("%hd",&copy); if (days<=90) reg_fee=100; else if(days>90 && days<=150) reg_fee=150; else reg_fee=1150; copy_fee=copy*10; total_fees=reg_fee+copy_fee+CD_fee; printf("nnttFEES RECEIPTn"); printf("ntRegistration Fees = Rs.%d/-",reg_fee);
  • 50. 50 printf("ntCertified Copy Feest = Rs.%d/-",copy_fee); printf("ntCD Fees = Rs.%d/-",CD_fee); printf("nt t ***************"); printf("ntTotal Fees = Rs.%d/-",total_fees); return 0; } Program C: SWITCH // ATM SERVICES USING SWITCH #include<stdio.h> int check_pin(); void withdrawl(unsigned long *,unsigned long *); void add_amount(unsigned long *,unsigned long *); void change_pin(); unsigned int pin, def_pin=1302; short end; int main() { short choice,k; unsigned long amount=500000,deposit,withdraw; char transaction; end=check_pin(); if (end==0) return 0; do { printf("n********Welcome To ATM Services********"); printf("n1.Check Balance n2.Cash Withdrawln3.Deposit Cashn4.Change Pinn5.Quit nEnter your Choice :"); scanf("%hd",&choice); switch(choice) { case 1: //Balance printf("n YOUR BALANCE IN Rs : %lu/- ", amount); break; case 2: //Withdrawl withdrawl(&withdraw,&amount); break; case 3: //Deposit add_amount(&deposit,&amount); break;
  • 51. 51 case 4: //Change Pin change_pin(); break; case 5: printf("nn THANKS FOR USING OUR ATM SERVICE"); return 0; default: printf("nInvalid Choice..."); } printf("nnn DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): n"); fflush(stdin); scanf("%c", &transaction); k=(transaction == 'n'|| transaction == 'N')?0:1; }while(k); printf("nn THANKS FOR USING OUR ATM SERVICE"); return 0; } //check pin int check_pin() { int i=1; end=1; for (;i<=5;++i) { printf("nENTER YOUR SECRET PIN NUMBER:"); scanf("%u", &pin); if (pin !=def_pin) printf("nPLEASE ENTER VALID PASSWORDn"); else break; printf("nREMAINING ATTEMPTS = %d",5-i); } if (i==6) { printf("nn YOUR CARD IS BLOCKED n CONTACT BRANCH FOR FURTHER DETAILSn THANK YOU"); end=0; }
  • 52. 52 return end; } //Withdrawl function void withdrawl(unsigned long *withdraw,unsigned long *amount) { printf("n ENTER THE AMOUNT TO WITHDRAW: "); scanf("%lu", &*withdraw); if (*withdraw % 100 != 0) printf("n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100"); else if (*withdraw >(*amount - 500)) printf("n INSUFFICENT BALANCE"); else { *amount = *amount - *withdraw; printf("nn PLEASE COLLECT CASH"); printf("n YOUR CURRENT BALANCE IS Rs.%lu/-", *amount); } } //Deposit function void add_amount(unsigned long *deposit,unsigned long *amount) { printf("n ENTER THE AMOUNT TO DEPOSIT Rs."); scanf("%lu", &*deposit); *amount = *amount + *deposit; printf("YOUR BALANCE IS Rs.%lu/-", *amount); } //change pin void change_pin() { int pin_1,pin_2; printf("nENTER YOUR OLD PIN : "); scanf("%u",&pin); if (pin==def_pin) { printf("nENTER YOUR NEW PIN : "); scanf("%d",&pin_1);
  • 53. 53 printf("nRE-ENTER YOUR NEW PIN : "); scanf("%d",&pin_2); def_pin=(pin_1==pin_2)?pin_1:pin; if (def_pin==pin_1) printf("n YOUR PIN IS UPDATED"); else printf("nPIN MISMATCH..."); } else { printf("nPLEASE, ENTER YOUR OLD PIN CORRECTLY"); change_pin(); } } Program D: CONDITIONAL GOTO #include<stdio.h> int main() { int battery; printf("Enter the percentage of your phone : "); scanf("%d",&battery); if (battery<=15) goto level; else printf("nBattery Saver is OFF "); return 0; level: printf("nBattery Saver is ON "); } Program E: UNCONDITIONAL GOTO #include<stdio.h> #include<ctype.h> int main() { char value_1; printf("Enter a lowercase letter : "); scanf("%c",&value_1); goto check; printf("These lines are not executed");
  • 54. 54 printf("These lines are skipped"); check: printf("nnLowercase to Uppercase n %c ->%c" ,value_1, toupper(value_1)); return 0; } Output: Output A(i): IF ELSE ENTER NUMBER OF COPIES OF XEROX : 60 The amount you have to pay is Rs.60 Output A(ii): IF ELSE ENTER NUMBER OF COPIES OF XEROX : 300 The amount you have to pay is Rs.180 Output B(i): ELSE IF TAMIL NADU MARRIAGE REGISTRATION Enter how many number of days after your marriage? 50 Enter how many Certified Copies do you want? 3 FEES RECEIPT Registration Fees = Rs.100/- Certified Copy Fees = Rs.30/- CD Fees = Rs.100/- *************** Total Fees = Rs.230/-
  • 55. 55 Output B(ii): ELSE IF TAMIL NADU MARRIAGE REGISTRATION Enter how many number of days after your marriage? 96 Enter how many Certified Copies do you want? 3 FEES RECEIPT Registration Fees = Rs.150/- Certified Copy Fees = Rs.30/- CD Fees = Rs.100/- *************** Total Fees = Rs.280/- Output B(iii): ELSE IF TAMIL NADU MARRIAGE REGISTRATION Enter how many number of days after your marriage? 250 Enter how many Certified Copies do you want? 3 FEES RECEIPT Registration Fees = Rs.1150/- Certified Copy Fees = Rs.30/- CD Fees = Rs.100/- *************** Total Fees = Rs.1280/-
  • 56. 56 Output C(i): SWITCH ENTER YOUR SECRET PIN NUMBER:1302 ********Welcome To ATM Services******** 1.Check Balance 2.Cash Withdrawl 3.Deposit Cash 4.Change Pin 5.Quit Enter your Choice :1 YOUR BALANCE IN Rs : 500000/- DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): y ********Welcome To ATM Services******** 1.Check Balance 2.Cash Withdrawl 3.Deposit Cash 4.Change Pin 5.Quit Enter your Choice :2 ENTER THE AMOUNT TO WITHDRAW: 500 PLEASE COLLECT CASH YOUR CURRENT BALANCE IS Rs.499500/- DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): y ********Welcome To ATM Services******** 1.Check Balance 2.Cash Withdrawl 3.Deposit Cash 4.Change Pin
  • 57. 57 5.Quit Enter your Choice :3 ENTER THE AMOUNT TO DEPOSIT Rs.1000 YOUR BALANCE IS Rs.500500/- DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): y ********Welcome To ATM Services******** 1.Check Balance 2.Cash Withdrawl 3.Deposit Cash 4.Change Pin 5.Quit Enter your Choice :4 ENTER YOUR OLD PIN : 1302 ENTER YOUR NEW PIN : 1756 RE-ENTER YOUR NEW PIN : 1756 YOUR PIN IS UPDATED DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): n THANKS FOR USING OUR ATM SERVICE Output C(ii): SWITCH ENTER YOUR SECRET PIN NUMBER:1756 PLEASE ENTER VALID PASSWORD REMAINING ATTEMPTS = 4 ENTER YOUR SECRET PIN NUMBER:5564
  • 58. 58 PLEASE ENTER VALID PASSWORD REMAINING ATTEMPTS = 3 ENTER YOUR SECRET PIN NUMBER:4589 PLEASE ENTER VALID PASSWORD REMAINING ATTEMPTS = 2 ENTER YOUR SECRET PIN NUMBER:7856 PLEASE ENTER VALID PASSWORD REMAINING ATTEMPTS = 1 ENTER YOUR SECRET PIN NUMBER:7458 PLEASE ENTER VALID PASSWORD REMAINING ATTEMPTS = 0 YOUR CARD IS BLOCKED CONTACT BRANCH FOR FURTHER DETAILS THANK YOU Output C(iii): SWITCH ENTER YOUR SECRET PIN NUMBER:1302 ********Welcome To ATM Services******** 1.Check Balance 2.Cash Withdrawl 3.Deposit Cash 4.Change Pin 5.Quit Enter your Choice :4 ENTER YOUR OLD PIN : 1569 PLEASE, ENTER YOUR OLD PIN CORRECTLY ENTER YOUR OLD PIN : 1302 ENTER YOUR NEW PIN : 1458
  • 59. 59 RE-ENTER YOUR NEW PIN : 1459 PIN MISMATCH... DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): y ********Welcome To ATM Services******** 1.Check Balance 2.Cash Withdrawl 3.Deposit Cash 4.Change Pin 5.Quit Enter your Choice :2 ENTER THE AMOUNT TO WITHDRAW: 5300 PLEASE COLLECT CASH YOUR CURRENT BALANCE IS Rs.494700/- DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): n THANKS FOR USING OUR ATM SERVICE Output D (i): CONDITIONAL GOTO Enter the percentage of your phone : 5 Battery Saver is ON Output D (ii): CONDITIONAL GOTO Enter the percentage of your phone : 55 Battery Saver is OFF
  • 60. 60 Output E (i): UNCONDITIONAL GOTO Enter a lowercase letter : g Lowercase to Uppercase g ->G Output E (ii): UNCONDITIONAL GOTO Enter a lowercase letter : G Lowercase to Uppercase G ->G result: The above code has executed successfully and algorithm and flow chart were drawn.
  • 61. 61 EXP NO : 07 DATE : 05-03-2021 REPETITIVE CONTROL STATEMENTS AIM: To create an algorithm, flowchart and c program for repetitive control statements like ‘for’, ‘while’ and ‘do while’. ALGORITHM: ALGORITHM A (FOR LOOP): Step 1. Start the Program. Step 2. Declare the variables n, count, c and initialize i is 3. Step 3. Read the value of n from the user. Step 4. If (n>=1) is true, then print “First n Prime numbers are : 2”. Step 5. Set the value of count is 2. Step 6. If (count<=n) is true, then go to step 7, otherwise go to step 15. Step 7. Set the value of c is 2. Step 8. If (c<=i-1) is true, then go to step 9, otherwise go to step 12. Step 9. If (i%c==0) is true, then use the break statement to exit. Step 10. Increment the value of c by 1. Step 11. Repeat step 8. Step 12. If (c==i) is true, then print the value of i and and increment the value of count. Step 13. Increment the value of i by 1. Step 14. Repeat step 6. Step 15. End the program. ALGORITHM B (WHILE LOOP): Step 1. Start the Program. Step 2. Declare variables column, max_row and initialize row is 1. Step 3. Read the value of max_row. Step 4. Print “ASCENDING ORDER”. Step 5. If (row<=max_row), then go to step 6, otherwise go to step 14. Step 6. Set the value of column is 1. Step 7. If (column<=row) is true then go to step 8, otherwise go to step 11. Step 8. Print the character of ‘A’+(coloumn-1). Step 9. Increment the value of column by 1. Step 10. Repeat the step 7. Step 11. Increment the value of row by 1. Step 12. Print the new line.
  • 62. 62 Step 13. Repeat step 5. Step 14. Print “DESCENDING ORDER”. Step 15. If (row<=max_row), then go to step 16, otherwise go to step 24. Step 16. Set the value of column is 1. Step 17. If (column<=row) is true then go to step 18, otherwise go to step 21. Step 18. Print the character of ‘A’+(row-column). Step 19. Increment the value of column by 1. Step 20. Repeat the step 17. Step 21. Increment the value of row by 1. Step 22. Print the new line. Step 23. Repeat step 15. Step 24. End the Program. ALGORITHM C (DO WHILE LOOP): Step 1. Start the program. Step 2. Declare variables year as integer, k as integer, choice as character. Step 3. Read the value of year from user. Step 4. If (year%4==0 && year%100!=0 ||year%400==0) is true, then print “It is a leap year”, otherwise print “It is not a leap year”. Step 5. Print “Do you wish to check another year?(y/n)”. Step 6. Read the value of choice from user. Step 7. If (choice == 'n'|| choice == 'N') is true, then assign k is 0, otherwise k is 1. Step 8. Repeat the step 3 if (k==1). Step 9. End the program.
  • 65. 65
  • 66. 66 FLOWCHART C (DO WHILE LOOP):
  • 67. 67 PROGRAM: PROGRAM A (FOR LOOP): //Program to find Prime numbers #include<stdio.h> int main() { int n, i = 3, count, c; printf("Enter the number of prime numbers to printn"); scanf("%d", &n); if (n >= 1) printf("First %d prime numbers are:n2n",n); for (count = 2; count <= n;) { for (c = 2; c<= i-1; c++) { if (i%c == 0) break; } if (c == i) { printf("%dn", i); count++; } i++; } return 0; } PROGRAM B (WHILE LOOP): //Program to print the pattern of Alphabets by entering number of rows #include<stdio.h> int main() { int row=1,coloumn,max_row; printf("nEnter how many number of rows?"); scanf("%d",&max_row); printf("nAscending Ordern"); while (row<=max_row) {
  • 68. 68 coloumn=1; while (coloumn<=row) { printf("%c",'A'+(coloumn-1)); coloumn++; } ++row; printf("n"); } printf("nDescending Ordern"); row=1; while (row<=max_row) { coloumn=1; while (coloumn<=row) { printf("%c",'A'+(row-coloumn)); coloumn++; } ++row; printf("n"); } return 0; } PROGRAM C (DO WHILE LOOP): //Program to find whether it is a leap year or not #include<stdio.h> int main() { int year,k; char choice; do { printf("nEnter the year : "); scanf("%d",&year); if (year%4==0 && year%100!=0 ||year%400==0) printf("n%d is a leap year",year); else printf("n%d is a not leap year",year); printf("nnn DO U WISH TO CHECK ANOTHER YEAR?(y/n): n");
  • 69. 69 fflush(stdin); scanf("%c", &choice); k=(choice == 'n'|| choice == 'N')?0:1; }while(k); return 0; } OUTPUT: OUTPUT A (FOR LOOP): Enter the number of prime numbers to print 10 First 10 prime numbers are: 2 3 5 7 11 13 17 19 23 29 OUTPUT B (WHILE LOOP): Enter how many number of rows?6 Ascending Order A AB ABC ABCD ABCDE ABCDEF Descending Order A BA CBA DCBA EDCBA FEDCBA
  • 70. 70 OUTPUT C (DO WHILE LOOP): Enter the year : 2020 2020 is a leap year DO U WISH TO CHECK ANOTHER YEAR?(y/n): y Enter the year : 1600 1600 is a leap year DO U WISH TO CHECK ANOTHER YEAR?(y/n): y Enter the year : 1800 1800 is a not leap year DO U WISH TO CHECK ANOTHER YEAR?(y/n): n RESULT: Above code has executed successfully.
  • 71. 71 EXP NO : 08 DATE : 05-03-2021 ONE-DIMENSIONAL AND TWO-DIMENSIONAL ARRAY AIM: To create an algorithm and program for one-dimensional and two-dimensional array. ALGORITHM: Algorithm A (One-Dimensional Array): Step 1. Start the program. Step 2. Declare num[10] and initialize i is 0,even is 0 and odd is 0. Step 3. If (i<10) is true then go to step 4, otherwise go to step 8. Step 4. Read the value of num[i]. Step 5. If (num[i]%2==0) is true, the increment the value of even by 1, otherwise increment the value of odd by 1. Step 6. Increment the value of i by 1. Step 7. Repeat the step 3. Step 8. Print the value of odd and even. Step 9. End the program. Algorithm B (Two-Dimensional Array): Step 1. Start the program. Step 2. Declaring i,j,k,result[10][10], a[10][10], b[10][10] as global variable. Step 3. Declare row1, row2, column1 and column2. Step 4. Read the values of row1 and column1. Step 5. Call the function with passing arguments get_Matrix_Elements(a,row1,coloumn1). Step 6. Read the values of row2 and column2. Step 7. Call the function with passing arguments get_Matrix_Elements(b,row2,coloumn2). Step 8. If (row1==row2 && coloumn1==coloumn2) is true, then go to step 9, otherwise go to step 13. Step 9. Print “Sum of two matrices”. Step 10. Calls the functions with passing arguments find (row1, column1, 11). Step 11. Print “Difference of two matrices”. Step 12. Call the function with passing arguments find (row1, column1, 12) and go to step 14. Step 13. Print “Addition and subtraction is not possible for this order”. Step 14. If (coloumn1==row2) is true, then go to step 15, otherwise go to step 17. Step 15. Print “Multiplication of two matrices:”.
  • 72. 72 Step 16. Call the function with passing arguments a. find(row1,coloumn2,coloumn1); b. find(row1,coloumn2,13); and go to step 18. Step 17. Print “Multiplication is not possible”. Step 18. Print “Matrix A”. Step 19. Call the function with passing arguments find(row1,coloumn1,14);. Step 20. Print “Transpose of A”. Step 21. Call the function with passing arguments a. find(row1,coloumn1,15); b. find(coloumn1,row1,13); Step 22. Print “matrix B”. Step 23. Call the function with passing arguments find(row2,coloumn2,16);. Step 24. Print “Transpose of B”. Step 25. Call the function with passing arguments a. find(row2,coloumn2,17); b. find(coloumn2,row2,13); Step 26. End the program. void get_Matrix_Elements(int matrix[][10], int row, int coloumn) : Step 1. Start the program. Step 2. Print “Enter elements of matrix”. Step 3. Set the value of i is 0. Step 4. If (i<row) is true, then go to step 5, otherwise go to step 12. Step 5. Set the value of j is 0. Step 6. If (j<column) is true, then go to step 7, otherwise go to step 10. Step 7. Read the value of matrix[i][j]. Step 8. Increment the value of j by 1. Step 9. Repeat the step 6. Step 10. Increment the value of i by 1. Step 11. Repeat the step 4. Step 12. End the program. void find(int row,int column,int n): Step 1. Start the program. Step 2. Set the value of i is 0. Step 3. If (i<row) is true, then go to step 4, otherwise go to step 31. Step 4. Set the value of j is 0. Step 5. If (j<column) is true, then go to step 6, otherwise go to step 28. Step 6. If (n==11) is true, then go to step 7, otherwise go to step 8. Step 7. Print (a[i][j] + b[i][j]) and go to step 26.
  • 73. 73 Step 8. If (n==12) is true, then go to step 9, otherwise go to step 10. Step 9. Print (a[i][j] - b[i][j]) and go to step 26. Step 10. If (n==13) is true, then go to step 11,otherwise go to step 12. Step 11. Print (result[i][j]) and go to step 26. Step 12. If (n==14) is true, then go to step 13,otherwise go to step 14. Step 13. Print (a[i][j]) and go to step 26. Step 14. If (n==15) is true, then go to step 15,otherwise go to step 16. Step 15. Assign Result[j][i] is equal to a[i][j] and go to step 26. Step 16. If (n==16) is true, then go to step 17,otherwise go to step 18. Step 17. Print (b[i][j]) and go to step 26. Step 18. If (n==17) is true, then go to step 19,otherwise go to step 20. Step 19. Assign Result[j][i] is equal to b[i][j] and go to step 26. Step 20. Set the value of k is 0. Step 21. If (k<n) is true, then go to step 22, otherwise go to step 26. Step 22. Multiply a[i][k] and b[k][j], and add result[i][j]. Step 23. Store the result in result[i][j]. Step 24. Increment the value of k by 1. Step 25. Repeat the step 21. Step 26. Increment the value of j by 1. Step 27. Repeat the step 5. Step 28. Print new line. Step 29. Increment the value of i by 1. Step 30. Repeat the step 3. Step 31. End the program. PROGRAM: Program A (One-Dimensional Array): //Program to find how many even and odd numbers of 10 numbers #include<stdio.h> int main() { int num[10],even=0,odd=0,i; for(i=0;i<10;i++) { printf("nEnter number %d : ",i+1); scanf("%d",&num[i]); if (num[i]%2==0) ++even; else ++odd;
  • 74. 74 } printf("n There are %d Even Numbers",even); printf("n There are %d Odd Numbers",odd); return 0; } Program B (Two-Dimensional Array): #include <stdio.h> void get_Matrix_Elements(int matrix[][10], int row, int column); void find(int row,int coloumn,int n); int i,j,k,result[10][10], a[10][10], b[10][10]; int main() { int row1,row2,coloumn2,coloumn1; printf("Enter rows and column for the first matrix: "); scanf("%d %d", &row1, &coloumn1); get_Matrix_Elements(a,row1,coloumn1);//Elements of 1st matrix printf("Enter rows and column for the second matrix: "); scanf("%d %d", &row2, &coloumn2); get_Matrix_Elements(b,row2,coloumn2);//Elements of 2nd matrix if (row1==row2 && coloumn1==coloumn2) { printf("nSum of two matrices: n"); find(row1,coloumn1,11); printf("nDifference of two matrices: n"); find(row1,coloumn1,12); } else printf("nAddition and Subtraction is not possible for this ordern"); if (coloumn1==row2) { printf("nMultiplication of two matrices: n"); find(row1,coloumn2,coloumn1); find(row1,coloumn2,13); } else printf("nMultiplication is not possiblen"); printf("nMatrix A:n"); find(row1,coloumn1,14); printf("nTranspose of A:n"); find(row1,coloumn1,15);
  • 75. 75 find(coloumn1,row1,13); printf("nMatrix B:n"); find(row2,coloumn2,16); printf("nTranspose of B:n"); find(row2,coloumn2,17); find(coloumn2,row2,13); return 0; } void get_Matrix_Elements(int matrix[][10], int row, int coloumn) { printf("nEnter elements of matrix:n"); for (i = 0; i<row; ++i) { for (j = 0; j<coloumn; ++j) { printf("Enter element a%d%d: ", i+1, j+1); scanf("%d", &matrix[i][j]); } } } void find(int row,int coloumn,int n) { for (i = 0; i<row; ++i) { for (j = 0; j<coloumn; ++j) { switch(n) { case 11: printf("%d ", a[i][j] + b[i][j]);//ADD break; case 12: printf("%d ", a[i][j] - b[i][j]);//SUB break; case 13: printf("%d ", result[i][j]);//Display break; case 14: printf("%d ", a[i][j]);//Matrix A break;
  • 76. 76 case 15: result[j][i]=a[i][j];//Transpose A break; case 16: printf("%d ", b[i][j]);//Matrix B break; case 17: result[j][i]=b[i][j];//Transpose B break; default: for(k=0;k<n;k++) result[i][j]+=a[i][k]*b[k][j];//Multiplication } } printf("n"); } } OUTPUT: Output A (One-Dimensional Array): Enter number 1 : 1 Enter number 2 : 2 Enter number 3 : 3 Enter number 4 : 4 Enter number 5 : 5 Enter number 6 : 6 Enter number 7 : 7 Enter number 8 : 8 Enter number 9 : 9 Enter number 10 : 10
  • 77. 77 There are 5 Even Numbers There are 5 Odd Numbers Output B (Two-Dimensional Array) (i): Enter rows and column for the first matrix: 2 2 Enter elements of matrix: Enter element a11: 3 Enter element a12: 3 Enter element a21: 3 Enter element a22: 3 Enter rows and column for the second matrix: 2 2 Enter elements of matrix: Enter element a11: 3 Enter element a12: 3 Enter element a21: 3 Enter element a22: 3 Sum of two matrices: 6 6 6 6 Difference of two matrices: 0 0 0 0 Multiplication of two matrices: 18 18 18 18 Matrix A: 3 3 3 3 Transpose of A:
  • 78. 78 3 3 3 3 Matrix B: 3 3 3 3 Transpose of B: 3 3 3 3 Output B (Two-Dimensional Array) (ii): Enter rows and column for the first matrix: 2 3 Enter elements of matrix: Enter element a11: 2 Enter element a12: 3 Enter element a13: 4 Enter element a21: 5 Enter element a22: 6 Enter element a23: 6 Enter rows and column for the second matrix: 3 2 Enter elements of matrix: Enter element a11: 2 Enter element a12: 2 Enter element a21: 2 Enter element a22: 5 Enter element a31: 6 Enter element a32: 8 Addition and Subtraction is not possible for this order Multiplication of two matrices:
  • 79. 79 34 51 58 88 Matrix A: 2 3 4 5 6 6 Transpose of A: 2 5 3 6 4 6 Matrix B: 2 2 2 5 6 8 Transpose of B: 2 2 6 2 5 8 Output B (Two-Dimensional Array) (iii): Enter rows and column for the first matrix: 2 3 Enter elements of matrix: Enter element a11: 1 Enter element a12: 2 Enter element a13: 3 Enter element a21: 4 Enter element a22: 5 Enter element a23: 6 Enter rows and column for the second matrix: 2 2
  • 80. 80 Enter elements of matrix: Enter element a11: 1 Enter element a12: 2 Enter element a21: 3 Enter element a22: 4 Addition and Subtraction is not possible for this order Multiplication is not possible Matrix A: 1 2 3 4 5 6 Transpose of A: 1 4 2 5 3 6 Matrix B: 1 2 3 4 Transpose of B: 1 3 2 4 RESULT: Above code has executed successfully.
  • 81. 81 EXP-NO : 09 DATE : 05-03-2021 MODULAR PROGRAMMING CONCEPTS AIM: To create an algorithm and program for built-in functions and user defined functions. ALGORITHM: ALGORITHM A (BUILT-IN FUNCTIONS): Step 1. Start the program. Step 2. Declare ceo[25] as char and len as int and initialize mn is 16 as double. Step 3. Initialize str[]=”cprogram”, cho[]=”open” and c=’s’. Step 4. Copy the str to ceo using strcpy() function. Step 5. Print the value of str and ceo. Step 6. Calculate string length using strlen() for ceo and store it in len. Step 7. Print the value of len. Step 8. Concatenate the two strings using strcat() to join cho and str. Step 9. Print the string cho. Step 10. Compare two strings using strcmp() of str and ceo and store it in len. Step 11. Print the value of len. Step 12. Print uppercase letter of variable c using toupper() function. Step 13. Print the lowercase letter of variable c using tolower() function. Step 14. Using sqrt() function, print the square root of mn variable. Step 15. End the program. ALGORITHM B (USER DEFINED FUNCTIONS): Step 1. Start the program. Step 2. Declare name[25][25], age[25], salary[25]as global variable. Step 3. Declare the variable named number. Step 4. Read the value of number. Step 5. Call get_detail() function with passing number. Step 6. Call display() function with passing number. Step 7. End the program. int get_details(int number); Step 1. Start the program. Step 2. Initialize i is 0. Step 3. If (i<number) is true, then go to step 4, otherwise go to step 7. Step 4. Read the value of name[i], age[i] and salary[i]. Step 5. Increment the value of i by 1. Step 6. Repeat the step 3.
  • 82. 82 Step 7. End the program. void display (int number) Step 1. Start the program. Step 2. Initialize i is 0. Step 3. Print “Name Age Salary Annual_income” with horizontal space. Step 4. If (i<number) is true, then go to step 5, otherwise go to step 7. Step 5. Print the value of name[i], age[i], salary[i] and (salary[i])*12. Step 6. Repeat the step 4. Step 7. End the program. PROGRAM: PROGRAM A (BUILT-IN FUNCTIONS): #include<stdio.h> #include<string.h> #include<math.h> int main() { char str[]="cprogram",ceo[25],cho[]="open",c='s'; int len; double mn=16; strcpy(ceo,str); printf("Original string : %s",str); printf("nCopied String :%s",ceo); len=strlen(ceo); printf("nLength of copied string : %d",len); strcat(cho,str); printf("nConcatenated String : %s",cho); len=strcmp(str,ceo); printf("nCompare string : %d",len); printf("nvariable c to uppercase :%c",toupper(c)); printf("nvariable c to lowercase :%c",tolower(c)); printf("nSquareroot of mn : %.2lf",sqrt(mn)); return 0; } PROGRAM B (USER DEFINED FUNCTIONS): #include<stdio.h> int get_details(int number); void display(int number); char name[25][25];
  • 83. 83 short age[25]; double salary[25]; int main() { short number; printf("Enter how many persons : "); scanf("%hd",&number); get_details(number); display(number); } int get_details(int number) { int i=0; for(;i<number;i++) { printf("nEnter name of %d person : ",i+1); scanf("%s",name[i]); printf("nEnter the age : "); scanf("%hd",&age[i]); printf("nEnter the salary : "); scanf("%lf",&salary[i]); } } void display (int number) { int i=0; printf("nNametAgetSalaryttAnnual_Income"); for(;i<number;i++) { printf("n%st %hdt %lft %lf",name[i],age[i],salary[i],salary[i]*12); } } OUTPUT: OUTPUT A (BUILT-IN FUNCTIONS): Original string : cprogram Copied String :cprogram Length of copied string : 8 Concatenated String : opencprogram Compare string : 0
  • 84. 84 variable c to uppercase :S variable c to lowercase :s Squareroot of mn : 4.00 OUTPUT B (USER DEFINED FUNCTIONS): Enter how many persons : 4 Enter name of 1 person : Ram Enter the age : 23 Enter the salary : 20000 Enter name of 2 person : Ravi Enter the age : 32 Enter the salary : 29565 Enter name of 3 person : Raju Enter the age : 31 Enter the salary : 65000 Enter name of 4 person : Ragu Enter the age : 26 Enter the salary : 85500 Name Age Salary Annual_Income Ram 23 20000.000000 240000.000000 Ravi 32 29565.000000 354780.000000 Raju 31 65000.000000 780000.000000 Ragu 26 85500.000000 1026000.000000 RESULT: Above code has executed successfully.
  • 85. 85 EX.NO : 10 DATE : 12-03-2021 CHARACTER - STRING OPERATIONS WITH AND WITHOUT BUILT-IN FUNCTIONS AIM: To create a algorithm, program and output for character and string operations with and without built-in library functions. ALGORITHM: Step 1. Start the program. Step 2. Declare the char variable chr with value ‘s’ and also declare pointer variable *p with value as “CHATUS”. Step 3. Read the value of str1 and str2. Step 4. Print to output screen “Using Built in Functions”. Step 5. Copy the str1 and str2 to ceo and cto respectively using strlen() function. Step 6. Print the value of str1 and ceo as original string and copied string. Step 7. Using strlen() function, find length of string of ceo and store it in len. Step 8. Print the value of len. Step 9. Join the strings str1 and str2 using strcat() function. Step 10. Print the value of str1. Step 11. Compare two strings str1 and str2, using strcmp() function and store result in len. Step 12. Print the value of len. Step 13. Convert a lowercase to uppercase for a character using toupper() function for chr. Step 14. Print the value of chr. Step 15. Convert a uppercase to lowercase for a character using tolower() function for chr. Step 16. Print the value of chr. Step 17. Print to output screen “Without Using Built in Functions”. Step 18. Call the function str_cpy(user1,ceo) and pass the values of user1 and ceo. Go to step 34. Step 19. Call the function str_cpy(user2,cto) and pass the values of user2 and cto. Go to step 34. Step 20. Print the value of ceo and user1. Step 21. Call the function str_len(user1) and pass the value of user1. Go to step 39. Step 22. Store the returned value in len. Step 23. Print the valu of len. Step 24. Call the function str_cat(user1,p) and pass the values of user1 and p. Go to step 42.
  • 86. 86 Step 25. Print the value of user1. Step 26. Call the function str_cmp(user2,cto) and pass the values of user2 and cto. Go to step 45. Step 27. Store the returned value in len. Step 28. Print the value of len. Step 29. Call the function to_upper(chr) and pass the values of chr. Go to step 49. Step 30. Print the value of chr. Step 31. Call the function to_lower(chr) and pass the values of chr. Go to step 52. Step 32. Print the value of chr. Step 33. End the program. Step 34. Declare i is 0. Step 35. If (ceo[i]!='0') is true, then go to step 36, otherwise go to step 38. Step 36. Assign user[i] equals to ceo[i]. Step 37. Increment the value of i and repeat the step 35. Step 38. Assign user[i] equals to ‘0’ and go to next step of calling function (here end of str_cpy() function). Step 39. Declare a is 0. Step 40. If (user[a]!='0') is true, then increment the value of a, otherwise return a. Step 41. Repeat step 40, until condition fails and go to next step of calling function (here end of str_len() function). Step 42. Declare i and j is 0 and set i is equals to str_len(user1) (i.e., go to step 39). Step 43. If (ceo[j]!='0') is true, then assign user[i] is equal to ceo[j] and increment value of i and j, otherwise set user[i] is ‘0’. Step 44. Repeat step 43, until the condition fails and go to next step of calling function (here end of str_cat() function). Step 45. Declare i is 0. Step 46. If (str1[i]==str2[i] && str1[i]=='0') is true, then increment the value of i. Step 47. Repeat step 46 untill condition fails. Step 48. If (str1[i]==str2[i]) is true, then return 0, otherwise return 1 and go to next step of calling function (here end of str_cmp() function). Step 49. If (c>=97 && c<=122) is true, then do the following steps, otherwise go to step 51. Step 50. Subtract 32 from c and store it in c. Step 51. Go to next step of calling function (here end of to_upper() function). Step 52. If (c>=65 && c<=90) is true, then do the following steps, otherwise go to step 51. Step 53. Add 32 with c and store it in c. Step 54. Go to next step of calling function (here end of to_lower() function).
  • 87. 87 PROGRAM: #include<stdio.h> #include<string.h> #include<ctype.h> void str_cpy(char user1[],char ceo[]); void str_cat(char user1[],char ceo[]); int str_len(char user[]); int str_cmp(char str1[], char str2[]); int to_upper(char c); int to_lower(char c); int main() { char str1[25],str2[25],ceo[25],cto[25],user1[25],user2[25],chr='s'; char *p="CHATUS"; int len,i; printf("nEnter string 1 : "); scanf("%s",str1); printf("nEnter String 2 : "); scanf("%s",str2); printf("nntUsing Built In Functionsn "); //using buil-in functions strcpy(ceo,str1); strcpy(cto,str2); printf("nnOriginal string 1: %s",str1); printf("nCopied String of 1 :%s",ceo); len=strlen(ceo); printf("nLength of copied string : %d",len); strcat(str1,str2); printf("nConcatenated String : %s",str1); len=strcmp(str2,cto); printf("nCompare string : %d",len); printf("nvariable chr to uppercase :%c",toupper(chr)); printf("nvariable chr to lowercase :%c",tolower(chr)); printf("nntWithout Built In Functions n");//not using buil-in functions str_cpy(user1,ceo); str_cpy(user2,cto); printf("nnOriginal string : %s",ceo); printf("nCopied String :%s",user1); len=str_len(user1); printf("nLength of copied string : %d",len);
  • 88. 88 str_cat(user1,p); printf("nConcatenated String : %s",user1); len=str_cmp(user2,cto); printf("nCompare string : %d",len); printf("nvariable chr to uppercase :%c",to_upper(chr)); printf("nvariable chr to lowercase :%c",to_lower(chr)); } int to_upper(char c) { if (c>=97 && c<=122) c=c-32; } int to_lower(char c) { if (c>=65 && c<=90) c=c+32; } int str_cmp(char str1[], char str2[]) { int i; for (i=0;str1[i]==str2[i] && str1[i]=='0';++i); if (str1[i]==str2[i]) return 0; else return 1; } void str_cat(char user1[],char ceo[]) { int i,j; i=str_len(user1); for (j=0; ceo[j]!='0';++j,++i) user1[i]=ceo[j]; user1[i]='0'; } int str_len(char user[]) { int a=0; for (;user[a]!='0';++a); return a; }
  • 89. 89 void str_cpy(char user1[],char ceo[]) { int i=0; for(;ceo[i]!='0';i++) user1[i]=ceo[i]; user1[i]='0'; } OUTPUT: Enter string 1 : Whatsapp Enter String 2 : Instagram Using Built In Functions Original string 1: Whatsapp Copied String of 1 :Whatsapp Length of copied string : 8 Concatenated String : WhatsappInstagram Compare string : 0 variable chr to uppercase :S variable chr to lowercase :s Without Built In Functions Original string : Whatsapp Copied String :Whatsapp Length of copied string : 8 Concatenated String : WhatsappCHATUS Compare string : 0 variable chr to uppercase :S variable chr to lowercase :s RESULT: Thus, the above code has executed successfully.
  • 90. 90 EX.NO: 11 DATE : 12-03-2021 USE OF POINTERS AIM: To create a algorithm, program and output to illustrate the use of pointers. ALGORITHM: Step 1. Start the program. Step 2. Initialize petrol is 86.3 and diesel is 70.2. Step 3. Print to output screen “Before Passing values”. Step 4. Print the value of petrol and diesel. Step 5. Call the change(&petrol,&diesel) function and pass the addresses of petrol and diesel and go to step 9. Step 6. Print to output screen “After Passing values”. Step 7. Print the value of petrol and diesel. Step 8. End the program. Step 9. Declare the pointer variables petrol and diesel. Step 10. Add 13.5 to the *petrol. Step 11. Add 15.7 to the *diesel. Step 12. End of the change() function. PROGRAM: #include<stdio.h> void change(float *petrol, float *diesel); int main() { float petrol=86.3,diesel=70.2; printf("nBefore Passing values "); printf("nPetrol Price = Rs.%.2f/-",petrol); printf("nDiesel Price = Rs.%.2f/-",diesel); //Passing address of petrol and diesel change(&petrol,&diesel); printf("nAfter Passing values ");
  • 91. 91 printf("nPetrol Price = Rs.%.2f/-",petrol); printf("nDiesel Price = Rs.%.2f/-",diesel); return 0; } void change(float *petrol, float *diesel) { //Increment the value of Petrol *petrol=*petrol+13.5; //Increment the value of diesel *diesel=*diesel+15.7; } OUTPUT: Before Passing values Petrol Price = Rs.86.30/- Diesel Price = Rs.70.20/- After Passing values Petrol Price = Rs.99.80/- Diesel Price = Rs.85.90/- RESULT: Thus the above code has executed successfully.
  • 92. 92 EX.NO : 12 DATE : 12-03-2021 USE OF USER DEFINED DATA TYPES AIM: To create an algorithm, program and output for the user defined data types. ALGORITHM: ALGORITHM A : STRUCTURE Step 1. Start the program. Step 2. Create a structure date which has the following members. Step 3. Day,month,year of type unsigned integer and end of structure date. Step 4. Create a structure student which has the following members. Step 5. Rollno[10] and name[30]] as a type of char and cutoff of float and age as short. Step 6. Create a structure variable for structure date as dob. Step 7. End of the structure student with variable a[50]. Step 8. Read the value of n as how many number of students. Step 9. Initialize i is 0. Step 10. If (i<n) is true, do the following steps, otherwise go to step 15. Step 11. Read the value of a[i].roll_no, a[i].name, a[i].age and a[i].cut_off. Step 12. Call the function date_of_birth(i) and pass the value of i. go to step 20. Step 13. Increment the value of i. Step 14. Repeat step 10. Step 15. Print to output screen” nnROLL_NO tNAME ttDATE-OF-BIRTH tAGE tCUTT-OFFn”. Step 16. Set i is 0. Step 17. If (i<n) is true, do the following steps, otherwise go to step 19. Step 18. Print the values of a[i].roll_no,a[i].name,a[i].dob.day,a[i].dob.month,a[i].dob.year,a[i].age,a[i].cut_off with horizontal spaces. Repeat step 17. Step 19. End the program. Step 20. Declare date, year and month. Step 21. Read the values of a[i].dob.day, a[i].dob.month, a[i].dob.year. Step 22. Assign year is a[i].dob.year, month is a[i].dob.month and date as a[i].dob.day. Step 23. If (year>1970 && year<=2021), then do following steps, otherwise go to step 27. Step 24. If (year%4==0 && year%100!=0 ||year%400==0), then do the step 25, otherwise do step 26.
  • 93. 93 Step 25. Call CHECK(date,month,i,1) function by passing values of date, month and i and 1(go to step 29). After executing, go to step 28. Step 26. Call CHECK(date,month,i,1) function by passing values of date, month and i and 2(go to step 29). After executing, go to step 28. Step 27. Print “Invalid Year” and call the function date_of_birth(i) (i.e., go to step 20). Step 28. End of date_of_birth(i) function. Step 29. If (month==1 || month==3 || month==5 || month==7 || month==8 ||month==10 || month==12) is true, then go to step 30, otherwise go to step 31. Step 30. Assign month is 1 and go to step 33. Step 31. If (month==4 || month==6 || month==9 || month==11) is true, then go to step 32, otherwise go to step 33. Step 32. Assign month is 3. Step 33. If (month==1), then do following steps, otherwise go to step 37. Step 34. If (!(day>0 && day<=31)) is true, then do following, otherwise go to step 51. Step 35. Print “Invalid Date”. Step 36. Call date_of_birth(i) function (i.e., go to step 20). Step 37. If (month==2), then do following steps, otherwise go to step 45. Step 38. If (j==1) is true, then do following steps, otherwise go to step 42. Step 39. If (!(day>0 && day<=29)) is true, then do following, otherwise go to step 51. Step 40. Print “Invalid Date”. Step 41. Call date_of_birth(i) function (i.e., go to step 20). Step 42. If (!(day>0 && day<=28)) is true, then do following, otherwise go to step 51. Step 43. Print “Invalid Date”. Step 44. Call date_of_birth(i) function (i.e., go to step 20). Step 45. If (month==3) is true, then do following, otherwise go to step 49. Step 46. If (!(day>0 && day<=29)) is true, then do following, otherwise go to step 51. Step 47. Print “Invalid Date”. Step 48. Call date_of_birth(i) function (i.e., go to step 20). Step 49. Print “Invalid month”. Step 50. Call date_of_birth(i) function (i.e., go to step 20). Step 51. End of CHECK () function. ALGORITHM B : UNION Step 1. Start the program. Step 2. Declare the union name as view with members val_1 as integer, val_2 as float and val_3[30] as char. Step 3. End the union with variable name data. Step 4. Print “Assigning and printing the union data one by one”. Step 5. Assign data.val_1 as 512. Step 6. Print the value of val_1.
  • 94. 94 Step 7. Assign data.val_1 as 12.56. Step 8. Print the value of val_2. Step 9. Use strcpy() function to copy “HelloC” to data.val_3. Step 10. Print the value of val_3. Step 11. Print “Try to print the value of val_1 and val_2”. Step 12. Print the value of val_1. Step 13. Print the value of val_2. Step 14. Print “Printing the lastly stored value”. Step 15. Print the value of val_3. Step 16. End of the program. ALGORITHM C : ENUMERATED TYPE Step 1. Start the program. Step 2. Create an enum channel_no with sun, vijay equals 6, ktv, zee equals 9, vasanth ,hdmusic. Step 3. Print channel no of sun. Step 4. Print channel no of vijay. Step 5. Print channel no of ktv. Step 6. Print channel no of zee. Step 7. Print channel no of vasanth. Step 8. Print channel no of hdmusic. Step 9. End the program. ALGORITHM D : TYPEDEF Step 1. Start the program. Step 2. Using typedef, long long int as NUM. Step 3. Initialize aadhar_num[50],phone_num[50] as type NUM. Step 4. Declare i and n. Step 5. Read the value of n. Step 6. Set i is 0. Step 7. If (i<n) is true, then go to step 8, otherwise go to step 11. Step 8. Read the value of aadhar_num[i],phone_num[i]. Step 9. Increment the value of i by 1. Step 10. Repeat the step 7. Step 11. Print “Entered Details : “. Step 12. Print “S.no AadharNumber PhoneNumber” with horizontal spaces. Step 13. Set i is 0. Step 14. If (i<n) is true, then go to step 15, otherwise go to step 18. Step 15. Print the value of aadhar_num[i],phone_num[i]. Step 16. Increment the value of i by 1.
  • 95. 95 Step 17. Repeat step 14. Step 18. End the program. PROGRAM: PROGRAM A : STRUCTURE #include<stdio.h> void date_of_birth(short i); void CHECK(int day,int month,short i,int j); struct date { unsigned int day; unsigned int month; unsigned int year; }; struct Student { char roll_no[10],name[30]; float cut_off; short age; struct date dob; }a[50]; int main() { short i,n; printf("nEnter how many number of students (Max:50) : "); scanf("%hd",&n); for (i=0;i<n;i++) { printf("nEnter Roll Number of student %hd : ",i+1); scanf("%s",&a[i].roll_no); printf("nEnter Name of student %hd : ",i+1); scanf("%s",a[i].name); date_of_birth(i); printf("nEnter Age of student %hd : ",i+1); scanf("%hd",&a[i].age); printf("nEnter Cutt-Off of student %hd : ",i+1); scanf("%f",&a[i].cut_off); } printf("nnROLL_NO tNAME ttDATE-OF-BIRTH tAGE tCUTT-OFFn"); for (i=0;i<n;i++)
  • 96. 96 { printf("n%s t%s tt%u-%u-%u t%hd t%.2f",a[i].roll_no,a[i].name,a[i].dob.day,a[i].dob.month,a[i].dob.year,a[i].age,a[i].cut_off); } return 0; } void date_of_birth(short i) { int date,year,month; printf("nEnter Date of birth of student %hd (dd/mm/yy) n(year must greater than 1970 and less than or equal to 2021)n : ",i+1); scanf("%u %u %u",&a[i].dob.day,&a[i].dob.month,&a[i].dob.year); year=a[i].dob.year; month=a[i].dob.month; date=a[i].dob.day; if (year>1970 && year<=2021) { if (year%4==0 && year%100!=0 ||year%400==0) CHECK(date,month,i,1); else CHECK(date,month,i,2); } else { printf("nINVALID YEAR t TRY AGAIN"); date_of_birth(i); } } void CHECK(int day,int month,short i,int j) { if (month==1 || month==3 || month==5 || month==7 || month==8 ||month==10 || month==12) month=1; else if (month==4 || month==6 || month==9 || month==11) month=3; switch(month) { case 1: if (!(day>0 && day<=31)) {
  • 97. 97 printf("nINVALID DATE t TRY AGAIN"); date_of_birth(i); } break; case 2: if (j==1) { if (!(day>0 && day<=29)) { printf("nINVALID DATE t TRY AGAIN"); date_of_birth(i); } } else { if (!(day>0 && day<=28)) { printf("nINVALID DATE t TRY AGAIN"); date_of_birth(i); } } break; case 3: if (!(day>0 && day<=30)) { printf("nINVALID DATE t TRY AGAIN"); date_of_birth(i); } break; default: printf("nINVALID MONTH t TRY AGAIN"); date_of_birth(i); } }
  • 98. 98 PROGRAM B : UNION #include<stdio.h> #include<string.h> union view { int val_1; float val_2; char val_3[30]; }data; int main() { printf("nAssigning and printing the union data one by one "); data.val_1=512; printf("nVal_1 = %d",data.val_1); data.val_2=12.56; printf("nVal_2 = %f",data.val_2); strcpy(data.val_3,"HelloC"); printf("nVal_3 = %s",data.val_3); printf("nTry to print the value of val_1 and val_2"); printf("nVal_1 = %d",data.val_1); printf("nVal_2 = %f",data.val_2); printf("nPrinting the lastly stored value "); printf("nVal_3 = %s",data.val_3); return 0; } PROGRAM C : ENUMERATED TYPE #include<stdio.h> enum channel_no{ sun,vijay=6,ktv,zee=9,vasanth,hdmusic}; int main() { printf("nChannel no of Sun_ch = %d",sun); printf("nChannel no of Vijay_ch = %d",vijay); printf("nChannel no of KTV_ch = %d",ktv); printf("nChannel no of Zee_ch = %d",zee); printf("nChannel no of Vasanth_ch = %d",vasanth); printf("nChannel no of hdmusic_ch = %d",hdmusic); }
  • 99. 99 PROGRAM D : TYPEDEF #include<stdio.h> typedef long long int NUM; int main() { NUM aadhar_num[50],phone_num[50]; int i,n; printf("nEnter number of students : "); scanf("%d",&n); for (i=0;i<n;i++) { printf("nEnter Aadhar number of student %d : ",i+1); scanf("%lld",&aadhar_num[i]); printf("nEnter Phone number of student %d : ",i+1); scanf("%lld",&phone_num[i]); } printf("nnEntered Details are : n"); printf("nS.No tAadharNumber tPhoneNumber"); for (i=0;i<n;i++) printf("n%d t%lld t%lld ",i+1,aadhar_num[i],phone_num[i]); return 0; } OUTPUT: OUTPUT A : STRUCTURE Enter how many number of students (Max:50) : 5 Enter Roll Number of student 1 : 20CSR137 Enter Name of student 1 : RAJA Enter Date of birth of student 1 (dd/mm/yy) (year must greater than 1970 and less than or equal to 2021) : 25 3 2001
  • 100. 100 Enter Age of student 1 : 19 Enter Cutt-Off of student 1 : 180.3 Enter Roll Number of student 2 : 20CSR138 Enter Name of student 2 : RAVI Enter Date of birth of student 2 (dd/mm/yy) (year must greater than 1970 and less than or equal to 2021) : 1 1 2001 Enter Age of student 2 : 19 Enter Cutt-Off of student 2 : 179.8 Enter Roll Number of student 3 : 20CSR139 Enter Name of student 3 : RAGU Enter Date of birth of student 3 (dd/mm/yy) (year must greater than 1970 and less than or equal to 2021) : 14 2 2002 Enter Age of student 3 : 19 Enter Cutt-Off of student 3 : 185.6 Enter Roll Number of student 4 : 20CCSR140 Enter Name of student 4 : RANI Enter Date of birth of student 4 (dd/mm/yy) (year must greater than 1970 and less than or equal to 2021) : 25 05
  • 101. 101 2002 Enter Age of student 4 : 19 Enter Cutt-Off of student 4 : 170.9 Enter Roll Number of student 5 : 20CSR141 Enter Name of student 5 : SANJU Enter Date of birth of student 5 (dd/mm/yy) (year must greater than 1970 and less than or equal to 2021) : 12 8 2002 Enter Age of student 5 : 19 Enter Cutt-Off of student 5 : 185.3 ROLL_NO NAME DATE-OF-BIRTH AGE CUTT-OFF 20CSR137 RAJA 25-3-2001 19 180.30 20CSR138 RAVI 1-1-2001 19 179.80 20CSR139 RAGU 14-2-2002 19 185.60 20CCSR140 RANI 25-5-2002 19 170.90 20CSR141 SANJU 12-8-2002 19 185.30 OUTPUT B : UNION Assigning and printing the union data one by one Val_1 = 512 Val_2 = 12.560000 Val_3 = HelloC Try to print the value of val_1 and val_2 Val_1 = 1819043144 Val_2 = 1143139122437582500000000000.000000 Printing the lastly stored value Val_3 = HelloC
  • 102. 102 OUTPUT C : ENUMERATED TYPE Channel no of Sun_ch = 0 Channel no of Vijay_ch = 6 Channel no of KTV_ch = 7 Channel no of Zee_ch = 9 Channel no of Vasanth_ch = 10 Channel no of hdmusic_ch = 11 OUTPUT D : TYPEDEF Enter number of students : 4 Enter Aadhar number of student 1 : 679712345678 Enter Phone number of student 1 : 9361742589 Enter Aadhar number of student 2 : 789654123321 Enter Phone number of student 2 : 7458963214 Enter Aadhar number of student 3 : 639852147852 Enter Phone number of student 3 : 8523697410 Enter Aadhar number of student 4 : 623145897753 Enter Phone number of student 4 : 8760306138 Entered Details are : S.No AadharNumber PhoneNumber 1 679712345678 9361742589 2 789654123321 7458963214 3 639852147852 8523697410 4 623145897753 8760306138 RESULT: Thus the above code has executed successfully.
  • 103. 103