Wednesday, December 1, 2010

Algorithm, Program & Output for Sum of digits of a number

Algorithm
  1. Start
  2. Read a number ‘n’
  3. Assign m with n, sum with 0
  4. If n ≠ 0 repeat steps (5) thru (7) else go to (8)
  5. k ß modulus(n,10)
  6. sum ß sum + k
  7. n ß quotient of n/10
  8. Print sum of digits of n is sum
  9. Stop
Program
#include <stdio.h>

main()
{
            int n,m,k,sum ;

            clrscr() ;
            printf("\tProgram to find Sum of Digits of a Number\n") ;
            printf("\n  Input\n\n") ;
            printf("Enter a Number : ") ;
            scanf("%d",&n) ;
            m = n ;
            sum = 0 ;
            while (n != 0)
              {
                  k = n%10 ;
                  sum += k ;
                  n = n/10 ;
              }
            printf("\n  Output\n\n") ;
            printf("Sum of Digits of %d is : %d",m,sum) ;
            getch() ;
}


Output
     Program to find Sum of Digits of a Number

  Input

Enter a Number : 1729

  Output

Sum of Digits of 1729 is : 19

       Program to find Sum of Digits of a Number

  Input

Enter a Number : -786

  Output

Sum of Digits of -786 is : -21

Algorithm, Program & Output for Sum of factors of a number

Algorithm
  1. Start
  2. Read a number ‘n’ > 0
  3. Assign sum with 0, i with 1
  4. If i<=n then repeat steps (5) and (6) else go to (7)
  5. If modulus(n,i) = 0
then sum ß sum + i and go to (6)
else go to (6)
  1. i ß i + 1
  2. Print sum of factors of n is sum
  3. Stop
 Program
#include <stdio.h>

main()
{
            int n,i,sum ;

            clrscr() ;
            printf("\tProgram to find Sum of factors of a Number\n") ;
            printf("\n  Input\n\n") ;
            printf("Enter a Number : ") ;
            scanf("%d",&n) ;
            sum = 0 ;
            for (i=1;i<=n;i++)
                if ((n%i) == 0)
                        sum += i ;
            printf("\n  Output\n\n") ;
            if (n <= 0)
                        printf("Enter greater than Zero") ;
            else
                        printf("Sum of factors of %d is : %d",n,sum) ;
            getch() ;
}


Output

Program to find Sum of factors of a Number

  Input

Enter a Number : 36

  Output

Sum of factors of 36 is : 91

Program to find Sum of factors of a Number

  Input

Enter a Number : 0

  Output

Enter greater than Zero

Wednesday, September 22, 2010

Algorithm for finding Result & Class in MS-Excel

  1. Start
  2. Click on Start Button à All Programs à MS Office à MS-Excel
  3. Enter the heading for the program at A1 to I2 cells
  4. Enter the given data from A4 to E13 cells, which is S.No., Name of the Student, Mathematics, Physics/Statistics and Computer Science with corresponding data
  5. Enter F4 to I4 cells : Total, Average, Result and Class headings
  6. Calculate Total for F5 cell as =Sum(C5 : E5), Average for G5 cell as =Average(C5 : E5), Result for H5 cell as =(IF(OR(C5<53,D5<35,E5<35),"Fail","Pass")) and the Class for I5 cell as
=IF(H5="Pass",IF(G5>=75,"Distinction",IF(AND(G5>=60,G5<75),"First",IF(AND(G5>=50,G5<60),"Second","Third"))),"Fail")
  1. Copy F5, G5, H5 and I5 cells formulae to Fth, Gth, Hth, Ith columns for remaining rows i.e., F6 to F13, G6 to G13, … after placing the mouse pointer at left, bottom of the cell and the mouse pointer changes to small + sign, and drag to those cells, then the other rows are filled with appropriate results
  2. Finally find out the Average marks of each subject by entering at some empty cells and by using the formula average(C5 : C13) for the subject at column C, like wise for other subjects also
  3. Save the worksheet with proper name and Close the Excel worksheet
  4. Stop



Algorithm for creating Charts in MS-Excel

  1. Start
  2. Click on Start Button à All Programs à MS Office à MS-Excel
  3. Enter the heading for the program at A1 to D1 cells
  4. Enter the given data from A3 to E8 cells, which is Year, Product-1, Product-2, Product-3 and Product-4 and corresponding data
  5. Click on Insert menu Chart option, opens Chart wizard window which is of 4 steps
  6. In Step 1 of 4, Select Chart type as Column and proper chart sub-type and click next button to proceed
  7. In Step 2 of 4, Select Data range is A3 to E8 cells and select Series in as rows and give proper names for each series and Category X-axis labels as A3 row which is all headings and click next button
  8. In Step 3 of 4, Type Chart title, X and Y axis titles, Axes, Gridlines, Legend, Data labels & Data tables as per your needs and click next button
  9. In Step4 of 4, Place the prepared Chart which is ready to place it as an object in Sheet1 or in a new excel worksheet and Finish
  10. Repeat Steps (5) thru (9) for 3D-Column and Bar Charts
  11. Save the worksheet with proper name and Close the Excel worksheet
  12. Stop





Algorithm for Number Conversions in MS-Excel

  1. Start
  2. Click on Start Button à All Programs à MS Office à MS-Excel
  3. A new blank worksheet is opened which contains A, B, C …. Rows and 1,2,3, … columns and the intersection of the rows and columns forms cells having the reference A1, A2, A3, … , B!, B2, B3, … etc.
  4. Enter the heading for the Program converting Decimal to Binary, Octal and Hexadecimal at 1st row
  5. Enter the given data in Ath column in the rows 3, 4, 5 …, and with appropriate headings in the columns B3, C3, D3 type the functions dec2bin(A4), dec2oct(A4), dec2hex(A4) functions respectively
  6. Copy B4, C4, D4 to remaining rows by placing the mouse pointer at the left, bottom corner of each cell and the mouse pointer changes to small + sign and drag it to other cells, then the other rows are filled with appropriate results
  7. Repeat step (5) and (6) for converting from Binary to others, Octal to others and Hexadecimal to others with appropriate functions by specifying proper cell references in the functions
  8. Save the worksheet with proper name and Close the Excel worksheet
  9. Stop


Algorithm for relating tables and generating Reports in MS-Access

  1. Start
  2. Click on Start Button à All Programs à MS Office à MS-Access
  3. A new blank database is opened. Use the Database wizard, where Tables, Queries, Forms, Reports, Pages etc., will appear on the left side in the wizard
  4. Click on Tables and create a table in Design view or by using wizard or by using entering data option to create the table structure with the given fields as columns with appropriate field names, data types to each field and click on Edit à Primary key option from menu bar to one appropriate column for two tables.
  5. Save it by entering table names to both the tables
  6. Enter the data properly to Employee Code, Employee Name and Basic Pay appropriately for table1
  7. Enter the data properly to Employee Code, Basic Pay appropriately for table2
  8. Click on Tools à Relationships option to relate the table1 and table2 by dragging Employee Code, which is the Primary key here
  9. Click on Queries and create a Query in Design view or by using wizard to create a query with Employee Code, Employee Name, Basic Pay by selecting the appropriate fields from each table
  10. Now add D.A. as an expression using function as : IIf ( [BasicPay]>=20000, [BasicPay]*40/100, IIf ( [BasicPay]>=10000 And [BasicPay] < 20000, [BasicPay]*30/100, [BasicPay]*20/100 ) ), H.R.A. as : [BasicPay]*25/100, and Gross Salary as : ([BasicPay]+[DA]+[HRA]) by entering the above formulae
  11. Save it by entering a query name and double click to see the rows of the query
  12. Report1 is created by using wizard view by following step by step process by including the required columns Employee Code, Employee Name, Basic Pay, D.A., H.R.A., and Gross Salary created while Query creation and finally save the report with an appropriate name
  13. Report2 is created by using wizard view by following step by step process by including the required columns Employee Code, Employee Name, Age, Gender and Gross Salary created and finally save the report with an appropriate name
  14. Double click the Reports to see the results of the reports in the desired format
  15. Close the database
  16. Stop








Algorithm for relating two tables in MS-Access

  1. Start
  2. Click on Start Button à All Programs à MS Office à MS-Access
  3. A new blank database is opened. Use the Database wizard, where Tables, Queries, Forms, Reports, Pages etc., will appear on the left side in the wizard
  4. Click on existing tables already created in the previous problem and now create two reports using Design view or by using Report wizard and  Save it by entering report names to both the reports
  5. Report1 is created by using wizard view by following step by step process by including the required columns Register Number, Name, marks of all subjects from the existing columns of tables and Total is already inserted as an Expression with the formula as : =(m1+m2+m3+m4+m5) while Query creation and finally save the report with an appropriate name
  6. Report2 is created by using wizard view by following step by step process by including the required columns Register Number from the existing column of any table, Total is already inserted as an expression with the formula as : (m1+m2+m3+m4+m5)  and Percentage as expression with the formula as : (total/5) while Query creation and finally save the report with an appropriate name
  7. Double click the Reports to see the results of the reports in the desired format
  8. Close the database
  9. Stop