(XII) Computer Science Lab Questions List

click here to know about Homework Rubrics
Order of pages (for each lab sheet/report)
  1. Folder and practical index sheet provided by the college
  2. Click here to download cover page and Lab Sheet title Page
  3. Objectives (write a paragraph-handwritten)
  4. Table of contents with page number
    • Theory (handwritten)
    • Program code (hand written)
    • sample Output screenshot including a statement "Program Written by Student Name"(Printed)
  5. Discussion and conclusion(Handwritten)
Point to Remember while preparing lab report :
  1. Use A4 size white paper only
  2. Only coverpage and output screenshot should be in printed format, other all parts must be handwritten.
    You must write manually; computerized reports will not be accepted!
  3. Write on one side/front only; the back side must be blank.
  4. Click here to view C lab report Sample

Lab Work - 1 (Function)

Lab Date : 12 July 2023
Submission Date : 19 July 2023 , Wednesday
  1. Write C program to find sum of two numbers using function named sum().
  2. #include<stdio.h> int sum(int a, int b); int main() { int a,b,c; printf("Enter two numbers:"); scanf("%d%d",&a,&b); c=sum(a,b); printf("Sum of two numbers = %d",c); return 0; } int sum(int a, int b) { int p; p=a+b; return (p); }
  3. Write C program to know a number is even or odd using function named evenodd().
  4. #include<stdio.h> void even_odd(int n); main() { int n; printf("Enter a number :"); scanf("%d",&n); even_odd(n); } void even_odd(int n) { if(n%2==0) printf("Even"); else printf("Odd"); }
  5. Write C program to print the greatest value among three numbers using a function int great(). We have to use return statement.
  6. #include<stdio.h> int great(int a, int, int c); int main() { int a,b,c,d; printf("Enter three numbers : "); scanf("%d%d%d",&a,&b,&c); d=great(a,b,c); printf("greatest number is %d",d); return 0; } int great(int a, int b, int c) { if(a>b && a>c) return a; else if (b>c) return b; else return c; }
  7. Write C program to know a number is prime or composite using function.
  8. #include<stdio.h> void test(int n); main() { int n; printf("Enter a number :"); scanf("%d",&n); test(n); } void test(int n) { int i,c=0 ; for(i=1;i<=n;i++) { if(n%i==0) c++; } if(c==2) printf("Prime"); else printf("not prime or composite"); }
  9. Write C program to find sum of series 1,2,3,…..200 using function. Assume yourself function name. It returns an integer value.
  10. #include<stdio.h> int sum(); int main() { printf("the sum is=%d",sum()); return 0; } int sum() { int s=0,i; for(i=1;i<=200;i++) { s=s+i; } return s; }
  11. Write C program to input elements of an array and print them with their sum. Suppose, the array is one dimensional and is of void type and function to be used is array_elements().
  12. #include<stdio.h> void array_elements(int a[]); int main() { int a[5],i,ans; for(i=0;i<5;i++) { printf("Enter num[%d] : ",i+1); scanf("%d",&a[i]); } array_elements(a); return 0; } void array_elements(int a[]) { int s=0,i; for(i=0;i<5;i++) { s=s+a[i]; } printf("Sum=%d",s); }
  13. Suppose a function void matrix_sum(int a[][],int b[][]).Here, we have passed array as parameter. Use this function to find sum of matrices.
  14. #include<stdio.h> void matrix_sum(int a[][3],int b[][3]); main() { int a[3][3],b[3][3],i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("Enter b[%d][%d] : ",i,j); scanf("%d",&a[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("Enter b[%d][%d] : ",i,j); scanf("%d",&b[i][j]); } } matrix_sum(a,b); } void matrix_sum(int a[][3],int b[][3]) { int c[3][3],i,j; printf("\n sum of two 3x3 matrices: \n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=a[i][j]+b[i][j]; printf(" %d\t ",c[i][j]); } printf("\n"); } }
  15. Write C program to sort ‘n’ number of strings using function. Pass strings as parameter.
  16. #include<stdio.h> #include<string.h> void sort(char str[][20],int n); main() { char str[50][20]; int i,n; printf(" How many strings : "); scanf("%d",&n); for(i=0;i<n;i++) { printf(" Enter str[%d] : ",i+1); scanf("%s",str[i]); } sort(str,n); } void sort( char str[][20],int n) { int i,j; char temp[20]; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(strcmp(str[i],str[j])>0) { strcpy(temp,str[i]); strcpy(str[i],str[j]); strcpy(str[j],temp); } } } printf(" Sorted strings are : \n"); for(i=0;i<n;i++) printf(" %s\n ",str[i]); }
  17. Write C program to find factorial value of a number using recursive function.
  18. #include<stdio.h> int fact(int); main() { int n,ans; printf( "Enter any number : "); scanf("%d",&n); ans=fact(n); printf(" Factorial of %d is %d ",n,ans); } int fact(int n) { if(n<=1) return (1); else return(n*fact(n-1)); }

Lab Work - 2 (Structure and Unions)

Lab Date : 20 July 2023
Submission Date : 27 July 2023 , Thursday
  1. Write C program to input id, name and grade for 10 students. Then print them. Use array of structure concept.
  2. #include<stdio.h> struct student { int id; char name[30]; int grade; } s[10]; main() { int i; for(i=0;i<10;i++) { printf("Enter student id,name and grade : "); scanf("%d%s%d",&s[i].id,s[i].name,&s[i].grade); } printf("-------Output-------\n"); printf("ID\t Name\t Grade\n"); for(i=0;i<10;i++) { printf("%d\t %s\t %d\n",s[i].id,s[i].name,s[i].grade); } }
  3. Write C program to input 20 employees name, post and salary. Then search a record of an employee on the basis of name.
  4. #include<stdio.h> #include<string.h> struct employee { char name[30]; char post[30]; int salary; } e[20]; main() { int i,flag=0; char search_name[30]; for(i=0;i<20;i++) { printf("Enter employee name,post and salary : "); scanf("%s%s%d",e[i].name,e[i].post,&e[i].salary); } printf("Enter name to search: "); scanf("%s",search_name); for(i=0;i<20;i++) { if(strcmp(e[i].name,search_name)==0) printf("%s\t %s\t %d\n",e[i].name,e[i].post,e[i].salary); flag=1; } if(flag==0) printf("Record not found"); }
  5. We have two structures as given below. Struct employee { Char ename[100]; Char eaddress[100]; }; Struct salarydetails { Char pos[100]; float salary; struct employee detail; }payinfo; Write C program to input employees’ details with salary then print them. Use nested struct concept.
  6. #include<stdio.h> struct employee { char ename[100]; char eaddress[100]; }; struct salarydetails { char post[100]; float salary; struct employee detail; }payinfo; main() { printf("Enter employee name,address,post and salary : "); scanf("%s%s%s%f",payinfo.detail.ename,payinfo.detail.eaddress,payinfo.post,&payinfo.salary); printf("Employee Name : %s\n",payinfo.detail.ename); printf("Address : %s\n",payinfo.detail.eaddress); printf("Post: %s\n",payinfo.post); printf("Salary: %f",payinfo.salary); }
  7. Write C program to input id, name and address of 20 students using struct. Then print them in sorted format on the basis of name.
  8. #include<stdio.h> #include<string.h> struct student { int id; char name[30]; char address[30]; }s[20]; int main() { struct student temp; int i,j; for(i=0;i<20;i++) { printf("Enter id, name and address: "); scanf("%d%s%s",&s[i].id,s[i].name,s[i].address); } for(i=0;i<19;i++) { for(j=i+1;j<20;j++) { if(strcmp(s[i].name,s[j].name)>0) { temp=s[i]; s[i]=s[j]; s[j]=temp; } } } printf("Records in Sorted order by Name \n"); for(i=0;i<20;i++) { printf("%d\t %s\t %s\n ",s[i].id,s[i].name,s[i].address); } return 0; }
  9. Write C program to input any 10 teacher’s id, name and subject using ‘typedef’ and structure. Then print them on screen.
  10. #include<stdio.h> typedef struct teacher { int id; char name[50]; char subject[50]; }t; main() { t s[10]; int i; for(i=0;i<10;i++) { printf("Enter [%d] teacher id, name and subject : ",i+1); scanf("%d%s%s",&s[i].id,s[i].name,s[i].subject); } printf("ID\t Name\t Subject\n"); for(i=0;i<10;i++) { printf("%d\t%s\t%s\n",s[i].id,s[i].name,s[i].subject); } }
  11. Write C program using function and structure to calculate sum of two distances measured in terms of kilometers and meters. For example, If we input following data Kilometer meter 23 445 45 756
    69 201 The output would be 69 km and 201 meters.
  12. #include<stdio.h> struct distance { int km; int m; }d1,d2,total; void sum(struct distance dis1,struct distance dis2); main() { printf("Enter first distance : "); Go to top scanf("%d%d",&d1.km,&d1.m); printf("Enter second distance : "); scanf("%d%d",&d2.km,&d2.m); sum(d1,d2); return 0; } void sum(struct distance dis1,struct distance dis2) { total.m=(dis1.m+dis2.m)%1000; total.km=dis1.km+dis2.km+(dis1.m+dis2.m)/1000; printf("Total km=%d m=%d",total.km,total.m); }
  13. Write C program to input student id, name and grade and print them. Use union concept.
  14. #include<stdio.h> union student { int id; char name[30]; int grade; } s; main() { printf("Enter student id: "); scanf("%d",&s.id); printf("Student ID: %d\n ",s.id); printf("Enter name : "); scanf("%s",s.name); printf("Name : %s\n",s.name); printf("Enter grade : "); scanf("%d",&s.grade); printf("Grade : %d\n",s.grade); }

Lab Work - 3 (Pointer)

  1. Write C program to perform arithmetic calculations (sum, difference, multiplication and division) of two numbers using pointers.
  2. #include<stdio.h> main() { int num1,num2,sum,diff,mul,div,*x,*y; printf("Enter two numbers : "); scanf("%d%d",&num1,&num2); x=&num1; y=&num2; sum=*x + *y; diff=*x - *y; mul=*x * *y; div=(*x) / (*y); printf("Sum=%d\n",sum); printf("Difference=%d\n",diff); printf("Multiplication=%d\n",mul); printf("Division=%d\n",div); }
  3. Write C program to know a number is even or odd using pointer.
  4. #include<stdio.h> main() { int num,*n; printf("Enter any number: "); scanf("%d",&num); n=&num; if(*n % 2==0) printf("even"); else printf("odd"); }
  5. Write C program to find sum and average of ‘n’ natural numbers using pointer.
  6. #include<stdio.h> main() { int *p; int n,i,sum=0,avg=0; p=&n; printf("Enter value of n: "); scanf("%d",&n); p=&n; for(i=1;i<=*p;i++) { sum=sum+i; } avg=sum/(*p); printf("Sum=%d\n",sum); printf("Average=%d\n",avg); }
  7. Write C program by using array to input 10 elements and print them. Use array as pointer.
  8. #include<stdio.h> main() { int i,arr[10]; for(i=0;i<10;i++) { printf("Enter arr[%d] : ",i); scanf("%d",(arr+i)); } for(i=0;i<10;i++) { printf("%d\n",*(arr+i)); } }
  9. Write C program to input 10 elements and print maximum and minimum value. Use array as pointer.
  10. #include<stdio.h> main() { int i,arr[10],max,min; for(i=0;i<10;i++) { printf("Enter arr[%d] : ",i); scanf("%d",(arr+i)); } max=*(arr+0); min=*(arr+0); for(i=0;i<10;i++) { if(*(arr+i)>max) max=*(arr+i); if(*(arr+i)<min) min=*(arr+i); } printf("Maximum number = %d \n Minimum number = %d",max,min); }
  11. Write C program to swap two values using call by reference and call by value.
  12. //program to show call by value #include<stdio.h> void swap(int a, int b); main() { int a = 10, b= 20; swap(a,b); printf("Call by value\n"); printf(" After swapping a = %d and b= %d ",a,b); } void swap(int a, int b) { int t; t = a; a = b; b = t; } //program to show call by reference #include<stdio.h> void swap(int *a, int *b); main() { int a = 10, b= 20; swap(&a,&b); // call by reference printf("Call by reference\n"); printf(" After swapping a = %d and b= %d ",a,b); } void swap(int *a, int *b) { int t; t = *a; *a = *b; *b = t; }
  13. Write C program to sort 10 numbers stored in an array using pointer.
  14. #include<stdio.h> main() { int *p; int num[10],i,j,temp; for(i=0;i<10;i++) { printf("Enter num[%d] : ",i+1); scanf("%d",(num+i)); } for(i=0;i<9;i++) { for(j=i+1;j<10;j++) { if(*(num+i)>*(num+j)) { temp=*(num+i); *(num+i)=*(num+j); *(num+j)=temp; } } } printf("Sorted in Ascending Order \n"); for(i=0;i<10;i++) { printf("%d\n",*(num+i)); } }
  15. Write C program to print multiplication table of a number using pointer.
  16. #include<stdio.h> main() { int num,i; int *p ; printf(" Enter any number : ") ; scanf("%d",&num); p = &num; for(i=1;i<=10;i++) { printf(" %d\n ",(*p * i)) ; } }

Lab Work - 4 (File Handling)

  1. Write C program to input a sentence and store data in a data file “file.txt”. And print them on screen. Use getc() and putc() functions.
  2. #include<stdio.h> main() { FILE *fp; char ch; printf("\n Input data (to exit press ctrl+z)="); fp=fopen("f.txt","w"); while((ch=getchar())!=EOF){ putc(ch,fp); } fclose(fp); printf("\n Output data\n "); fp=fopen("f.txt","r"); while((ch=getc(fp))!=EOF){ putchar(ch); } fclose(fp); }
  3. Write C program to store some ‘n’ natural numbers in a data file and print them on screen. Use getw() function. Also print their average.
  4. #include<stdio.h> main() { FILE *fp; int i,n,sum=0,avg=0; fp=fopen("file.txt","w"); printf("Enter the value of n: "); scanf("%d",&n); for(i=1;i<=n;i++) { putw(i,fp); } fclose(fp); printf("Press enter to view numbers :"); printf("\n Output data\n "); fp=fopen("file.txt","r"); while((i=getw(fp))!=EOF){ sum=sum+i; printf(" %d\n ",i); } avg=sum/n; fclose(fp); printf("\n Average = %d ",avg); }
  5. Write C program to store student’s name and address in a data file “student.txt”. Use fprintf() function. Then read contents of data file and print them on screen. Use fscanf() function.
  6. #include<stdio.h> main() { char name[30],add[30]; FILE *fp; fp=fopen("student.txt","w"); printf("Enter name and address : "); scanf("%s%s",name,add); fprintf(fp,"%s\t %s",name,add); fclose(fp); fp=fopen("student.txt","r"); fscanf(fp,"%s\t %s",name,add); printf("\n -----Ouput data -----\n "); printf("%s \t %s",name,add); fclose(fp); }
  7. Write C program to store book’s name, edition and price in a data file “book.txt” using yes/no options. It means the computer stores data until you say ‘n’. Then print them on screen.
  8. #include<stdio.h> main() { char b_name[30]; int b_edition; float b_price; char ch='y'; FILE *fp; fp=fopen("book.txt","w"); while(ch!='n') { printf("Enter book name : " ); scanf("%s",b_name); printf("Enter book edition : " ); scanf("%d",&b_edition); printf("Enter book price : " ); scanf("%f",&b_price); fprintf(fp,"%s\t %d\t %f\n",b_name,b_edition,b_price); printf("Add more records (y/n) : "); scanf(" %c",&ch); } fclose(fp); fp=fopen("book.txt","r"); while(fscanf(fp,"%s%d%f",b_name,&b_edition,&b_price)!=EOF) { printf(" %s\t %d\t %f\n ",b_name,b_edition,b_price); } fclose(fp); }
  9. Write C program to store employee’s name, position and salary in a data file “employee.txt” using fwrite(). The computer stores data until you say ‘n’. Then read the contents of that file and print on screen using fread().
  10. #include<stdio.h> struct employee{ char e_name[30]; char post[10]; float salary; }; main(){ struct employee emp; char ch; FILE *fp; fp=fopen("employee.txt","w"); while(ch!='n'){ printf(" Enter employee name:\n "); scanf("%s",emp.e_name); printf(" Enter employee post:\n "); scanf("%s",emp.post); printf(" Enter employee salary:\n "); scanf("%f",&emp.salary); fwrite(&emp,sizeof(emp),1,fp); printf("\n Add more record (y/n): "); scanf(" %c",&ch); } fclose(fp); fp=fopen("employee.txt","r"); printf("\n Data from the file: \n"); printf("\n Name\t Post \t Salary"); while(fread(&emp,sizeof(emp),1,fp)) { printf("\n %s\t %s\t %f",emp.e_name,emp.post,emp.salary); } printf("\n"); fclose(fp); }
  11. Write C program to input students’ name, grade and marks in five subjects. Then store these all data with total and percentage in a data file “student.dat”. Print all those data of students who have percentage >=80. You may use fscanf() or fwrite().
  12. #include<stdio.h> struct student { char name[30]; int grade; int sub1,sub2,sub3,sub4,sub5,total; float per; }s[10]; main() { int i,n; printf("How many records : "); scanf("%d",&n); FILE *fp; fp=fopen("student.dat","w"); for(i=0;i<n;i++) { printf("Enter name : "); scanf("%s",s[i].name); printf("Enter grade : "); scanf("%d",&s[i].grade); printf("Enter sub1 mark: "); scanf("%d",&s[i].sub1); printf("Enter sub2 mark: "); scanf("%d",&s[i].sub2); printf("Enter sub3 mark: "); scanf("%d",&s[i].sub3); printf("Enter sub4 mark: "); scanf("%d",&s[i].sub4); printf("Enter sub5 mark: "); scanf("%d",&s[i].sub5); s[i].total=s[i].sub1+s[i].sub2+s[i].sub3+s[i].sub4+s[i].sub5; s[i].per=(float)s[i].total/5; fprintf(fp,"%s %d %d %d %d %d %d %d %f\n",s[i].name,s[i].grade,s[i].sub1,s[i].sub2,s[i].sub3,s[i].sub4,s[i].sub5,s[i].total,s[i].per); } fclose(fp); printf("\n-----output-----\n"); fp=fopen("student.dat","r"); while(fscanf(fp,"%s %d %d %d %d %d %d %d %f\n ",s[i].name,&s[i].grade,&s[i].sub1,&s[i].sub2,&s[i].sub3,&s[i].sub4,&s[i].sub5,&s[i].total,&s[i].per)!=EOF) if(s[i].per>=80) { printf("\n Name: %s\n",s[i].name); printf("Grade:%d\n",s[i].grade); printf("Sub1 : %d\n",s[i].sub1); printf("Sub2 : %d\n",s[i].sub2); printf("Sub3 : %d\n",s[i].sub3); printf("Sub4 : %d\n",s[i].sub4); printf("Sub5 : %d\n",s[i].sub5); printf("Total:%d\n",s[i].total); printf("Percentage:%0.2f\n",s[i].per); } }
  13. Write C program to show the concept of rename() and remove() functions.
  14. #include<stdio.h> main() { FILE *fp; char name[30]; fp=fopen("oldfile.txt","w"); printf("\n Enter your name : "); scanf("%s",name); fprintf(fp,"%s",name); fclose(fp); rename("oldfile.txt","newfile.txt"); remove("newfile.txt"); }
  15. Write C program to show concept of ftell(), fseek() and rewind() functions.
  16. // Program of ftell () and rewind()

    #include<stdio.h> main () { char name [30]; int age, length; FILE *fp; fp = fopen ("trinity.txt","w"); printf("Enter your name: \n"); scanf("%s",name); printf("Enter your age: \n"); scanf("%d",&age); fprintf (fp, "%s %d", name,age); length = ftell(fp); rewind (fp); fscanf (fp, "%s", name); fscanf (fp, "%d", &age); fclose (fp); printf ("Name= %s \n Age= %d \n",name,age); printf ("Total number of characters in file is %d \n", length); }

    // Program of fseek ()

    #include<stdio.h> main () { FILE *fp; fp = fopen("test.txt", "r"); // Moving pointer to end fseek(fp, 0, SEEK_END); // Printing position of pointer printf("%ld", ftell(fp)); }

Lab Work - 5 (SQL)

Lab Work - 6 (Javascript)

Lab Work - 7 (PHP)

  1. Click here for sample C programming project work of XII
  2. Measurement Conversion php project
  3. php crud project
  4. Click here for Cover-page , title page and declaration page

Project Work Guidelines

If you are going to make a project in C/php & mysql, follow the order as given below. At the end of session students will be asked to prepare a project work on ‘web technology’/C. In this Project work students may choose to make a website using HTML , CSS, php,& mysql and javascript or simple application using C . Students may choose a topic of their own interest. Project work assessment is the internal assessment of reports and presentation of their project works either individually or on a group basis. In case of group presentation, every member of the group should submit a short reflection on the presented report in their own language.
1.1 Project work writing format:
Students have to follow the same format as given by college.

Formatting Guidelines for Project Work

Title page
Title of the project, name of the author(s), class, ID number, registration numbers, email, school name and address
Title
Capitalize each word. / Be clear, informative & concise. / Avoid abbreviations
Spacing
Double-space
Fonts
Times New Roman or Arial (Title – 14-point bold font / Body text – 12-point font)
Page Numbering
Bottom of the page, centre
Report structure
Divide body text into different sections with appropriate headings. Use standard headings as far as possible such as:

1. Introduction: Background, literature review, objectives & limitation · 2. Materials & Methods: Equipment used & data collection procedure 3. Results or Findings: Presentation, analysis and interpretation of data / Give important details in tables and figures. 4. Conclusions: Highlight key findings 5. Acknowledgements 6. References

Headings
Bold font on a separate line / No numbering for headings & subheadings
Paper
A4 size, white, one-sided printing
Page margins
Left 1.25”, Right 1”, Top 1”, Bottom 1”,Alignment-justify
Page Binding
Fixed Binding
Project work writing order (what to write and in what order): 1.cover page 2.project title page 3.Declaration page 4.Letter of approval page 5.Table of contents with page number 6. 6.1 Introduction: 6.1.1 Background, literature review, objectives & limitation:(write about objectives; write about existing system and faced problems and possible solutions; talk about system(computerized) you are going to develop and its benefits) 6.1.2 Talk about Planning,System study, Analysis, Feasibility study,system requirements 6.2 Materials & Methods: Equipment used & data collection procedure 6.2.1 talk about methods applied to gather data. Talk about materials used. 6.2.2 Represent everything diagrammatically/design part. You may use a context diagram or UML or flowchart to design the system. 6.3 Results or Findings: Presentation, analysis and interpretation of data / Give important details in tables and figures/graphs. 6.3.1 talk about system development and platforms used. Put all source codes here( four or five pages/modules codes). 6.3.2 put all screenshots here (any five/six would be enough). 6.4 Conclusions: Highlight key findings 6.5 Acknowledgements Acknowledgements enable you to thank all those who have helped in carrying out the research/work. Careful thought needs to be given concerning those whose help should be acknowledged and in what order. The general advice is to express your appreciation in a concise manner and to avoid strong emotive language. Note that personal pronouns such as 'I, my, me …' are nearly always used in the acknowledgements while in the rest of the project such personal pronouns are generally avoided. The following list includes those people who are often acknowledged. Note however that every project is different and you need to tailor your acknowledgements to suit your particular situation. Main supervisor Second supervisor Other academic staff in your department Technical or support staff in your department Academic staff from other departments Other institutions, organizations or companies Past students Family Friends 7.References / Bibliography ----------------------------------------- Notes:- 1. Use passive voice while writing 2. Use third person (do not use I or we; instead use “it was done”) 3. Use proper formatting (justify) 4. If you need then you can use header and footer properly 5. Do not mix/use colors. Make it as simple as it has to be. 6.The topic for the website/C project should be chosen by the students themselves. Additionally:- 1. You have to make the same format as given there 2. no copying or direct printing 3. On your exam day, bring all the works done (project work)in pen drive as well as in hardcopy. We may ask you to show a softcopy.