Programming in C Lab
|
|
- Jeffrey Austin
- 5 years ago
- Views:
Transcription
1 Programming in C Lab
2 1a. Write a program to find biggest number among given 3 numbers. ALGORITHM Step 1 : Start Start 2 : Input a, b, c Start 3 : if a > b goto step 4, otherwise goto step 5 Start 4 : if a > c goto step 6, otherwise goto step 8 Start 5 : if b > c goto step 7, otherwise goto step 8 Start 6 : Output "a is the largest", goto step 9 Start 7 : Output "b is the largest", goto step 9 Start 8 : Output " c is the largest", goto step 9 Start 9 : Stop FLOWCHART
3 PROGRAM #include <stdio.h> int main() double n1, n2, n3; printf("enter three different numbers: "); scanf("%lf %lf %lf", &n1, &n2, &n3); if( n1>=n2 && n1>=n3 ) printf("%.2f is the largest number.", n1); if( n2>=n1 && n2>=n3 ) printf("%.2f is the largest number.", n2); if( n3>=n1 && n3>=n2 ) printf("%.2f is the largest number.", n3); return 0; OUTPUTgcc 1a.c./a.out Enter three different numbers is the largest number
4 2a. Write a program to determine roots of quadratic equation of the form ax2+bx+c by checking the discriminant value using IF statement. The discriminant tells us whether there are two solutions, one solution, or no solutions. ALGORITHM Step 1: [Start] Begin Step 2: [Input the co-efficients of the quadratic equation Read a,b,c Step 3:[Check for the non-zero coefficient of a] If a = 0 then print Invalid input, go to step 2 Step 4: [Find the value of disc] disc = b * b 4 * a * c Step 5: [Find the type and the values of roots of a given quadratic equation] If (disc = 0) then Print The roots are equal root1 = root2 = -b / 2.0*a Go to step 6 Else If (disc > 0) then Print The roots are real and distinct root1 = (-b + sqrt(disc)) / 2.0*a root2 = (-b - sqrt(disc)) / 2.0*a Go to step 6 else Print The roots are imaginary root1 = -b / 2.0*a root2 = sqrt(fabs(disc)) / 2.0*a Step 6: [Output] Print root1, root2 Step 7: [Stop] End
5 FLOWCHART PROGRAM #include <stdio.h> #include<math.h> void main() int a,b,c,d; float x1,x2; printf("enter the value of a,b & c\n"); scanf("%d%d%d",&a,&b,&c); d=b*b-4*a*c; if(d==0)
6 printf("both roots are equal\n"); x1=-b/(2.0*a); x2=x1; printf("first  Root x1= %f\n",x1); printf("second Root x2= %f\n",x2); else if(d>0) printf("both roots are real and diff-2\n"); x1=(-b+sqrt(d))/(2*a); x2=(-b-sqrt(d))/(2*a); printf("first  Root x1= %f\n",x1); printf("second Root x2= %f\n",x2); else printf("root are imaginary\n No Solution \n"); OUTPUT Enter a, b and c of quadratic equation: Roots are real numbers. Roots of quadratic equation are: ,
7 3a. Write a program to demonstrate use of Switch-Case statement by choosing and displaying day- name when day-number is given as input. (Eg: 0 for Sunday, 1 for Monday, 2 for Tuesday...etc...). ALGORITHM Step 1: Input day number from user. Store it in some variable say week. Step 2: Switch the value of week i.e. use switch(week) and match with cases. Step 3: There can be 7 possible values(choices) of week i.e. 1 to 7. Therefore write 7 case inside switch. In addition, add default case as an else block. Step 4: For case 1: print "MONDAY", for case 2: print "TUESDAY" and so on. Print "SUNDAY" for case 7:. Step 5: If any case does not matches then, for default: case print "Invalid week number". FLOWCHART
8 PROGRAM #include <stdio.h> int main() int week; /* Input week number from user */ printf("enter week number(1-7): "); scanf("%d", &week); switch(week) case 1: printf("monday"); break; case 2: printf("tuesday"); break; case 3: printf("wednesday"); break; case 4: printf("thursday"); break; case 5: printf("friday"); break; case 6: printf("saturday"); break; case 7: printf("sunday"); break; default: printf("invalid input! Please enter week number between 1-7."); return 0; OUTPUT Enter week no 3
9 Wednesday 4a. Write a program to generate Prime numbers between 2 to a given number, N. ALGORITHM Step 1: Input N & M Step 2: While (N < M) I=2 Step 4: While (I<N) Step 5: IF N%I == 0 goto Step 7 Step 6: I++ Step 7: IF I==NUM Print NUM Step 7: N++ FLOWCHART PROGRAM
10 #include<stdio.h> void main() int n,i,fact,j; printf("enter the Number"); scanf("%d",&n); printf("prime Numbers are: \n"); for(i=1; i<=n; i++) fact=0; for(j=1; j<=n; j++) if(i%j==0) fact++; if(fact==2) printf("%d ",i); OUTPUT: Enter the Number50 Prime Numbers are:
11 5a. Write a program to determine following SIN series and find the difference between calculated series value and the value returned by built-in Sin(x) function. ALGORITHM Step 1 : Start Start 2 : Input x Start 3 : from i=1 to 10 Fact=1 Start 4 : for(j=1;j<=i+2;j++) fact=fact*j; sin=sin+(f*pow(x,i+2))/fact; Start 5 :go to step 3 Start 6 : Output sin x Start 7 : Stop FLOWCHART start read X for(i=1;i<10;i+=2) fact=1 i<10 for(j=1;j<=i+2;j++) fact=fact*j; sin=sin+(f*pow(x,i+2))/fact;
12 Print sin x Stop PROGRAM #include<stdio.h> #include<math.h> int main() float sin=0,x,fact; int i,j,f=-1; printf("enter x:"); scanf("%f",&x); for(i=1;i<10;i+=2) fact=1; for(j=1;j<=i+2;j++) fact=fact*j; sin=sin+(f*pow(x,i+2))/fact; if(f>0) f=-1; else f=1; printf("\n\nsinx=%f",x+sin); return 0; OUTPUT: $ gcc 5a.c -lm $./a.out Enter x:3 sinx=
13 6.a Write a program to store 10 elements in an array of numbers and search given number and its position in array. ALGORITHM Step 1 : Start Start 2 : Read array of elements Read element to be searched Found=0 Start 3 : from 0 to n position of the array search the array element=element to be searched Start 4 : if found found =1 else found =0 Start 5 ; if found=1 print the element else print element not found Start 6 : Stop
14 FLOWCHART
15 PROGRAM #include <stdio.h> #define MAX_SIZE 100 // Maximum array size int main() int arr[max_size]; int size, i, tosearch, found; /* Input size of array */ printf("enter size of array: "); scanf("%d", &size); /* Input elements of array */ printf("enter elements in array: "); for(i=0; i<size; i++) scanf("%d", &arr[i]); printf("\nenter element to search: "); scanf("%d", &tosearch); /* Assume that element does not exists in array */ found = 0; for(i=0; i<size; i++) /* * If element is found in array then raise found flag * and terminate from loop. */ if(arr[i] == tosearch) found = 1; break; /* * If element is not found in array */ if(found == 1) printf("\n%d is found at position %d", tosearch, i + 1);
16 else printf("\n%d is not found in the array", tosearch); return 0; OUTPUT: $ gcc 6a.c $./a.out Enter size of array: 6 Enter elements in array: Enter element to search: 8 8 is not found in the array
17 7.a Write a program to sort given random numbers into ascending order using arrays ALGORITHM Step 1: [Start] Begin Step 2: [Input the number of elements in the array] Read n Step 3: [Input the n integer numbers] For i -1 in steps of 1 Read End for Step 4: [Display the original array] For i 0 thru n-1 in steps of End for Step 5: [Repeat step 5 for i varies from 0 thru n-1] For i = 0 thru n-1 in steps of 1 For j = 0 thru n-i-1 in steps of 1 IF ( num[j] > num[j + 1] ) then temp= num[j] num[j] = num[j + 1] num[j+1] = temp End if End for End for Step 6: [Output the sorted array] For i 0 thru n-1 in steps of End for
18 FLOWCHART
19 PROGRAM #include <stdio.h> void main() int i, j, a, n, number[30]; printf("enter the value of N \n"); scanf("%d", &n); printf("enter the numbers \n"); for (i = 0; i < n; ++i) scanf("%d", &number[i]); for (i = 0; i < n; ++i) for (j = i + 1; j < n; ++j) if (number[i] > number[j]) a = number[i]; number[i] = number[j]; number[j] = a; printf("the numbers arranged in ascending order are given below \n"); for (i = 0; i < n; ++i) printf("%d\n", number[i]); OUTPUT: ~$ ^C ~$ ^C ~$ gcc 7a.c ~$./a.out Enter the value of N 5 Enter the numbers The numbers arranged in ascending order are given below
20 8.a Write a program to sort given strings in ascending or descending order. ALGORITHM Step 1: [Start] Begin Step 2: [Input the number of elements in the array] Read n Step 3: [Input string array] For i -1 in steps of 1 Read End for Step 4: [Display the original array] For i 0 thru n-1 in steps of End for Step 5: [Repeat step 5 for i varies from 0 thru n-1] For i = 0 thru n-1 in steps of 1 For j = 0 thru n-i-1 in steps of 1 IF ( num[j] > num[j + 1] ) then temp= num[j] num[j] = num[j + 1] num[j+1] = temp End if End for End for Step 6: [Output the sorted array] For i 0 thru n-1 in steps of End for
21 FLOWCHART PROGRAM #include <stdio.h> #include <string.h> void main()
22 char str[100],ch; int i,j,l; printf("\n\nsort a string array in ascending order :\n"); printf(" \n"); printf("input the string : \n"); fgets(str, sizeof str, stdin); l=strlen(str); /* sorting process */ for(i=1;i<=l;i++) for(j=0;j<l-i;j++) if(str[j]>str[j+1]) ch=str[j]; str[j] = str[j+1]; str[j+1]=ch; printf("after sorting the string appears like : \n"); printf("%s\n\n",str); OUTPUT: $ gcc 8a.c $./a.out Sort a string array in ascending order : Input the string : welcome to pda cse dept After sorting the string appears like : accddeeeelmooppsttw
23 9.a Write a program to print multiplication table of a given number. ALGORITHM Step 1:Start the process. Step 2:Input N, the number for which multiplication table is to be printed. Step 3: For T = 1 to 10 Step 4:Print M = N * T Step 5:End For Step 6: Stop the process FLOWCHART
24 PROGRAM #include <stdio.h> int main() int num, i = 1; printf("enter any Number:"); scanf("%d", &num); printf("multiplication table of %d: ", num); while (i <= 10) printf(" %d x %d = %d\n", num, i, num * i); i++; return 0; OUTPUT: ~$ gcc 9a.c ~$./a.out Enter any Number:9 Multiplication table of 9: 9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81 9 x 10 = 90
25 10.a Write a program to read elements of 3x3 matrix and print the elements in matrix form ALGORITHM Step 1: [Start] Begin Step 2: [Input the order of matrix A and matrix B] Read m, n, p, q Step 3: [Check whether two matrices are multplicable] If (n = p) then go to step 4 Else Print ( MULTIPLICATION NOT ALLOWED TRY AGAIN ) Go to step 2 End if Step 4: [Read matrix A] For i 0 thru m-1 in steps of 1 For j0 thru n-1 in steps of 1 Read A[ I ][ j ] End for End for Step 5: [Read matrix B] For i 0 thru p-1 in steps of 1 For j -1 in steps of 1 Read B[ I ][ j ] End for End for Step 7: [Output] Print A[m][n], B[p][q] Step 8: [Stop] End
26 FLOWCHART
27 PROGRAM #include <stdio.h> void main() int arr1[3][3],i,j; printf("\n\nread a 2D array of size 3x3 and print the matrix :\n"); printf(" \n"); /* Stored values into the array*/ printf("input elements in the matrix :\n"); for(i=0;i<3;i++) for(j=0;j<3;j++) printf("element - [%d],[%d] : ",i,j); scanf("%d",&arr1[i][j]); printf("\nthe matrix is : \n"); for(i=0;i<3;i++) printf("\n"); for(j=0;j<3;j++) printf("%d\t",arr1[i][j]); printf("\n\n");
28 OUTPUT: ~$ gedit 10b.c ~$ gcc 10b.c ~$./a.out Read a array of size 3x3 and print the matrix : Input elements in the matrix : element - [0],[0] : 1 element - [0],[1] : 2 element - [0],[2] : 3 element - [1],[0] : 4 element - [1],[1] : 5 element - [1],[2] : 65 element - [2],[0] : 67 element - [2],[1] : 78 element - [2],[2] : 98 The matrix is :
29 11a. Write a program to multiply two matrices and print input and output mattresses in matrix form ALGORITHM Matrix-Multiply(A, B) Step 1: if columns [A] rows [B] then error "incompatible dimensions" Step 2: else for i =1 to rows [A] for j = 1 to columns [B] C[i, j] =0 Step3: for k = 1 to columns [A] C[i, j]=c[i, j]+a[i, k]*b[k, j] Step 4: return C Step 5: Stop FLOWCHART
30 PROGRAM #include<stdio.h> int main() int m, n, p, q, c, d, k, sum = 0; int first[10][10], second[10][10], multiply[10][10]; printf("enter the number of rows and columns of first matrix\n"); scanf("%d%d", &m, &n); printf("enter the elements of first matrix\n"); for ( c = 0 ; c < m ; c++ ) for ( d = 0 ; d < n ; d++ ) scanf("%d", &first[c][d]); printf("enter the number of rows and columns of second matrix\n"); scanf("%d%d", &p, &q); if ( n!= p ) printf("matrices with entered orders can't be multiplied with each other.\n"); else printf("enter the elements of second matrix\n"); for ( c = 0 ; c < p ; c++ ) for ( d = 0 ; d < q ; d++ ) scanf("%d", &second[c][d]); for ( c = 0 ; c < m ; c++ ) for ( d = 0 ; d < q ; d++ ) for ( k = 0 ; k < p ; k++ ) sum = sum + first[c][k]*second[k][d]; multiply[c][d] = sum; sum = 0; printf("product of entered matrices:-\n"); for ( c = 0 ; c < m ; c++ ) for ( d = 0 ; d < q ; d++ ) printf("%d\t", multiply[c][d]); printf("\n");
31 return 0; OUTPUT Enter rows and columns of first matrix:3 3 Enter rows and columns of second matrix:3 3 Enter first matrix: Enter second matrix: The new matrix is:
32 12a. write a program to read a string and perform following operations on input string i. capitalise ii. find length iii. find last letter and first letter PROGRAMS CAPITALISE #include <stdio.h> void upper_string(char []); int main() char string[100]; printf("enter a string to convert it into upper case\n"); scanf(" %[^\n]s", string); upper_string(string); printf("the string in upper case: %s\n", string); return 0; void upper_string(char s[]) int c = 0; while (s[c]!= '\0') if (s[c] >= 'a' && s[c] <= 'z') s[c] = s[c] - 32; c++; FINDING LENGTH #include <stdio.h> int main() char s[1000], i; printf("enter a string: "); scanf("%s", s); for(i = 0; s[i]!= '\0'; ++i);
33 printf("length of string: %d", i); return 0; FIND FIRST AND LAST LETTER #include<stdio.h> #include<string.h> void main() int i, count = 0, pos1, pos2; char str[50], key, a[10]; printf("enter the string\n"); scanf(" %[^\n]s", str); printf("enter character to be searched\n"); scanf(" %c", &key); for (i = 0;i <= strlen(str);i++) if (key == str[i]) count++; if (count == 1) pos1 = i; pos2 = i; printf("%d\n", pos1 + 1); else pos2 = i; printf("%d\n", pos2 + 1);
34 13.a) Write a program to determine factorial of a numbers using recursion techniques ALGORITHM: Step 1: Start Step 2: Read number n Step 3: Call factorial(n) Step 4: Print factorial f Step 5: Stop factorial(n) Step 1: If n==1 then return 1 Step 2: Else f=n*factorial(n-1) Step 3: Return f FLOWCHART:
35 PROGRAM #include <stdio.h> long int multiplynumbers(int n); int main() int n; printf("enter a positive integer: "); scanf("%d", &n); printf("factorial of %d = %ld", n, multiplynumbers(n)); return 0; long int multiplynumbers(int n) if (n >= 1) return n*multiplynumbers(n-1); else return 1; OUTPUT Enter a positive integer: 6 Factorial of 6 = 720
36 14.a) Write a program to read values of three numbers a b c print the values of using pointers and print their memory addresses ALGORITHM: Step 1: Read a,b,c Step 2: [Assign the Address of a to pointer p, b to q, c to r] P=&a; Q=&b; R=&c; Step 3: Print The Value and address of A= *p, p; Print The Value and address of B= *q, q; Print The Value and address of c= *r, r; Stop FLOWCHART Start Read a, b, c p=&a; q=&b; r=&c Print the values and addresses of a,b,c Stop PROGRAM #include<stdio.h> int main()
37 int arr[10]; int *pa; //declare integer array //declare an integer pointer int i; pa=&arr[0]; //assign base address of array printf("enter array elements:\n"); for(i=0;i < 10; i++) printf("enter element %02d: ",i+1); scanf("%d",pa+i); //reading through pointer printf("\nentered array elements are:"); printf("\naddress\t\tvalue\n"); for(i=0;i<10;i++) printf("%08x\t%03d\n",(pa+i),*(pa+i)); return 0; OUTPUT
38 15.a) write a program to read 10 numbers and find sum of all elements of Array access the values of Array using integer pointer with pointer arithmetic ALGORITHM: Step1: Start Step 2: Declare variable Step 3: Take input numbers Step 4: Copy base address of array to pointer variable Step 5: Read array element from one by one Step 6: Calculate Sum Step 7: Array ends then top Start Step 8: Print sum of elements in array Step 9: stop FLOWCHART: Read array[] ptr=array i=0 to10 in steps of 1 sum = sum + *ptr; ptr++; Print sum Stop
39 PROGRAM #include <stdio.h> #include <malloc.h> void main() int i,n,sum=0; int *a; printf("enter the size of array A\n"); scanf("%d", &n); a=(int *) malloc(n*sizeof(int)); /*Dynamix Memory Allocation */ printf("enter Elements of First List\n"); for(i=0;i<n;i++) scanf("%d",a+i); /*Compute the sum of all elements in the given array*/ for(i=0;i<n;i++) sum = sum + *(a+i); printf("sum of all elements in array = %d\n", sum); OUTPUT
40 16a. Create a text file by name my data.txt and store a given file of text into created text file. ALGORITHM FLOWCHART PROGRAMS #include <stdio.h> void main() FILE *fptr; char name[20]; int age; float salary; /* open for writing */ fptr = fopen("emp.rec", "w"); if (fptr == NULL) printf("file does not exists \n");
41 return; printf("enter the name \n"); scanf("%s", name); fprintf(fptr, "Name = %s\n", name); printf("enter the age\n"); scanf("%d", &age); fprintf(fptr, "Age = %d\n", age); printf("enter the salary\n"); scanf("%f", &salary); fprintf(fptr, "Salary = %.2f\n", salary); fclose(fptr);
PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE
PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE 1. Write a C program to perform addition, subtraction, multiplication and division of two numbers. # include # include int a, b,sum,
More informationList of Programs: Programs: 1. Polynomial addition
List of Programs: 1. Polynomial addition 2. Common operations on vectors in c 3. Matrix operation: multiplication, transpose 4. Basic Unit conversion 5. Number conversion: Decimal to binary 6. Number conversion:
More informationUNIT III ARRAYS AND STRINGS
UNIT III ARRAYS AND STRINGS Arrays Initialization Declaration One dimensional and Two dimensional arrays. String- String operations String Arrays. Simple programs- sorting- searching matrix operations.
More informationWAP 10. WAP 11. WAP 12. WAP 13. WAP 14. WAP 15. WAP 16. WAP 1. : 17. WAP 18. WAP 19. WAP 20. WAP 21. WAP 22. WAP 23. WAP & 24. WAP
Contents 1. WAP to accept the value from the user and exchange the values.... 2 2. WAP to check whether the number is even or odd.... 2 3. WAP to Check Odd or Even Using Conditional Operator... 3 4. WAP
More informationStructured programming
Exercises 6 Version 1.0, 25 October, 2016 Table of Contents 1. Arrays []................................................................... 1 1.1. Declaring arrays.........................................................
More information'C' Programming Language
F.Y. Diploma : Sem. II [DE/EJ/ET/EN/EX] 'C' Programming Language Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define pointer. Write syntax
More informationF.E. Sem. II. Structured Programming Approach
F.E. Sem. II Structured Programming Approach Time : 3 Hrs.] Mumbai University Examination Paper Solution - May 13 [Marks : 80 Q.1(a) Explain the purpose of following standard library functions : [3] (i)
More informationUnit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?
1 What is an array? Explain with Example. What are the advantages of using an array? An array is a fixed-size sequenced collection of elements of the same data type. An array is derived data type. The
More informationLab Manual B.Tech 1 st Year
Lab Manual B.Tech 1 st Year Fundamentals & Computer Programming Lab Dev Bhoomi Institute of Technology Dehradun www.dbit.ac.in Affiliated to Uttrakhand Technical University, Dehradun www.uktech.in CONTENTS
More informationTHE BAPATLA ENGINEERING COLLEGE:: BAPATLA DEPARTMENT OF MCA. Subject name: C programing Lab. Subject code: MCA 107. LAB manual of c programing lab
THE BAPATLA ENGINEERING COLLEGE:: BAPATLA DEPARTMENT OF MCA Subject name: C programing Lab Subject code: MCA 107 LAB manual of c programing lab 1. Write a C program for calculating compound interest. #include
More informationQuestion Bank (SPA SEM II)
Question Bank (SPA SEM II) 1. Storage classes in C (Refer notes Page No 52) 2. Difference between function declaration and function definition (This question is solved in the note book). But solution is
More informationP.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)
FACULTY: Ms. Saritha P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) SUBJECT / CODE: Programming in C and Data Structures- 15PCD13 What is token?
More information/* Area and circumference of a circle */ /*celsius to fahrenheit*/
/* Area and circumference of a circle */ #include #include #define pi 3.14 int radius; float area, circum; printf("\nenter radius of the circle : "); scanf("%d",&radius); area = pi
More informationUnit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION
INTRODUCTION Decision Making and Looping Unit 5 In the previous lessons we have learned about the programming structure, decision making procedure, how to write statements, as well as different types of
More informationComputer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];
Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data
More informationBCSE1002: Computer Programming and Problem Solving LAB MANUAL
LABMANUAL BCSE1002: Computer Programming and Problem Solving LAB MANUAL L T P Course Type Semester Offered Academic Year 2018-2019 Slot Class Room Faculty Details: Name Website link Designation School
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate
More informationClassification s of Data Structures
Linear Data Structures using Sequential organization Classification s of Data Structures Types of Data Structures Arrays Declaration of arrays type arrayname [ arraysize ]; Ex-double balance[10]; Arrays
More informationQ 1. Attempt any TEN of the following:
Subject Code: 17212 Model Answer Page No: 1 / 26 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The
More informationLABORATORY MANUAL. (CSE-103F) FCPC Lab
LABORATORY MANUAL (CSE-103F) FCPC Lab Department of Computer Science & Engineering BRCM College of Engineering & Technology Bahal, Haryana Aim: Main aim of this course is to understand and solve logical
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities
PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities Continuous Internal Evaluation Test 2 Date: 0-10- 2017 Marks: 0 Subject &
More informationTribhuvan University Institute of Science and Technology 2065
1CSc.102-2065 2065 Candidates are required to give their answers in their own words as for as practicable. 1. Draw the flow chart for finding largest of three numbers and write an algorithm and explain
More informationSubject: Fundamental of Computer Programming 2068
Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find
More informationCGS 3460 Summer 07 Midterm Exam
Short Answer 3 Points Each 1. What would the unix command gcc somefile.c -o someotherfile.exe do? 2. Name two basic data types in C. 3. A pointer data type holds what piece of information? 4. This key
More informationonly in the space provided. Do the rough work in the space provided for it. The question paper has total 12 pages.
Instructions: Answer all five questions. Total marks = 10 x 2 + 4 x 10 = 60. Time = 2hrs. Write your answer only in the space provided. Do the rough work in the space provided for it. The question paper
More information1) Write a C Program to check whether given year is Leap year or not. AIM: A C Program to check whether given year is Leap year or not.
1) Write a C Program to check whether given year is Leap year or not. AIM: A C Program to check whether given year is Leap year or not. #include int year; printf("enter a year:"); scanf("%d",&year);
More informationWrite a C program using arrays and structure
03 Arrays and Structutes 3.1 Arrays Declaration and initialization of one dimensional, two dimensional and character arrays, accessing array elements. (10M) 3.2 Declaration and initialization of string
More informationF.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C
F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1 (a) List any four relational operators.
More informationITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University
ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 10: Arrays Readings: Chapter 9 Introduction Group of same type of variables that have same
More informationMODULE 2: Branching and Looping
MODULE 2: Branching and Looping I. Statements in C are of following types: 1. Simple statements: Statements that ends with semicolon 2. Compound statements: are also called as block. Statements written
More informationFunctions. Arash Rafiey. September 26, 2017
September 26, 2017 are the basic building blocks of a C program. are the basic building blocks of a C program. A function can be defined as a set of instructions to perform a specific task. are the basic
More informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays 1 What are Arrays? Arrays are our first example of structured data. Think of a book with pages numbered 1,2,...,400.
More informationCSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming
CSE101-Lec#18 Multidimensional Arrays Application of arrays Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Defining and processing 1D array 2D array Applications of arrays 1-D array A
More informationComputer Programming Unit 3
POINTERS INTRODUCTION Pointers are important in c-language. Some tasks are performed more easily with pointers such as dynamic memory allocation, cannot be performed without using pointers. So it s very
More informationPrinciples of C and Memory Management
COMP281 Lecture 8 Principles of C and Memory Management Dr Lei Shi Last Lecture Pointer Basics Previous Lectures Arrays, Arithmetic, Functions Last Lecture Pointer Basics Previous Lectures Arrays, Arithmetic,
More informationINDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator EXAMINATION ( End Semester ) SEMESTER ( Spring ) Roll Number Section Name Subject Number C S 1 0 0 0 1 Subject Name Programming
More informationScheme of valuations-test 3 PART 1
Scheme of valuations-test 3 PART 1 1 a What is string? Explain with example how to pass string to a function. Ans A string constant is a one-dimensional array of characters terminated by a null ( \0 )
More information1. Basics 1. Write a program to add any two-given integer. Algorithm Code 2. Write a program to calculate the volume of a given sphere Formula Code
1. Basics 1. Write a program to add any two-given integer. Algorithm - 1. Start 2. Prompt user for two integer values 3. Accept the two values a & b 4. Calculate c = a + b 5. Display c 6. Stop int a, b,
More informationC Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function
More informationFloating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions
Announcements Thursday Extras: CS Commons on Thursdays @ 4:00 pm but none next week No office hours next week Monday or Tuesday Reflections: when to use if/switch statements for/while statements Floating-point
More informationUNDERSTANDING THE COMPUTER S MEMORY
POINTERS UNDERSTANDING THE COMPUTER S MEMORY Every computer has a primary memory. All our data and programs need to be placed in the primary memory for execution. The primary memory or RAM (Random Access
More informationBranching is deciding what actions to take and Looping is deciding how many times to take a certain action.
3.0 Control Statements in C Statements The statements of a C program control the flow of program execution. A statement is a command given to the computer that instructs the computer to take a specific
More informationM4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE
M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be
More informationIntroduction to Computing Lecture 07: Repetition and Loop Statements (Part II)
Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II) Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical & Electronics Engineering nukhet.ozbek@ege.edu.tr Topics
More informationArrays. Example: Run the below program, it will crash in Windows (TurboC Compiler)
1 Arrays General Questions 1. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array? A. The element will be set to 0. B. The compiler would
More informationProgramming and Data Structures Mid-Semester - Solutions to Sample Questions Dept. of Computer Science and Engg. IIT Kharagpur Spring
Programming and Data Structures Mid-Semester - s to Sample Questions Dept. of Computer Science and Engg. IIT Kharagpur Spring 2015-16 February 15, 2016 1. Tick the correct options. (a) Consider the following
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)
Subject Code: 17212 Model Answer Page No: 1/28 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate
More information// CSE/CE/IT 124 JULY 2015, 2.a. algorithm to inverse the digits of a given integer. Step 1: Start Step 2: Read: NUMBER Step 3: r=0,rev=0
// CSE/CE/IT 124 JULY 2015, 2a algorithm to inverse the digits of a given integer Step 1: Start Step 2: Read: NUMBER Step 3: r=0,rev=0 Step 4: repeat until NUMBER > 0 r=number%10; rev=rev*10+r; NUMBER=NUMBER/10;
More informationModule 6: Array in C
1 Table of Content 1. Introduction 2. Basics of array 3. Types of Array 4. Declaring Arrays 5. Initializing an array 6. Processing an array 7. Summary Learning objectives 1. To understand the concept of
More informationMCS-011. June 2014 Solutions Manual IGNOUUSER
MCS-011 June 2014 Solutions Manual IGNOUUSER 1 1. (a) Write an algorithm and draw corresponding flowchart to calculate the factorial of a given number. Factorial of a number n n! = 1*2*3*4*...*n Algorithm
More informationDeveloped By: P.Venkateshwarlu, Alphores Womens Degree College, Karimnagar
B.Sc (Computer Science) 1 sem Practical Solutions 1.Program to find biggest in 3 numbers using conditional operators. # include # include int a, b, c, big ; printf("enter three numbers
More informationGovernment Polytechnic Muzaffarpur.
Government Polytechnic Muzaffarpur. Name of the Lab: COMPUTER PROGRAMMING LAB (MECH. ENGG. GROUP) Subject Code: 1625408 Experiment: 1 Aim: Programming exercise on executing a C program. If you are looking
More informationEx. No. 3 C PROGRAMMING
Ex. No. 3 C PROGRAMMING C is a powerful, portable and elegantly structured programming language. It combines features of a high-level language with the elements of an assembler and therefore, suitable
More informationArrays. Arrays are of 3 types One dimensional array Two dimensional array Multidimensional array
Arrays Array is a collection of similar data types sharing same name or Array is a collection of related data items. Array is a derived data type. Char, float, int etc are fundamental data types used in
More informationBITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER
BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER 2017-2018 COURSE : COMPUTER PROGRAMMING (CS F111) COMPONENT : Tutorial#4 (SOLUTION) DATE : 09-NOV-2017 Answer 1(a). #include
More informationUnit III Functions. C functions can be classified into two categories, namely, library functions and user defined functions.
Unit III Functions Functions: Function Definition, Function prototype, types of User Defined Functions, Function calling mechanisms, Built-in string handling and character handling functions, recursion,
More informationIndian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : Mid-Semester Examination
Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn 2017-18: Mid-Semester Examination Time: 2 Hours Full Marks: 60 INSTRUCTIONS 1. Answer ALL questions 2. Please write
More informationC Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }
C Program Output #include main () { printf ( Hi everyone\n ); Hi everyone #include main () { printf ( Hi everyone\n ); #include and main are Keywords (or Reserved Words) Reserved Words
More informationArrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection
Morteza Noferesti Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful
More informationint Return the number of characters in string s.
1a.String handling functions: Function strcmp(const char *s1, const char *s2) strcpy(char *s1, const char *s2) strlen(const char *) strcat(char *s1, Data type returned int Task Compare two strings lexicographically.
More informationEngineering 12 - Spring, 1999
Engineering 12 - Spring, 1999 1. (18 points) A portion of a C program is given below. Fill in the missing code to calculate and display a table of n vs n 3, as shown below: 1 1 2 8 3 27 4 64 5 125 6 216
More informationMODULE V: POINTERS & PREPROCESSORS
MODULE V: POINTERS & PREPROCESSORS INTRODUCTION As you know, every variable is a memory-location and every memory-location has its address defined which can be accessed using ampersand(&) operator, which
More informationME 172. C Programming Language Sessional Lecture 8
ME 172 C Programming Language Sessional Lecture 8 Functions Functions are passages of code that have been given a name. C functions can be classified into two categories Library functions User-defined
More informationIntroduction: The Unix shell and C programming
Introduction: The Unix shell and C programming 1DT048: Programming for Beginners Uppsala University June 11, 2014 You ll be working with the assignments in the Unix labs. If you are new to Unix or working
More informationDECISION CONTROL AND LOOPING STATEMENTS
DECISION CONTROL AND LOOPING STATEMENTS DECISION CONTROL STATEMENTS Decision control statements are used to alter the flow of a sequence of instructions. These statements help to jump from one part of
More informationArrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]
(November 10, 2009 2.1 ) Arrays An array is a collection of several elements of the same type. An array variable is declared as type array name[size] I The elements are numbered as 0, 1, 2... size-1 I
More informationSubject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100
Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space
More informationPESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities
SOLUTION OF CONTINUOUS INTERNAL EVALUATION TEST -1 Date : 27-02 2018 Marks:60 Subject & Code : Programming in C and Data Structures- 17PCD23 Name of faculty : Dr. J Surya Prasad/Mr. Naushad Basha Saudagar
More informationWhat is recursion. WAP to find sum of n natural numbers using recursion (5)
DEC 2014 Q1 a What is recursion. WAP to find sum of n natural numbers using recursion (5) Recursion is a phenomenon in which a function calls itself. A function which calls itself is called recursive function.
More informationUNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Midterm Examination October 20, 2011 6:15 p.m. 8:00 p.m. (105 minutes) Examiners: J. Anderson, T. Fairgrieve,
More informationPESIT Bangalore South Campus Hosur road, 1km before ElectronicCity, Bengaluru -100 Department of Basic Science and Humanities
INTERNAL ASSESSMENT TEST-3 Date : 12-05-2016 Marks: 40 Subject & Code : Programming in C and data structures (15PCD23) Sec : F,G,H,I,J,K Name of faculty :Dr J Surya Prasad/Mr.Sreenath M V/Ms.Monika/ Time
More informationMTH 307/417/515 Final Exam Solutions
MTH 307/417/515 Final Exam Solutions 1. Write the output for the following programs. Explain the reasoning behind your answer. (a) #include int main() int n; for(n = 7; n!= 0; n--) printf("n =
More informationF.E. Sem - 2 CBCGS SPA MAY 17
F.E. Sem 2 CBCGS SPA MAY 17 Q.1.a.) Convert 0010 0100 0010 1101 from base 2 to decimal. Convert 134 from base 10 to hexadecimal. Write steps for conversion. Ans: Binary to decimal: The steps to be followed
More informationProgramming & Data Structure Laboratory. Day 2, July 24, 2014
Programming & Data Structure Laboratory Day 2, July 24, 2014 Loops Pre and post test loops for while do-while switch-case Pre-test loop and post-test loop Condition checking True Loop Body False Loop Body
More informationC PROGRAMMING. Prof. (Dr.) S. N. Mishra (Prof. & Head, Dept. of CSEA, IGIT, Sarang)
LAB MANUAL C MING Prof. (Dr.) S. N. Mishra (Prof. & Head, Dept. of CSEA, IGIT, Sarang) C MING LAB Experiment No. 1 Write a C program to find the sum of individual digits of a positive integer. Experiment
More informationProgramming in C Lab
Lab Manual for Programming in C Lab 2139 Diploma In Computer Engineering 2 nd Semester By SITTTR Kalamassery STATE INSTITUTE OF TECHNICAL TEACHERS TRAINING AND RESEARCH 2 GENERAL INSTRUCTIONS Rough record
More informationQuestions Bank. 14) State any four advantages of using flow-chart
Questions Bank Sub:PIC(22228) Course Code:-EJ-2I ----------------------------------------------------------------------------------------------- Chapter:-1 (Overview of C Programming)(10 Marks) 1) State
More informationChapter 8. Arrays, Addresses, and Pointers : Structured Programming Structured Programming 1
Chapter 8 Arrays, Addresses, and Pointers 204112: Structured Programming 204112 Structured Programming 1 Pointer Pointer is a variable that contains an address. If num_ptr is a pointer, *num_ptr means
More informationF.E. Sem. II. Structured Programming Approach
F.E. Sem. II Structured Programming Approach Time : 3 Hrs.] Mumbai University Examination Paper Solution - May 14 [Marks : 80 Q.1(a) What do you mean by algorithm? Which points you should consider [4]
More informationArrays and Pointers. CSE 2031 Fall November 11, 2013
Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example
More informationEssar Placement Paper
Essar Placement Paper Question 1 The fourth proportional to 5, 8, 15 is: A. 18 B. 24 C. 19 D. 20 Let the fourth proportional to 5, 8, 15 be x. Then, 5 : 8 : 15 : x 5x = (8 x 15) x=(8*15)/5=24 Question
More informationSorting & Searching. Hours: 10. Marks: 16
Sorting & Searching CONTENTS 2.1 Sorting Techniques 1. Introduction 2. Selection sort 3. Insertion sort 4. Bubble sort 5. Merge sort 6. Radix sort ( Only algorithm ) 7. Shell sort ( Only algorithm ) 8.
More informationM3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE
M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be
More informationProgramming & Data Structure Laboratory. Arrays, pointers and recursion Day 5, August 5, 2014
Programming & Data Structure Laboratory rrays, pointers and recursion Day 5, ugust 5, 2014 Pointers and Multidimensional rray Function and Recursion Counting function calls in Fibonacci #include
More informationThe C language. Introductory course #1
The C language Introductory course #1 History of C Born at AT&T Bell Laboratory of USA in 1972. Written by Dennis Ritchie C language was created for designing the UNIX operating system Quickly adopted
More informationA. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS
Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization
More informationIntroduction to Programming. Sample Question Paper. Q. 1. a). What is an algorithm? 2.5 X10
Introduction to Programming Sample Question Paper Note: Q.No. 1 is compulsory, attempt one question from each unit. Q. 1. a). What is an algorithm? 2.5 X10 b) What do you mean by Program? Write a small
More informationSample Paper - II Subject Computer Science
Sample Paper - II Subject Computer Science Max Marks 70 Duration 3 hrs Note:- All questions are compulsory Q1) a) What is significance of My Computer? 2 b) Explain different types of operating systems.
More informationMODULE 3: Arrays, Functions and Strings
MODULE 3: Arrays, Functions and Strings Contents covered in this module I. Using an Array II. Functions in C III. Argument Passing IV. Functions and Program Structure, locations of functions V. Function
More informationContent. In this chapter, you will learn:
ARRAYS & HEAP Content In this chapter, you will learn: To introduce the array data structure To understand the use of arrays To understand how to define an array, initialize an array and refer to individual
More informationMA 511: Computer Programming Lecture 3: Partha Sarathi Mandal
MA 511: Computer Programming Lecture 3: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11 Last
More informationIosif Ignat, Marius Joldoș Laboratory Guide 4. Statements. STATEMENTS in C
STATEMENTS in C 1. Overview The learning objective of this lab is: To understand and proper use statements of C/C++ language, both the simple and structured ones: the expression statement, the empty statement,
More informationECE15: Introduction to Computer Programming Using the C Language Lecture 6: Arrays
ECE15: Introduction to Computer Programming Using the C Language Lecture 6: Arrays A. Orlitsky and A. Vardy, based in part on slides by S. Arzi, G. Ruckenstein, E. Avior, S. Asmir, and M. Elad Outline
More informationPROGRAMMING IN C AND C++:
PROGRAMMING IN C AND C++: Week 1 1. Introductions 2. Using Dos commands, make a directory: C:\users\YearOfJoining\Sectionx\USERNAME\CS101 3. Getting started with Visual C++. 4. Write a program to print
More informationMODULE 1. Introduction to Data Structures
MODULE 1 Introduction to Data Structures Data Structure is a way of collecting and organizing data in such a way that we can perform operations on these data in an effective way. Data Structures is about
More informationBasic Assignment and Arithmetic Operators
C Programming 1 Basic Assignment and Arithmetic Operators C Programming 2 Assignment Operator = int count ; count = 10 ; The first line declares the variable count. In the second line an assignment operator
More information1. Write a C program that receives 10 float numbers from the console and sort them in nonascending order, and prints the result
Solutions 1. Write a C program that receives 10 float numbers from the console and sort them in nonascending order, and prints the result #include int main() //Program Start float numbers[10],result;
More informationESC101N: Fundamentals of Computing End-sem st semester
ESC101N: Fundamentals of Computing End-sem 2010-11 1st semester Instructor: Arnab Bhattacharya 8:00-11:00am, 15th November, 2010 Instructions 1. Please write your name, roll number and section below. 2.
More informationAROUND THE WORLD OF C
CHAPTER AROUND THE WORLD OF C 1 1.1 WELCOME TO C LANGUAGE We want to make you reasonably comfortable with C language. Get ready for an exciting tour. The problem we would consider to introduce C language
More information