MCS-011 ASSIGNMENT SOLUTION (2018-19)

In this ASSIGNMENT all the below PROGRAMMINGS are written and run in Turbo C++ 3.0

We have removed clrscr( ) and getch( ) functions from each programming because of different version of C compiler.

Question 1 : Write an algorithm, draw a flow chart and write its corresponding C program to convert a decimal number to its equivalent hexadecimal number.

 #include void main() { int n, i, pos=0, array[10]; printf("\n Enter the decimal number... "); scanf("%d",&n); while(n>15) { array[pos++]=n%16; n=n/16; } array[pos]=n; printf("\n Converted Hexadecimal Number = "); for(i=pos;i>=0;i--) { if(array[i] == 10) printf("A"); else if(array[i] == 11) printf("B"); else if(array[i] == 12) printf("C"); else if(array[i] == 13) printf("D"); else if(array[i] == 14) printf("E"); else if(array[i] == 15) printf("F"); else printf("%d",array[i]); } }

Output

Enter the decimal number . . . 245

Question 2 : Write an algorithm and its corresponding C program to generate students Progress-Report for VIII standard (section of 20 students) of a CBSE school for all its 4 terms. Use Structures concept. Assumptions can be made wherever necessary.

 #include struct student { int roll; char name[50]; int result[4][9]; }; struct student st[20]; int i, j, pos=-1; void insertresult(); void display(); void main() { int choice; while(1) { printf("\n Press 1 for insert result"); printf("\n Press 2 for display result"); printf("\n Press 3 for exit"); printf("\n Enter your choice... "); scanf("%d",&choice); switch(choice) { case 1: insertresult(); break; case 2: display(); break; case 3: exit(0); default: printf("\n Wrong Input"); } } } void insertresult() { pos++; printf("\n Enter the student roll number... "); scanf("%d",&st[pos].roll); printf("\n Enter the student name... "); fflush(stdin); gets(st[pos].name); for(i=0;i<4;i++) { printf("\n Enter the Marks for Term %d",(i+1)); printf("\n English 1 : "); scanf("%d",&st[pos].result[i][0]); printf("\n English 2 : "); scanf("%d",&st[pos].result[i][1]); printf("\n Mathematics : "); scanf("%d",&st[pos].result[i][2]); printf("\n Physics : "); scanf("%d",&st[pos].result[i][3]); printf("\n Chemistry : "); scanf("%d",&st[pos].result[i][4]); printf("\n Biology : "); scanf("%d",&st[pos].result[i][5]); printf("\n Computer : "); scanf("%d",&st[pos].result[i][6]); printf("\n History : "); scanf("%d",&st[pos].result[i][7]); printf("\n Geography : "); scanf("%d",&st[pos].result[i][8]); } } void display() { int n, found=0; printf("\n Enter the roll number... "); scanf("%d",&n); for(i=0;i<=pos;i++) { if(st[i].roll == n) { found=1; printf("\n\n %s",st[i].name); printf("\n\n Subject \t Term-1 \t Term-2 \t Term-3 \t Term-4"); printf("\n\n English 1 "); for(j=0;j<4;j++) printf("\t\t %d ",st[i].result[j][0]); printf("\n\n English 2 "); for(j=0;j<4;j++) printf("\t\t %d ",st[i].result[j][1]); printf("\n\n Mathematics "); for(j=0;j<4;j++) printf("\t\t %d ",st[i].result[j][2]); printf("\n\n Physics "); for(j=0;j<4;j++) printf("\t\t %d ",st[i].result[j][3]); printf("\n\n Chemistry "); for(j=0;j<4;j++) printf("\t\t %d ",st[i].result[j][4]); printf("\n\n Biology "); for(j=0;j<4;j++) printf("\t\t %d ",st[i].result[j][5]); printf("\n\n Computer "); for(j=0;j<4;j++) printf("\t\t %d ",st[i].result[j][6]); printf("\n\n History "); for(j=0;j<4;j++) printf("\t\t %d ",st[i].result[j][7]); printf("\n\n Geography "); for(j=0;j<4;j++) printf("\t\t %d ",st[i].result[j][8]); break; } } if(found == 0) printf("\n Given roll number not exist"); }

Question 3 : Write a C program to generate the following pattern :
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

#include<stdio.h>
void main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}

Question 4 : Write a program to generate Fibonacci series using Recursion.

 #include void fibonacci(int x, int y, int n); void main() { int a, b, terms; printf("\n Enter the first number of the series... "); scanf("%d",&a); printf("\n Enter the second number of the series... "); scanf("%d",&b); printf("\n Enter the number of terms you want to generate... "); scanf("%d",&terms); printf("\n"); fibonacci(a,b,terms); } void fibonacci(int x, int y, int n) { int z; if(n!=0) { z=x+y; printf("\t%d",z); x=y; y=z; fibonacci(x,y,n-1); } }

Output

Enter the first number of the series . . . 1

Enter the second number of the series . . . 3

Enter the number of terms you want to generate . . . 5

47111829

Question 5 : Write a C program to perform the following operation on matrices D = A + (B * C), where A, B and C are matrices of (3 X 3) size and D is the resultant matrix.

 #include void main() { int i, j, k, a[3][3], b[3][3], c[3][3], d[3][3]; // Input Matrix A printf("\n Enter the element of matrix A"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\n Enter the value of A[%d][%d] ",i,j); scanf("%d",&a[i][j]); } } // Input Matrix B printf("\n Enter the element of matrix B"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\n Enter the value of B[%d][%d] ",i,j); scanf("%d",&b[i][j]); } } // Input Matrix C printf("\n Enter the element of matrix C"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\n Enter the value of C[%d][%d] ",i,j); scanf("%d",&c[i][j]); // Initialize Matrix D d[i][j]=0; } } // Matrix Multilication for(i=0;i<3;i++) { for(j=0;j<3;j++) { for(k=0;k<3;k++) { d[i][j]=(d[i][j] + (b[i][k] * c[k][j])); } } } // Matrix Addition for(i=0;i<3;i++) { for(j=0;j<3;j++) { d[i][j]=d[i][j]+a[i][j]; } } // Print Matrix D for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\t%d",d[i][j]); } printf("\n"); } } Output Enter the Element of First Matrix Enter the value of A[0][0] : 6 Enter the value of A[0][1] : 9 Enter the value of A[0][2] : 1 Enter the value of A[1][0] : 7 Enter the value of A[1][1] : 2 Enter the value of A[1][2] : 4 Enter the value of A[2][0] : 8 Enter the value of A[2][1] : 3 Enter the value of A[2][2] : 7 Enter the Element of Second Matrix Enter the value of B[0][0] : 1 Enter the value of B[0][1] : 4 Enter the value of B[0][2] : 2 Enter the value of B[1][0] : 3 Enter the value of B[1][1] : 2 Enter the value of B[1][2] : 5 Enter the value of B[2][0] : 4 Enter the value of B[2][1] : 6 Enter the value of B[2][2] : 3 Enter the Element of Third Matrix Enter the value of C[0][0] : 2 Enter the value of C[0][1] : 6 Enter the value of C[0][2] : 3 Enter the value of C[1][0] : 8 Enter the value of C[1][1] : 1 Enter the value of C[1][2] : 5 Enter the value of C[2][0] : 6 Enter the value of C[2][1] : 2 Enter the value of C[2][2] : 4 522332 593243 823961

Question 6 : Write an interactive C program to calculate the string length of a given string, using pointers.

#include<stdio.h>
void main()
{
char *s;
int i, len=0;
printf("\n Enter the string... ");
gets(s);
for(i=0; *(s+i)!='\0'; i++)
{
len++;
}
printf("\n Length = %d",len);
}

Output

Enter the string . . . Computer Application

Length = 20

Question 7 : Write a C program to take a list of N numbers, separate even and odd numbers and put them in two appropriate files (evenfile and oddfile). Use File Handling concept.

 #include #include void main() { FILE *even, *odd; int n, array[100], i; printf("\n How many numbers you want to take... "); scanf("%d",&n); for(i=0;i

Question 8 : Write an interactive C program for each to illustrate the following concepts :
a) enumerated data type
b) macros in C
c) typedef
d) goto statement
e) break statement

a) enumerated data type

#include<stdio.h>
enum state {FAILED=0, WORKING};
enum state currentState=1;
enum state FindState()
{
return currentState;
}
void main()
{
if(FindState() == WORKING)
printf("WORKING");
else
printf("FAILED");
}

b) macros in C

#include<stdio.h>
#define PI 3.14
void main()
{
printf("Circle Area = %f",area);
}

c) typedef

 #include struct employee { int id; char *name; int salary; }; typedef struct employee emp; void main() { emp e; e.id=1; e.name="Debabrata"; e.salary=10000; printf("%d\t%s\t%d",e.id,e.name,e.salary); }

d) goto statement

//Factorial Calculation
#include<stdio.h>
void main()
{
int n,i=1,fact=1;
printf("Enter the number...");
scanf("%d",&n);
start:
fact=fact*i;
i++;
if(i <= n)
goto start;
}

e) break statement

 /* Calculate the sum of 10 numbers */ /* If negative number is entered, loop terminates */ #include void main() { int i; double n,sum=0.0; for(i=1;i<=10;i++) { printf("Enter the number..."); scanf("%lf",&n); if(n < 0.0) { break; } sum=sum+n; } printf("Answer = %lf",sum); }

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.

MORE TOPIC

WHAT WE DO