You are on page 1of 10

a.Execute the following using UNIX Commands: 1.To print the present working directory : pwd 2.

To create a directory mkdir <filename> 3.To change the directory cd <filename> 4.To copy files cp <sourcefilename> <destinationfilename> 5.To concatenate two files cat filename1 filename2 >>filename3 6.To change the permission of the file chmod 777 <filename> 7.To find out who's logged in who 8.To view one page of the file cat <filename> | more 9.To view first 10 lines of the file head -10 <filename> 10.To view last 10 lines of the file tail -10 <filename> 11.To view the commands which was executed history 12.To clear the screen clear 13.List all filenames which has dot at the end ls *. 14.List all filenames which has an extension ls *.* 15.Find the subdirectories available in the present working directory ls d 16.Display all files, sub directories and files in subdirectories including their sizes

ls l or ls -R 17.To print the calendar cal 18.To print the date and time date 19.To change the password passwd 20.To print presently who is using the system who am i 21.To append the contents of one file into another cat filename1 >>filename2 22To link files ln filename1 filename2 23.To display the file attributes ls l 24.To append more than one file cat filename1 filename2 filename3>>filename4 To list files and directories, recursively on a single line ls -R To view the files page by page ls l | more To move the files mv <sourcefile> <destinationfile> To remove an empty directory rmdir <directory name> Print the calendar for 2012 for the month July cal 7 2012 Store the output of date command in a file called date. out date>date.out cat date.out Sort the files in alphabetical order ls s or ls sort

Show manual for a command man <command> Change the file to read only mode chmod 444 <filename> Copy the directory and its file to the other directory cp R * <entiredestinationpath> example; cp R * /home/exam01/tmp Change the mode of the file, where the changed file should posses all the permission use chmod command List all files in current directory whose second character is a digit ls ?[0-9]* Print todays date and the calendar of the current month using single command date&&cal

b.Shell Program 20 Marks


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. Write a shell program to find the sum and average of four integers Write a shell program to compute simple interest and compound interest. Write a shell program to swap two numbers Write a shell program to compute the power of x. Write a shell program to check whether a given year is leap year or not. Write a shell program to find whether the given number is odd or even Write a shell program to check whether the given number is positive or negative. Write a shell program to find the quotient and remainder of two numbers Write a shell program to check whether a number is divisible by 5 Write a shell program to check whether a number is divisible by 5 Write a shell program to find the GCD of numbers Write a shell program to find the factorial of a number Write a shell program to reverse the digits of a number Write a shell program to find the sum of the digits of a given number Write a shell program to find the greatest among three numbers Write a shell program to print the first N even numbers Write a shell program to print the first N odd numbers. Write a shell program to print the first N prime numbers. Write a shell program to print the first N numbers divisible by 4 Write a shell program to print the factorial of first N numbers

C Program : 50 Marks 1. Develop a C program to compute the roots of a quadratic equation #include<stdio.h> #include<math.h>

main() { int i,n=0; float a,b,c,d,x1,x2; printf("Enter value for a"); scanf("%d",&a); printf("Enter value for b"); scanf("%d",&b); printf("Enter value for c"); scanf("%d",&c); d=sqrt(b*b-4*a*c); x1=(-b+d)/(2*a); x2=(-b-d)/(2*a); printf("x1=%f x2=%f",x1,x2); }
2. Write a C program to compute the transpose of a matrix

#include<stdio.h> main() { int a[10][10],b[10][10],i,j,m,n; printf("Enter no of rows"); scanf("%d",&m); printf("Enter no of columns"); scanf("%d",&n); printf(enter values for matrix); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); }} //transpose of a matrix for(i=0;i<m;i++) { for(j=0;j<n;j++)

{ b[i][j]=a[j][i]; }} //print transpose matrix for(i=0;i<n;i++) for(j=0;j<n;j++) printf("%d",b[i][j]); }


3. Write a C program to perform matrix addition #include<stdio.h> main() { int a[10][10],b[10][10],c[10][10],i,j,m,n; printf("Enter no of rows"); scanf("%d",&m); printf("Enter no of columns"); scanf("%d",&n); //first matrix printf("enter the values for first matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); }} //second matrix printf("Enter the values for second matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&b[i][j]); }} //addition of a matrix for(i=0;i<m;i++) { for(j=0;j<n;j++) { c[i][j]=a[i][j]+b[i][j]; }} //print resultant matrix for(i=0;i<n;i++) for(j=0;j<n;j++)

printf("%d",c[i][j]); } 4.

Write a C program to perform matrix multiplication.

#include<stdio.h> main() { int a[10][10],b[10][10],c[10][10],i,j,m,n; printf("Enter no of rows"); scanf("%d",&m); printf("Enter no of columns"); scanf("%d",&n); //first matrix printf("enter the values for first matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); }} //second matrix printf("Enter the values for second matrix\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&b[i][j]); c[i][j]=0; }} //multiplication of a matrix for(i=0;i<m;i++) { for(j=0;j<n;j++) { c[i][j]=c[i][j]+(a[i][j]*b[i][j]); }} //print resultant matrix for(i=0;i<n;i++) for(j=0;j<n;j++) printf("%d",c[i][j]); }

5. Develop a C function that will scan a character string passed as an argument and convert all lower-case characters to their upper-case equivalents.

#include<stdio.h> main() { int n; char str[20]; void function(char *); printf("Enter lowercase string\n"); scanf("%s",&str); function(str); scanf("%d",&n); } void function(char *c) { int i; char temp; for(i=0;c[i]!='\0';i++) { if(c[i]>='a' && c[i]<='z') { temp = c[i] - 32; printf("%c",temp); } } }

6.

Write a C program to find the greatest of N numbers using arrays

#include<stdio.h> main() { int n,a[10],i,j,k,temp; printf("enter no of elements"); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { for(j=i+1;j<n;j++)

{ if(a[i]<a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } }} Printf(Greatest number); printf("%d",a[0]); } 7. Develop a C program to print the number of vowels in a given paragraph #include<stdio.h> main() { int n,i,count=0,x=0; char str[100],c; FILE *fp; fp=fopen("para.txt","r"); while(!feof(fp)) { c=getc(fp); switch(c) { case 'a': case 'e': case 'i': case 'o': case 'u': count++; } } printf("%d",count);

} 8.

Write a C program to sort N names alphabetically. Use functions

#include<stdio.h> #include<stdlib.h> #include<string.h> main()

{ int i,n=0; char x[10][10]; void reorder(int n,char x[][10]); printf("enter no.of name"); scanf("%d",&n); for(i=0;i<n;i++) scanf("%s",x[i]); reorder(n,x); for(i=0;i<n;i++) printf("%s\n",x[i]); } void reorder(int n,char x[][10]) { char temp[10]; int i,j; for(i=0;i<n-1;++i) for(j=i+1;j<n;++j) if(strcmp(x[i],x[j])>0) { strcpy(temp,x[i]); strcpy(x[i],x[j]); strcpy(x[j],temp); } }
9. Write a C program to sort N numbers. Use pointers Refer: Lab Record

10. Write a C program using pointers to read in an array of integers and print its elements in reverse order Refer: Lab Record 11. 12. 13. Develop a C program to copy the contents of one file into another Refer: Lab Record File Operations - String I/O Functions Write a C program to sort N numbers. Use functions Write a C program to sort N names alphabetically. Use pointers

You might also like