IGNOU MCS-011 Assignment Solution for 2020-21 | IGNOU Solved Assignment
IGNOU MCS-011 Assignment Solution for 2020-21 | IGNOU Solved Assignment
Q1 (10 Marks)
Write an algorithm, draw a corresponding flowchart and write an interactive program to convert a decimal number to its hexadecimal equivalent.
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
long int dec,r;
int i=0,l;
char hex[50];
printf("Enter Decimal number\n");
scanf("%ld",&dec);
while(dec!=0)
{
r=dec%16;
if(r<10)
hex[i++]=48+r;
else
hex[i++]=55+r;
dec=dec/16;
}
for(l=i-1;l>=0;l--)
printf("%c",hex[l]);
getch();
}
Q2. (10 Marks)
Write an interactive C program to find the MINIMUM and MAXIMUM (value) array elements in a given 3X3 matrix.
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,min,max;
int a[3][3];
clrscr();
printf("Enter array elements in a[3][3]");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
min=a[0][0];
max=a[0][0];
for(i=0;i<3;i++)
{
if(i==0)
j=1;
else
j=0;
for(;j<3;j++)
{
if(a[i][j]<min)
min=a[i][j];
if(a[i][j]>max)
max=a[i][j];
}
}
printf("Minimum value element in the given array is %d\n",min);
printf("Maximum value element in the given array is %d",max);
getch();
}
Q3. (2X 5 =10 Marks)
Write the following functions that:
a) Calculate simple interest.
b) Calculate compound interest.
Write an interactive C (main) program to provide the above functions as options to the user using switch statement and performs the functions accordingly.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
float SI(float p, float r, float t)
{
float si;
si=p*r*t/100;
return si;
}
float CI(float p, float r, float t,int n)
{
float ci;
ci=p*pow((1+r/(n*100)),(n*t))-p;
return ci;
}
void main()
{
float p,r,t,si,ci;
int choice,n;
clrscr();
printf("Enter principal, rate and time\n");
scanf("%f%f%f",&p,&r,&t);
printf("Enter your choice\nPress 1 for Simple Interest\nPress 2 for Compound Interest\n");
scanf("%d",&choice);
switch(choice)
{
case 1: si=SI(p,r,t);
printf("Simple Interest is %f",si);
break;
case 2:
printf("Enter number of times the Interest is to be Compounded");
scanf("%d",&n);
ci=CI(p,r,t,n);
printf("Compound Interest is %f",ci);
break;
default:
printf("Wrong Choice only 1 or 2 is the right choice");
}
getch();
}
MCS-011 Q3 Explanation
Q4. (2 ½ X 4 =10 Marks)
Write the following string functions that:
a) Replace a character in a given string with a character suggested by the user.
b) Convert the given string into uppercase.
c) Convert the alternate character into upper case.
d) Check each and every character in the string and display whether it is an alphabet, digit or special character.
Write an interactive C (main) program to provide the above string functions as options to the user using switch statement and perform the functions accordingly
Source Code:
#include<stdio.h>
#include<conio.h>
void rep(char str[],char ch1,char ch2)
{
int i=0;
while(str[i]!='\0')
{
if(str[i]==ch1)
str[i]=ch2;
i++;
}
printf("%s\n",str);
}
void convert2upper(char str[])
{
int i=0;
while(str[i]!='\0')
{
if(str[i]>=97&&str[i]<=122)
str[i]=str[i]-32;
i++;
}
printf("%s",str);
}
void convertaltupper(char str[])
{
int i=0;
while(str[i]!='\0')
{
if(i%2==0)
{
if((str[i]>=97&&str[i]<=122))
str[i]=str[i]-32;
}
else
{
if(str[i]>=65&&str[i]<=90)
str[i]=str[i]+32;
}
i++;
}
printf("%s",str);
}
void chkalpdigsps(char str[])
{
int i=0;
while(str[i]!='\0')
{
if((str[i]>=65&str[i]<=90)||(str[i]>=97&&str[i]<=122))
printf("Character at str[%d] is an alphabet that is %c\n",i,str[i]);
else if(str[i]>=48&&str[i]<=57)
printf("Character at str[%d] is a digit that is %c\n",i,str[i]);
else
printf("Character at str[%d] is a special symbol that is %c\n",i,str[i]);
i++;
}
}
void main()
{
char ch1,ch2;
char str[]="H?ello!";
// char str[]="hEllo how are you?";
int choice;
printf("Enter your choice\n");
scanf("%d",&choice);
fflush(stdin);
switch(choice)
{
case 1:
printf("Enter a character you want to replace in the given string\n");
scanf("%c",&ch1);
fflush(stdin);
printf("Enter a character you want to replace with in the given string\n");
scanf("%c",&ch2);
rep(str,ch1,ch2);
printf("%s",str);
break;
case 2:
convert2upper(str);
break;
case 3:
convertaltupper(str);
break;
case 4:
chkalpdigsps(str);
break;
default:
printf("Wrong Choice");
}
getch();
}
Q5. (10 Marks)
Write a program to search a given string among the available strings, using Binary Search.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char names[][15]={"amit","bobby","gaurav","gauri","nitin","ramesh","suresh",
"vijay","vikas","yuki"};
char n[15];
int lower=0,upper=9,mid,flag=0;
clrscr();
printf("Enter the name you want to be search\n");
gets(n);
while(lower<=upper)
{
mid=(lower+upper)/2;
if(strcmp(names[mid],n)==0)
{
flag=1;
break;
}
else if(strcmp(names[mid],n)>0)
upper=mid-1;
else
lower=mid+1;
}
if(flag==1)
printf("%s name found at names[%d]\n",n,mid);
else
printf("%s name not found in the list\n",n);
getch();
}