• Save
C Programming
Upcoming SlideShare
Loading in...5
×
 

C Programming

on

  • 1,095 views

I. Create Pattern

I. Create Pattern
II. Print Series
III. Work with Records
IV. Use Numeric Functions
V. Work with Arrays
VI. Exit

Statistics

Views

Total Views
1,095
Views on SlideShare
1,095
Embed Views
0

Actions

Likes
1
Downloads
55
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

C Programming C Programming Document Transcript

  • Introduction to C ProgrammingCE00312-1 Individual Assignment APIIT SD INDIA Module Code: CE00312-1 Module title: Introduction to C programming Submitted by: Prince Kumar E-mail id: prince_karan640035@yahoo.com Page 1 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment Acknowledgement I would like to use this opportunity to thank all who lend their hand for completing our project successfully. First of all I would like to thank Almighty, who drove us through our project with his blessing and providing us with enough support to make it a success. I would then like to thank our project supervisor Miss XYZ who was there to guide us along the project, providing us assistance in doing the things in a proper and appropriate manner. Without her supervision this project would have been a tedious task for us. Also I would like to extend our gratitude to my friends, lab assistants, the librarian and management for providing us with good services and creating an environment for carrying out our project. At last I am thankful to APIIT SD INDIA for giving me this opportunity to carry out my C Assignment which contributed in enhancing my skill and knowledge in C Language. Page 2 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment Contents Acknowledgement .........................................................................................................................................2 1. Introduction...............................................................................................................................................4 1.1 Objective .......................................................................................................................................4 2. Project Description ...................................................................................................................................4 3. Program Design using Pseudo-code ........................................................................................................8 4. Segment of Code......................................................................................................................................11 4.1 Create Pattern ...................................................................................................................................14 4.1.1 Pyramid of asterisks ..................................................................................................................14 4.1.2 Pyramid of numbers ..................................................................................................................14 4.1.3 Square of asterisks .....................................................................................................................15 4.2 Print Series ........................................................................................................................................15 4.2.1 Series of Armstrong numbers between 1 and 500. ..................................................................15 4.2.2 Fibonacci series from 1 to 100 using recursion. ......................................................................16 4.2.3 Series of prime numbers from 1 to 100. ...................................................................................16 4.3 Work with Records ...........................................................................................................................17 4.3.1 Enter and Display Employee Information ...............................................................................17 4.3.2 Find Grade for a student ...........................................................................................................17 4.4 Use Numeric Functions.....................................................................................................................18 4.4.1 Factorial of a number using while loop ....................................................................................18 4.4.2 Sum of first and fifth digit of a 5 digit number. ......................................................................19 4.4.3 Find out whether a 5 digit number is palindrome or not. ......................................................19 4.5 Work with Arrays ......................................................................................................................20 4.5.1 Count number of vowels in the sentence. .............................................................................20 4.5.2 Copy the contents of an array into another. ........................................................................21 4.5.3 Delete item from an array .....................................................................................................21 4.6 Exit ..............................................................................................................................................22 5. User guide with Sample Input Output Screens ....................................................................................22 6. Limitations and Future Enhancements.................................................................................................27 7. Test Plan AND RESULT ...........................................................................................................................27 8. Conclusion ...............................................................................................................................................30 9. References ................................................................................................................................................31 10. Appendix ................................................................................................................................................32 Page 3 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment 1. Introduction C is a programming language developed at USA in 1972 by DENNIS RITCHIE. After that time the popularity of C is gone on increasing without any advertisement. C is a successor of B language which was introduced around 1970 The language was formalized in 1988 by the American National Standard Institute (ANSI). By 1973 UNIX OS almost totally written in C. Today C is the most widely used System Programming Language. Most of the state of the art software have been implemented using C. C was invented to write an operating system called UNIX. 1.1 Objective Be able to design, implement and document in well-organized manner. Explain the structure, functions, array and correct use of many features and implementation in appropriate advance manner to make application attractive. 2. Project Description In our Program, there is optimized programming which contributes to the programs in menu driven. The functionality of our program would be in the order of 1, 2, 3,4,5, and 6 in menu driven. There are six option in main menuCreate Pattern,Print Series, Work with Records, Use Numeric Functions, Work with Arrays and Exit. Each case contains another switch functionality to perform following function:I. Create Pattern After selecting this option, menu will be provided for the following sub options: 1. Pyramid of asterisks 2. Pyramid of numbers 3. Square of asterisks User will enter the sub-option and based upon it the following steps will execute Pyramid of asterisks System will ask for the number of rows of pattern from the user and will display the pattern accordingly. Like: If he entered 6 then the output is: * ** *** Page 4 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment **** ***** ****** Pyramid of numbers System will ask for the number of rows of pattern from the user and will display the pattern accordingly. Like: If he entered 6 then the output will be: 654321 65432 6543 654 65 6 Square of asterisks System will ask for the number of rows of pattern from the user and will display the pattern accordingly Like: If he entered 6 then the output will be: ****** ****** ****** ****** ****** ****** II. Print Series After selecting this option, menu will be provided for the following sub options. 1. Series of Armstrong numbers between 1 and 500. 2. Fibonacci series from 1 to 100 using recursion. 3. Series of prime numbers from 1 to 100. User will be asked to choose the sub-option and based upon that the result will be displayed on the screen. Page 5 of 44
  • Introduction to C ProgrammingCE00312-1 III. Individual Assignment Work with Records After selecting this option, menu will be provided for the following sub options. 1. Enter and Display Employee Information 2. Find Grade for a student User will be asked to choose the sub-option and based upon that the following steps should execute: Enter and Display Employee Information In this option, array of structures should be used to hold employee information like employee code, name etc. User will enter the information of three employees and after that system will display the information of all the three employees on the screen. Like: If he entered Employee code: 1, Employee Name: XYZ and Department: HR Then the output will be Employee Code: 1 Employee Name: Xyz Department: HR Find Grade for a student In this option, system will accept roll number, name and total marks of a student and will display roll number, name and grade. A criteria for finding the grade is as follows: If Marks >=70 grade is A If Marks between 60 and 69 grade is B If Marks between 50 and 59 grade is C If Marks <50 grade is D Like: If he entered 80 then the output will be A If he entered 65 then the output will be B If he entered 55 then the output will be C If he entered 40 then the output will be D IV. Use Numeric Functions After selecting this option, menu will be provided for the following sub options. 1. Factorial of a number using while loop 2. Sum of first and fifth digit of a 5 digit number. 3. Find out whether a 5 digit number is palindrome or not. After selecting the sub-option, user will be asked to enter the appropriate number and the calculations will be performed accordingly. Factorial of a number using while loop. Page 6 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment It will take number from the user and display the factorial of number. Like If user entered 4 then the factorial is 24 it will calculate like this 4*3*2*1 Sum of first and fifth digit of a 5 digit number. It will take input from the user and it will sum of first and fifth digit number. Like If user entered 12345 then it will take first and fifth digit and the answer is 6. Find out whether a 5 digit number is palindrome or not. Like If user entered 12321 then it will show 12321 is palindrome and if user entered 12345 then it will show the entered number is not palindrome. V. Work with Arrays After selecting this option, menu will be provided for the following sub options. 1. Count number of vowels in the sentence. 2. Copy the contents of an array into another. 3. Delete item from an array After selecting the sub-option, user will be asked to enter the size of the array for the option 2 And 3, after that appropriate array will be entered and result will be displayed accordingly. Maximum size of the array will be 100. Count number of vowels in the sentence. It will count vowels from the sentence and display number of vowels and constants distinctly This will count the vowels in sentence Like If user entered “working” then it will show Number of vowels in working = 2 Number of constant in working = 5 Copy the contents of an array into another. If user entered 3 then it will take 3 input and display in one array. Like If user entered Enter the value of array 1 = 1 Enter the value of array 2 = 2 Enter the value of array 3 = 3 Then Page 7 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment It will show Destination array = 3 2 1. Delete item from an array This will delete item from taken element Like It will take number of input number like if user entered 5 then user has to entered 5 input 1 2 3 4 5 Then it will ask to delete the item from array. If user entered 3 then it will show 1 2 4 5 VI. Exit This option is used to exit from the system 3. Program Design using Pseudo-code 3.1 Create Pattern 3.1.1 Pyramid of asterisks Step1: START Step2: Function Asterisk Step3: Read n,c,k Step4: Display Step5: Input n Step6: Loop C from 1 to x. End Loop Step7: Display * Step8: STOP 3.1.2 Pyramid of numbers Step1: START Step2: Function Pyramid Numbers Step3: Read num,r,c Step4: Display Step5: Input num Step6: Loop R from num to r. End Loop Page 8 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment Step7: Display c Step8: STOP 3.1.3 Square of asterisks Step1: START Step2: Function square_asterisk Step3: Read num,r,c Step4: Display Step5: Input num Step6: Loop C from 1 to x. End Loop Step7: Display * Step8: STOP 3.2 Print Series 3.2.1 Series of Armstrong numbers between 1 and 500. Step1: START Step2: Function Armstrong Step3: Read i,j,k,l,m,n; Step4: Loop 1 from 1 to 500. j=i%10; k=i/10; l=k%10; m=k/10; n=(m*m*m)+(l*l*l)+(j*j*j); if (n==i) End Loop Step5: Display i Step6: STOP 3.2.2 Fibonacci series from 1 to 100 using recursion. Step1: START Step2: Function Fibonacci Step3: Read old_number, current_number, next_number Step4: Display Step5: While (current_number < 100) Step6: Display Step7: STOP 3.2.3 Series of prime numbers from 1 to 100. Step1: START Step2: Function Prime Step3: Read n,div,p, num=100 Step4: FOR LOOP N from 2 to num :for(n=2; n<=num; n++) :{ :for(div=2; div<n; div++) :{ :if(n%div==0) :{ :p=0; :break; :} Page 9 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment :p=1; :} :if(p) : END LOOP Step5: Display n Step6: STOP 3.3 Work with Records 3.3.1 Enter and Display Employee Information Step1: START Step2: Function emp_information Step3: Read i=1,j=1 name[50],dept[20] Step4: FOR LOOP I from 1 to 3 END LOOP Step5: Display i and employee code Step6: Read empCode Step7: STOP 4.3.2 Find Grade for a student Step1: START Step2: Function grade_student Step3: Read name[50], roll, marks Step4: Display Step5:Input Step6: Display Step7: Input Step8: Display Step9: Display IF Step10: Display ELSE IF Step11:Display ELSE IF Step12: Display ELSE IF Step13: Display ELSE Step14: Display Step15: STOP 3.4 Use Numeric Functions 3.4.1 Factorial of a number using while loop Step1: START Step2: Function factorial Step3: Read a,i Step4: Display Step5: Input a Step6: IF : Display : ELSE Page 10 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment { f=1; i=1; while(i<=a) { f = f * i; i++; } Step7: Display Stop8: STOP 4. Segment of Code and Concepts Concepts Various C programming concepts have been applied in the program to make it as requested by the project. We have included the wide variety of the c data handling techniques and control structures to construct the whole program. Following are the concepts used in the assignment and their elaboration with the sample code from the program. Decision Control Structure: There are three ways for taking decision in the program and they are – IF-ELSE statement: If else statement has been frequently used in the program to facilitate the user to make the selection between the conditions based on the choice made. The sample code is shown below: if (decimal_number1 >= decimal_number2) { flag = 0; decimal_number3 = decimal_number1 – decimal_number2; } else { flag = 1; decimal_number3 = decimal_number2 – decimal_number1; } Switch statement: The developers have included many switch statements in the program whenever there is the necessity to make the choices between multiple options. The main benefit of using switch statement is that it will not take the control to scan each statement and execute the correct one but the control will directly jump to the provided case. Switch (temp_number[i]) { case‘0’: number = number*10 + 0; break; Page 11 of 44
  • Introduction to C ProgrammingCE00312-1 case‘1’: case‘2’: case‘3’: case‘4’: case‘5’: case‘6’: case‘7’: case‘8’: case‘9’: number number number number number number number number number = = = = = = = = = Individual Assignment number*10 number*10 number*10 number*10 number*10 number*10 number*10 number*10 number*10 + + + + + + + + + 1; 2; 3; 4; 5; 6; 7; 8; 9; break; break; break; break; break; break; break; break; break; } Nested IF-ELSE We have also included the nested if else statements whenever felt necessary. The sample code is given below. if (ch == 49 ||ch == 48) { printf("%c",ch); temp_number[i] = ch; i++; } elseif((ch == 8) && (i != 0)) { printf("b"); printf(" "); printf("b"); if (i!=0) { i--; } continue; } Loop Control Structure – Looping constructs are used in assignments where the multiple iterations were to be used for taking the passwords, calculating the totals, searching etc. Following are the sample codes for the different types of looping constructs used in the program. For Looping structure: for(i = node.char_count; node.temp_string[i] != '0'; i++) { printf("%c",node.temp_string[i]); } While Looping structure: while(i!=20) { ch = getch(); if (ch == 13) { break; } Page 12 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment if (ch == 8) { if (i!=0) { printf("b"); printf(" "); printf("b"); i--; } } else { printf("%c",ch); first_string[i] = ch; i++; } Symbolic Constants Symbolic constants are used in the program to make the program scalable. The length of string array are defined at the very beginning of the program. #define SIZE 20 Functions and pointers: The whole program consists of many of the functions calling each other to perform the task such as calculating determinant etc. Pointers are also used to pass through functions to change the original values of in the memory location. Example of function calling with Arguments: int determinent_solution(int **a,int order) { int **temp,i, j, k = 0, b = 0, deter = 0, coloumn_position, minor_value = 0; temp = malloc((5) * sizeof(int *)); for(i = 0; i < 5; i++) { temp[i] = malloc(5 * sizeof(int *)); } Arrays Arrays are used to store the numeric data or the characters. Character arrays in the form of string are used to store the information. The different numeric data after the calculation are also stored in the array: Examples of arrays in program (character arrays included) void matrix_addition() // Array to store elements of matrices { int first_matrix[6][6], second_matrix[6][6], result_matrix[6][6],row[2],coloumn[2],count = 0,i,j; Page 13 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment Structures Structures are used to store the string and a integer variable used in case of finding the number of characters in string. Structures are initialized outside the main function to make it global and the members of structures are accessed in the program wherever necessary. Sample code for structure struct search_char{ char temp_string[SIZE]; int char_count; }node; 4.1 Create Pattern 4.1.1 Pyramid of asterisks void asterisk() { Initialization of variables int n, c, k; printf("Enter number of rowsn"); scanf("%d",&n); Performed for ( c = 1 ; c <= n ; c++ ) Pyramid of asterisks { for( k = 1 ; k <= c ; k++ ) printf("*"); printf("n"); } } 4.1.2 Pyramid of numbers voidpyramid_numbers() { intnum,r,c; printf("Enter any number: "); scanf("%d", &num); for(r=1; r<=num; r++) { for(c=num; c>=r; c--) printf("%d",c); printf("n"); } } Initialization of variables Performed Pyramid of Numbers Page 14 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment 4.1.3 Square of asterisks voidsquare_asterisk() { Initialization of variables intnum,r,c; printf("Enter loop repeat number(rows): "); scanf("%d",&num); for(r=1; num>=r; r++) { Performed for(c=1; c<=num; c++) Square of asterisks printf("*"); printf("n"); } } 4.2 Print Series 4.2.1 Series of Armstrong numbers between 1 and 500. void Armstrong() { Initialization of variables inti,j,k,l,m,n; for (i=1;i<=500;i++) { j=i%10; k=i/10; Performed l=k%10; Series of Armstrong numbers between 1 and 500 m=k/10; n=(m*m*m)+(l*l*l)+(j*j*j); if (n==i) printf("%d n",i); } } Page 15 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment 4.2.2 Fibonacci series from 1 to 100 using recursion. void Fibonacci() { intold_number; intcurrent_number; intnext_number; Initialization of variables old_number = 1; current_number = 1; printf("1n"); while (current_number< 100) { printf("%dn", current_number); next_number = current_number + old_number; old_number = current_number; Performed Fibonacci series from 1 to 100 using recursion. current_number = next_number; } } 4.2.3 Series of prime numbers from 1 to 100. void prime() { intn,div,p; intnum=100; for(n=2; n<=num; n++) { for(div=2; div<n; div++) Performed { Series of prime numbers from 1 to 100. if(n%div==0) { p=0; break; } p=1; } if(p) printf("t%d",n); Page 16 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment } } 4.3 Work with Records 4.3.1 Enter and Display Employee Information voidemp_information() { struct Emp e[3]; Initialization of variables inti=1,j=1; char name[50],dept[20]; for(i=1;i<=3;++i) { printf("nn Employee : %d", i); printf("n Enter the Employee Code : "); scanf("%d",&e[i].empCode); printf("Enter the Employee Name : "); scanf("%s",&name); strcpy(e[i].empName,name); printf("Enter the Department : "); scanf("%s",&dept); Performed strcpy(e[i].empDept,dept); Enter and Display Employee Information } printf("nnn Employee Details "); for(j=1;j<=3;++j) { printf("nn Employee : %d",j); printf("n Employee Code : %d",e[j].empCode); printf("n Employee Name : %s",e[j].empName); printf("n Department : %s",e[j].empDept); } } 4.3.2 Find Grade for a student voidgrade_student() { Page 17 of 44
  • Introduction to C ProgrammingCE00312-1 char name[50]; Individual Assignment Initialization of variables introll,marks; printf("Enter student name:-- "); scanf("%s",&name); printf("Enter roll number of student:-- "); scanf("%d",&roll); printf("Enter total marks of student:-- "); scanf("%d",&marks); printf("nName of student is:-- %s",name); printf("nRoll number is:-- %d",roll); if(marks>=70) printf("nYour Grade is A"); else if(marks>=60 && marks<=69) printf("nYour Grade is B"); Performed else if(marks>=50 && marks<=59) Find Grade for a student printf("nYour Grade is C"); else if(marks<50) printf("nYour Grade is D"); else printf("n Kindly enter a valid marks"); } 4.4 Use Numeric Functions 4.4.1 Factorial of a number using while loop void factorial() { unsigned long longint f; inta,i; printf("nEnter a number: "); scanf("%d",&a); if(a<0) { printf("nPlease enter a positive number"); Page 18 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment factorial(); } Performed else Find Grade for a student { f=1; i=1; while(i<=a) { f = f * i; i++; } printf("Factorial: %lu",f); } } 4.4.2 Sum of first and fifth digit of a 5 digit number. voidsum_of_first_to_fifth() { int number, last_digit, first_digit, total; Initialization of variables printf (" Enter a five digit numeber: "); scanf ("%d", &number); last_digit = number % 10; Performed total = last_digit; Sum of first and fifth digit of a 5 digit number first_digit = (number / 10000) % 10; total = total + first_digit; printf ("The total of the first and the last digit of the entered number is: %d", total); } 4.4.3 Find out whether a 5 digit number is palindrome or not. voidpalindrom() { intnum,rem,i,rev=0,num1,count=0; printf("Enter the five digit number:n"); scanf("%d",&num); num1=num; while(num>0) Initialization of variables Page 19 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment { rem=num%10; rev=rem+rev*10; num=num/10; count++; } if(count==5) { if(num1==rev) { printf("The Given Number %d is Palindrome",num1); } else { printf("The Given Number %d is NOT Palindrome",num1); } } else { printf("The given %d number is not a five digit number!",num1); } Performed Find out whether a 5 digit number is palindrome or not. } 4.5 Work with Arrays 4.5.1 Count number of vowels in the sentence. voidcount_vowel() { char sentence[80]; inti, vowels = 0, consonants = 0, special = 0; printf("Enter a word n"); scanf("%s",&sentence); for (i = 0; sentence[i] != '0'; i++) { if ((sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] == 'i' || sentence[i] == 'o' || sentence[i] == 'u') || (sentence[i] == 'A' || sentence[i] == 'E' || sentence[i] == 'I' || sentence[i] == 'O' || sentence[i] == 'U')) { vowels = vowels + 1; } else { consonants = consonants + 1; } if (sentence[i] =='t' ||sentence[i] =='0' || sentence[i] ==' ') { Page 20 of 44 Performed Count number of vowels in the sentence
  • Introduction to C ProgrammingCE00312-1 Individual Assignment special = special + 1; } } consonants = consonants - special; printf("No. of vowels in %s = %dn", sentence, vowels); printf("No. of consonants in %s = %dn", sentence, consonants); getch(); } 4.5.2 Copy the contents of an array into another. voidcopy_array() { int source[100], dest[100],i,j,no; Initialization of variables clrscr(); printf("Enter the number of values to be enterd: "); scanf("%d",&no); for(i=0;i<no;i++){ printf("Enter the value of array no. %d :",i+1); scanf("%d",&source[i]); } Performed for(i=0,j=no-1;i<no;i++,j--){ Copy the contents of an array into another dest[j]=source[i]; } printf("Destination array:n"); for(i=0;i<no;i++){ printf("%dt",dest[i]); } } 4.5.3 Delete item from an array voiddelete_array() { int array[100], position, c, n; Initialization of variables printf("Enter number of elements in arrayn"); scanf("%d", &n); printf("Enter %d elementsn", n); for ( c = 0 ; c < n ; c++ ) scanf("%d", &array[c]); Page 21 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment printf("Enter the location where you wish to delete elementn"); scanf("%d", &position); if ( position >= n+1 ) printf("Deletion not possible.n"); else { for ( c = position - 1 ; c < n - 1 ; c++ ) array[c] = array[c+1]; Performed Delete item from an array printf("Resultant array isn"); for( c = 0 ; c < n - 1 ; c++ ) printf("%dn", array[c]); } } 4.6 Exit exit (0); 5. User guide with Sample Input Output Screens Page 22 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment Page 23 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment Page 24 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment Page 25 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment Page 26 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment 6. Limitations and Future Enhancements Like there are two faces of a coin so do our project has some of the limitation which makes it non-functional in some cases. Following are some of the limitations of the program and future enhancement – I. No graphical user interface - The program does not provide any kind of graphical user interface as it is a console application which may make it difficult to navigate for the user with little knowledge of computers. It may also take lots of time for the user to use the program as the user has to go through each and every message and texts written in the program unlike the graphical system which provides the graphical images in replace of bulk text messages. For the further enhancement the program can be made by choosing the windows application format which provides the graphical user interface to the users making it easy to navigate. II. No option to save results - There is no way to store the results for future use and access them whenever required. Once the work is done the results will be flushed out and system will come back to its previous position. For the further enhancement the program can make a use of file handling so that results would be stored for future access. 7. Test PlanAND RESULT In general, testing is finding out how well something works. In terms of human beings, testing tells what level of knowledge or skill has been acquired. In computer hardware and software development, testing is used at key checkpoints in the overall process to determine whether objectives are being met. For example, in software development, product objectives are sometimes tested by product user representatives. When the design is complete, coding follows and the finished code is then tested at the unit PERFORMANCE MANAGEMENT or module level by each programmer; at the component level by the group of programmers involved; and at the system level when all components are combined together. At early or late stages, a product or service may also be tested for usability. At the system level, the manufacturer or independent reviewer may subject a product or service to one or more performance tests, possibly using one or more benchmarks. Whether viewed as a product or a service or both, an application can also be tested in various ways by observing user experiences, by asking questions of users, by timing the flow through specific usage scenarios, and by comparing it with other application. Page 27 of 44
  • Introduction to C ProgrammingCE00312-1 Question No: 1.Pyramid of asterisks Individual Assignment Input 6 2.Pyramid numbers of of * ** *** **** ***** ****** 6 3. Square asterisks Output 6 Status Tested By: Successful 654321 65432 6543 654 65 6 ****** ****** ****** ****** ****** ****** User Successful User Successful User 4. Series of Armstrong numbers between 1 and 500 1 153 370 371 407 Successful User 5.Fibonacci series from 1 to 100 using recursion User 6. Series of prime numbers from 1 to 100. 1 Successful 1 2 3 5 8 13 21 34 55 89 2,3,5,7,11,13,17,19,23, Successful 29,31,37,41,43,47,53,59, 61,67,71,73,79,83,89,97. Enter and Display Employee Information Employee 1 Employee code:101 Employee Name: ABC Department: HR Successful User 7. Employee 2 Page 28 of 44 User
  • Introduction to C ProgrammingCE00312-1 Individual Assignment Employee code:102 Employee Name: XYZ Department: IT 9.Factorial of a number using while loop 4 Employee 3 Employee code:103 Employee Name: DEF Department: Accountant Student name: ABC Student number:12 Student marks:80 Grade: “A” 24 10.Sum of first and fifth digit of a 5 digit number 12345 11. Find out whether a 5 digit number is palindrome or not 8. Find Grade for a student Successful User Successful User 6 Successful User 12321 Number is palindrome Successful User 12.Count number of vowels in the sentence Working Number of vowels in “working”=2 Successful User 13. Copy the contents of an array into another Enter the value of array1=1 Destination array = 3 2 1 Successful User Item to be deleted from array = 3 1 Successful User Number of constants in “working”=5 Enter the value of array2=2 Enter the value of array3=3 14. Delete item from an array 1 2 3 Page 29 of 44
  • Introduction to C ProgrammingCE00312-1 4 5 15. Exit 6 Individual Assignment 2 4 5 Exit – Out of the system Successful User 8. Conclusion I started this project when I had very few concepts about the C language and its different usage. During the project preparation Iwas introduced with the new concepts and new elements of C language along with the progression of the course. I was able to apply all those theoretical C concepts taught to me in my application to make it more and more functional. As the time passed by I worked on my project to make it very Compaq and very much functional and easy to use for the user. During this period I learned various C programming concepts and now in position to design in the error free program successfully. I came to know the various C programming techniques. I learned to make the variables and constants either global or local.I also learned the practical way of implementing the structures in the program and access the members of structures, compare them, initialize them and so on. The implementation of techniques like string comparison, function calling, recursion, array storage, and calling by value or reference, has broaden my knowledge regarding C language. The major technical learning I had from the project is that how different functions can be associated to form the single program and how the data flows from one unit (function) to another and produce the desired output. I was introduced with the validations techniques to make the program error free and reliable. Ihad also learned to design the problem, develop the algorithms, and test the program to measure the efficiency and accuracy. Page 30 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment 9. References Books I. II. III. IV. V. Robert"C Programming Functions." C Programming Functions. Programiz, n.d. Web. 09 Nov. 2013. Code Coding. "C Program to Print Pyramid." Cprogramtocom. WordPress.,n.d. Web. 09 Nov. 2013. AbhasTandon. "C Program to Print All Prime Numbers between 1 and 100." - C WithAbhas. Cwithabhas, n.d. Web. 09 Nov. 2013. Dietel, P. & Dietel H. (2010).C How to program, New Delhi, Prentice Hall of India (PHI). Vol 6, pp.1-437 Donald, K. (2001).The Art of Computer Programming, Kansas City, AddisonWesleyPublication vol. 1. Electronic I. Available at : http://www.cembedded.com/2009/04/write-pseudocode-to-compare-versions.html [Last Accessed: 12 September 2013] II. Available at : http://www.dreamincode.net/forums/topic/10300-pseudocode-help/ [Last Accessed: 1 October 2013] III. Available at : http://www.fredosaurus.com/notes-cpp/algorithms/sorting/bubblesort-fixed.html [Last Accessed: 15 September 2013] IV. Available at http://www.metalshell.com/source_code/32/Simple_Struct_Example.html [Last Accessed: 19 September 2013] V. Available at http://qa.techinterviews.com/q/20060729010733AA7wpXo [Last Accessed: 25 September 2013] VI. Available at http://www.unf.edu/~broggio/cop3530/3530pseu.htm [Last Accessed: 21 September 2013] Page 31 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment 10. Appendix Program: #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<string.h> void menu() { clrscr(); printf("n Main Menu"); printf("n 1. Create Pattern "); printf("n 2. Print Series"); printf("n 3. Work with Records"); printf("n 4. Use Numeric Functions"); printf("n 5. Work with arrays"); printf("n 6. Exit"); } struct Emp { intempCode; charempName[50]; charempDept[20]; }; /* ====1.1 Creat Pattern for pyramid of asterisks==== */ void asterisk() { int n, c, k; printf("Enter number of rowsn"); scanf("%d",&n); for ( c = 1 ; c <= n ; c++ ) { Page 32 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment for( k = 1 ; k <= c ; k++ ) printf("*"); printf("n"); } } /* ====1.2 Creat Pattern for pyramid of numbers==== */ voidpyramid_numbers() { intnum,r,c; printf("Enter any number: "); scanf("%d", &num); for(r=1; r<=num; r++) { for(c=num; c>=r; c--) printf("%d",c); printf("n"); } } /* ====1.3 Creat Pattern for square of asterisks==== */ voidsquare_asterisk() { intnum,r,c; printf("Enter loop repeat number(rows): "); scanf("%d",&num); for(r=1; num>=r; r++) { for(c=1; c<=num; c++) printf("*"); printf("n"); } } /* ====2.1 Print series of Armstrong numbers between 1 and 500==== */ Page 33 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment void Armstrong() { inti,j,k,l,m,n; for (i=1;i<=500;i++) { j=i%10; k=i/10; l=k%10; m=k/10; n=(m*m*m)+(l*l*l)+(j*j*j); if (n==i) printf("%d n",i); } } /* ====2.2 Print series of Fibonacci series from 1 to 100 using recursion==== */ void Fibonacci() { intold_number; intcurrent_number; intnext_number; old_number = 1; current_number = 1; printf("1n"); while (current_number< 100) { printf("%dn", current_number); next_number = current_number + old_number; old_number = current_number; current_number = next_number; } } /* ====2.3 Print series of prime numbers from 1 to 100==== */ void prime() Page 34 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment { intn,div,p; intnum=100; for(n=2; n<=num; n++) { for(div=2; div<n; div++) { if(n%div==0) { p=0; break; } p=1; } if(p) printf("t%d",n); } } /* ====3.1 Work with Records to Enter and Display Employee Information==== */ voidemp_information() { struct Emp e[3]; inti=1,j=1; char name[50],dept[20]; for(i=1;i<=3;++i) { printf("nn Employee : %d", i); printf("n Enter the Employee Code : "); scanf("%d",&e[i].empCode); printf("Enter the Employee Name : "); scanf("%s",&name); strcpy(e[i].empName,name); Page 35 of 44
  • Introduction to C ProgrammingCE00312-1 printf("Enter the Department Individual Assignment : "); scanf("%s",&dept); strcpy(e[i].empDept,dept); } printf("nnn Employee Details "); for(j=1;j<=3;++j) { printf("nn Employee : %d",j); printf("n Employee Code : %d",e[j].empCode); printf("n Employee Name : %s",e[j].empName); printf("n Department : %s",e[j].empDept); } } /* ====3.2 Work with Records to Find Grade for a student==== */ voidgrade_student() { char name[50]; introll,marks; printf("Enter student name:-- "); scanf("%s",&name); printf("Enter roll number of student:-- "); scanf("%d",&roll); printf("Enter total marks of student:-- "); scanf("%d",&marks); printf("nName of student is:-- %s",name); printf("nRoll number is:-- %d",roll); if(marks>=70) printf("nYour Grade is A"); else if(marks>=60 && marks<=69) printf("nYour Grade is B"); else if(marks>=50 && marks<=59) printf("nYour Grade is C"); Page 36 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment else if(marks<50) printf("nYour Grade is D"); else printf("n Kindly enter a valid marks"); } /* ====4.1 Use Numeric Functions for Factorial of a number using while loop ==== */ void factorial() { unsigned long longint f; inta,i; printf("nEnter a number: "); scanf("%d",&a); if(a<0) { printf("nPlease enter a positive number"); factorial(); } else { f=1; i=1; while(i<=a) { f = f * i; i++; } printf("Factorial: %lu",f); } } /* ====4.2 Use Numeric Functions for Sum of first and fifth digit of a 5 digit number ==== */ voidsum_of_first_to_fifth() Page 37 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment { int number, last_digit, first_digit, total; printf (" Enter a five digit numeber: "); scanf ("%d", &number); last_digit = number % 10; total = last_digit; first_digit = (number / 10000) % 10; total = total + first_digit; printf ("The total of the first and the last digit of the entered number is: %d", total); } /* ====4.3 Use Numeric Functions to Find out whether a 5 digit number is palindrome or not==== */ voidpalindrom() { intnum,rem,i,rev=0,num1,count=0; printf("Enter the five digit number:n"); scanf("%d",&num); num1=num; while(num>0) { rem=num%10; rev=rem+rev*10; num=num/10; count++; } if(count==5) { if(num1==rev) { printf("The Given Number %d is Palindrome",num1); } else Page 38 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment { printf("The Given Number %d is NOT Palindrome",num1); } } else { printf("The given %d number is not a five digit number!",num1); } } /* ====5.1 Work with Arrays to Count number of vowels in the sentence==== */ voidcount_vowel() { char sentence[80]; inti, vowels = 0, consonants = 0, special = 0; printf("Enter a word n"); scanf("%s",&sentence); for (i = 0; sentence[i] != '0'; i++) { if ((sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] == 'i' || sentence[i] == 'o' || sentence[i] == 'u') || (sentence[i] == 'A' || sentence[i] == 'E' || sentence[i] == 'I' || sentence[i] == 'O' || sentence[i] == 'U')) { vowels = vowels + 1; } else { consonants = consonants + 1; } if (sentence[i] =='t' ||sentence[i] =='0' || sentence[i] ==' ') { Page 39 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment special = special + 1; } } consonants = consonants - special; printf("No. of vowels in %s = %dn", sentence, vowels); printf("No. of consonants in %s = %dn", sentence, consonants); getch(); } /* ====5.2 Work with Arrays to Copy the contents of an array into another==== */ voidcopy_array() { int source[100], dest[100],i,j,no; clrscr(); printf("Enter the number of values to be enterd: "); scanf("%d",&no); for(i=0;i<no;i++){ printf("Enter the value of array no. %d :",i+1); scanf("%d",&source[i]); } for(i=0,j=no-1;i<no;i++,j--){ dest[j]=source[i]; } printf("Destination array:n"); for(i=0;i<no;i++){ printf("%dt",dest[i]); } } /* ====5.3 Work with Arrays to Delete item from an array==== */ voiddelete_array() { int array[100], position, c, n; Page 40 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment printf("Enter number of elements in arrayn"); scanf("%d", &n); printf("Enter %d elementsn", n); for ( c = 0 ; c < n ; c++ ) scanf("%d", &array[c]); printf("Enter the location where you wish to delete elementn"); scanf("%d", &position); if ( position >= n+1 ) printf("Deletion not possible.n"); else { for ( c = position - 1 ; c < n - 1 ; c++ ) array[c] = array[c+1]; printf("Resultant array isn"); for( c = 0 ; c < n - 1 ; c++ ) printf("%dn", array[c]); } } void main() { intch; charans; menu: do{ clrscr(); menu(); printf("n ENTER CHOICE ...."); scanf("%d",&ch); switch(ch) { case 1: clrscr(); Page 41 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment printf("tt ******** CREATE PATTERN ********"); printf("n1. Pyramid of asterisks "); printf("n2. Pyramid of numbers"); printf("n3. Square of asterisks"); printf("nn Enter choice..."); scanf("%d",&ch); switch(ch) { case 1: asterisk(); break; case 2: pyramid_numbers(); break; case 3: square_asterisk(); break; default: printf("Wrong choicenn"); goto menu; } break; case 2: clrscr(); printf("nntt ******** PRINT SERIES *******"); printf("n1. Series of Armstrong numbers between 1 and 500 "); printf("n2. Fibonacci series from 1 to 100 using recursion"); printf("n3. Series of prime numbers from 1 to 100"); printf("nnEnter your choice....."); scanf("%d",&ch); switch(ch) { case 1: Armstrong(); break; case 2: Fibonacci(); break; case 3: prime(); break; default: printf("Wrong choicenn"); goto menu; } break; Page 42 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment case 3: clrscr(); printf("nntt ******* WORK WITH RECORDS *******"); printf("n1. Enter and Display Employee Information "); printf("n2. Find Grade for a student"); printf("nnEnter your choice....."); scanf("%d",&ch); switch(ch) { case 1: emp_information(); break; case 2: grade_student(); break; default: printf("Wrong choicenn"); goto menu; } break; case 4: clrscr(); printf("nntt ******* USE NUMERIC FUNCTION *******"); printf("n1. Factorial of a number using while loop "); printf("n2. Sum of first and fifth digit of a 5 digit number."); printf("n3. Find out whether a 5 digit number is palindrome or not."); printf("nnEnter your choice....."); scanf("%d",&ch); switch(ch) { case 1: factorial(); break; case 2: sum_of_first_to_fifth(); break; case 3: palindrom(); break; default: printf("Wrong choicenn"); goto menu; } break; Page 43 of 44
  • Introduction to C ProgrammingCE00312-1 Individual Assignment case 5: clrscr(); printf("nntt ******** WORK WITH ARRAYS ********"); printf("n1. Count number of vowels in the sentence"); printf("n2. Copy the contents of an array into another."); printf("n3. Delete item from an array."); printf("nnEnter your choice....."); scanf("%d",&ch); switch(ch) { case 1: count_vowel(); break; case 2: copy_array(); break; case 3: delete_array(); break; default: printf("Wrong choicenn"); goto menu; } break; case 6: printf("nn Thanks"); printf("nn See you again"); exit (0); default: goto menu; } printf("nnPress y to continuee...."); scanf("%s",&ans); } while(ans=='y'||ans=='Y'); getch(); } Page 44 of 44