You are on page 1of 18

MCA SEM I MCSL - 017 Practical Questions

1. WAP to print the grade according to following specifications:

Marks >=90 >=75 & <90 >=60 & <75 >=50 & <60 Below 50

Grade A B C D E

#include<stdio.h> #include<conio.h> void main() { int marks; clrscr(); printf("Enter marks of student: "); scanf("%d",&marks); if(marks>=90) { printf("Student got A grade"); } else if(marks>=75 && marks<90) { printf("Student got B grade");

} else if(marks>=60 && marks<75) { printf("Student got C grade"); } else if(marks>=50 && marks<60) { printf("Student got D grade"); } else { printf("Student got E grade"); } getch(); } 2. WAP to reverse a given number using do..while loop. #include<stdio.h> #include<conio.h> void main() { int num,num1,rev,rem; clrscr(); printf("\n Enter any number:"); scanf("%d",&num); num1=0; do {

rem=num%10; num=num/10; num1=num1*10+rem;

} while(num!=0); printf("\n Reverse number of entered number is: %d",num1); //scanf("%d",num1); getch(); } 3. WAP to check whether a given number is Armstrong or not. (153=1*1*1+5*5*5+3*3*3). #include<stdio.h> #include<conio.h> void main() { int temp,num,num1,rem,sum;

clrscr(); printf("\n Enter any number:"); scanf("%d",&num); temp=num; num1=0; do { rem=num%10; num=num/10;

num1=num1+(rem*rem*rem); } while(num!=0); if(temp==num1) { printf("\n Entered number is Armstrong number"); } else { printf("\n entered number is not armstrong number %d\t%d",temp,num1); } getch(); }
4. 5.WAP to print the Fibonacci series 1 1 2 3 5 8 13 . . . .

#include<stdio.h> #include<conio.h> void main() { int a,b,c,i,n; clrscr(); printf("Enter the range:"); scanf("%d",&n); a=1; b=0; for(i=1;i<=n;i++) {

c=a+b; a=b; b=c; printf("%d ",c); } getch(); }

5. WAP to swap two numbers using call by value. #include<stdio.h> #include<conio.h> void main() { int num1,num2; clrscr(); num1=10; num2=20; printf("\t\tBefore Swapping\n"); printf("num1=%d,num2=%d",num1,num2); swap(num1,num2); getch(); } swap(int x,int y){ int temp; temp=x; x=y;

y=temp; printf("\n\nAfter swapping\n"); printf("num1=%d,num2=%d",x,y); return 0; } 6. WAP to swap two numbers using call by reference. #include<stdio.h> #include<conio.h> void main() { int num1,num2; clrscr(); num1=10; num2=20; printf("\t\tBefore Swapping\n"); printf("num1=%d,num2=%d",num1,num2); swap(&num1,&num2); printf("\n\nAfter swapping\n"); printf("num1=%d,num2=%d",num1,num2);

getch(); } swap(int *x,int *y){ int temp; temp=*x; *x=*y; *y=temp;

return 0; } 7. WAP to find power of given number using recursion. #include<stdio.h> #include<conio.h> void main() { int num1,pw; int ans; int power(int,int); clrscr(); printf("Enter the number and its power:"); scanf("%d %d",&num1,&pw); ans=power(num1,pw); printf("The power of given number is : %d",ans); getch(); } int power(int a, int b){ int result; if(b==0){ return 1; }else{ result = a * power(a,b-1); return(result); } } 8. WAP to find factorial of a given number using recursion.

#include<stdio.h> #include<conio.h>

void main() { int i; long power; long fact(int); printf("Enter any Number between 1 to 200"); scanf("%d",&i); power = fact(i); printf("%ld",power); getch(); }

long fact(int i) { if(i < 0) { printf("\ncan't find the factorial of Negative No"); return 0; } else if(i == 1) return 1; else return i*fact(i-1); }

9. WAP to find GCD of two numbers using recursion.

10. WAP to multiply two matrices. #include<stdio.h> #include<conio.h> void main() { clrscr(); int m1[3][3],m2[3][3],m3[3][3];

printf("Enter the number of first matrix:\n"); int i,j; for(i=0;i<3;i++) { for( j=0;j<3;j++) { scanf("%d",&m1[i][j]); } }

printf("first matrix:\n");

for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",m1[i][j]);

} printf("\n"); }

printf("Enter the number of second matrix:\n"); for(i=0;i<3;i++) { for( j=0;j<3;j++) { scanf("%d",&m2[i][j]); } }

printf("second matrix:\n");

for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",m2[i][j]); } printf("\n"); }

for(i=0;i<3;i++) {

for(j=0;j<3;j++) { m3[i][j]=m1[i][0]*m2[0][j]+m1[i][1]*m2[1][j]+m1[i][2]*m2[2][j]; } }

printf("multiplication matrix:\n");

for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",m3[i][j]); } printf("\n"); }

getch(); } 11. WAP to find transpose of a matrix. #include<stdio.h> #include<conio.h> void main() { clrscr();

int m1[3][3],m2[3][3];

printf("Enter the number of matrix:\n"); int i,j; for(i=0;i<3;i++) { for( j=0;j<3;j++) { scanf("%d",&m1[i][j]); } }

printf("matrix:\n");

for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",m1[i][j]); } printf("\n"); } for(i=0;i<3;i++) { for(j=0;j<3;j++) { m2[i][j]=m1[j][i];

} }

printf("transpose matrix:\n");

for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",m2[i][j]); } printf("\n"); }

getch(); } 12. WAP to sort an array in descending order. #include<stdio.h> #include<conio.h> void main() { clrscr(); int arr[10],i,j,t;

printf("Enter the 10 number of array:\n");

for(i=0;i<10;i++) { scanf("%d",&arr[i]); }

printf("Array before sorting:\n");

for(i=0;i<10;i++) { printf("%d",arr[i]); } printf("\n");

printf("Array after sorting:\n");

for(i=0;i<10;i++) { for(j=0;j<9;j++) { if(arr[j]<arr[j+1]) { t=arr[j]; arr[j]=arr[j+1]; arr[j+1]=t; } } }

for(i=0;i<10;i++) { printf("%d",arr[i]);

getch(); }
13. .write a program to design structure for student having roll no, name,marks.store the data

of 10 tsudents and sort it in ascending order in their names /*WAP to design str for student having roll number,name,marks.Store the data of 10 student and sort it in assending order of there of name*/ #include<stdio.h> #include<conio.h> #include<iostream.h> #include<string.h> main(void) { struct student { int roll_number; char name[15];

int marks; } ;

struct student stu[4]; int i; clrscr(); printf("Plesae enter data of students\n"); int k,j ;

for(i=0;i<=2;i++) { printf("Enter roll number,name and marks of %d student\t",i); scanf("%d",&stu[i].roll_number); scanf("%s",&stu[i].name); scanf("%d",&stu[i].marks);

} printf("Entered data is as follows:\n"); for(i=0;i<=2;i++) {

printf("\t%d",stu[i].roll_number); printf(stu[i].name); printf("\t%d",stu[i].marks); printf("\n"); } printf("Students data is in sorted order is as follows"); char temp[15]; int r,m;

for(int t=0;t<=2;t++) { for(i=0;i<2;i++) { if(strcmp(stu[i].name,stu[i+1].name)>0) { strcpy(temp,stu[i+1].name); strcpy(stu[i+1].name,stu[i].name); strcpy(stu[i].name,temp) ; r=stu[i+1].roll_number; stu[i+1].roll_number=stu[i].roll_number; stu[i].roll_number=r; m=stu[i+1].marks; stu[i+1].marks=stu[i].marks; stu[i].marks=m ; } } }

for(i=0;i<=2;i++) {

printf("\n\t%d",stu[i].roll_number); printf(stu[i].name); printf("\t%d",stu[i].marks); printf("\n"); }

getch(); return 0; }
14. WAP to copy 1 file into another file. 15. WAP to append new data in file 16. WAP to read any 10 random nos and find sum and avg using pointers.

Subject I/C Mahendra S. Patil

You might also like