You are on page 1of 10

For more IGNOU Solved Assignments visit – www.IGNOUHelp.

in

Get Daily Updates by Facebook:

https://www.facebook.com/IGNOUHelp.in

Course Code : MCS-011


Course Title : Problem Solving and Programming Assignment Number :
MCA(1)/011/Assign/13
Maximum Marks : 100
Weightage : 25%

There are six questions in this assignment, which carry 80 marks. Rest 20 marks
are for viva-voce.
Answer all the questions. You may use illustrations and diagrams to enhance the
explanations.
Please go through the guidelines regarding assignments given in the Programme
Guide for the format of presentation. Insert comments in the coding for better
understanding.

Question 1:
Write a C program to find out perfect numbers from 1 and 50
. Solution :
#include<stdio.h>
#include<conio.h> voidmain()
{
voidperfect(); clrscr(); perfect(); getch();
}
void perfect()
{
int n,i,s,lim; lim=1;
while(lim<=50) { i=1;s=0;
while(i<lim)
{
if(lim%i==0)
{
s=s+i;
} i++;
}
if(s==lim)

For more IGNOU solved assignments please visit - www.IGNOUHelp.in


printf("perfect no =%d",lim); lim++;
}
}
Question 2: Write an algorithm, draw a corresponding flowchart and write
an interactive program to convert a binary number to its octal equivalent.
Solution :
Alogrithm:

Binary to octal conversion method:

Step1: Arrange the binary number in the group 3


from right side.

Step 2: Replace the each group with following


values:

Binary
number Octal
values 000
0
001
1
010
2
011
3
100
4
101
5
110
6
111
7
Binary to octal chart

Binary to octal conversion examples:

For example we want to convert binary


number 1011010101001101 to octal.

Step 1: 001 011 010 101 001 101


Step 2: 1 3 2 5 1 5

So (1011010101001101)2 = (132515)8
For more IGNOU solved assignments please visit - www.IGNOUHelp.in c
program to convert binary to octal

#include<stdio.h>
int main(){

long int binaryNumber,octalNumber=0,j=1,remainder;

printf("Enter any number any binary number: "); scanf("%ld",&binaryNumber);

while(binaryNumber!=0){
remainder=binaryNumber%10;
octalNumber=octalNumber+remainder*j;
j=j*2;
binaryNumber=binaryNumber/10;
}

printf("Equivalent octal
value: %lo",octalNumber);

return 0;
}

Sample output:

Enter any number any binary number: 1101


Equivalent hexadecimal value: 15

For more IGNOU solved assignments please visit - www.IGNOUHelp.in

Question 3 : Write the function strreplace(s, chr, repl_chr) which will replace each
occurrences of character chr with the character repl_chr in the string s. The function
returns the number of replacements. Place the source code of this function in a file named
strreplace.c

Solution :

char *replace_str(const char *str, const char *old, const


char *new)
{
char *ret, *r;
const char *p, *q;
size_t oldlen = strlen(old);
size_t count, retlen, newlen = strlen(new);

if (oldlen != newlen) {
for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q
+ oldlen)
count++;
/* this is undefined if p - str > PTRDIFF_MAX */
retlen = p - str + strlen(p) + count * (newlen - oldlen);
} else
retlen = strlen(str);

if ((ret = malloc(retlen + 1)) == NULL)


return NULL;

for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q


+ oldlen) {
/* this is undefined if q - p > PTRDIFF_MAX */

For more IGNOU solved assignments please visit - www.IGNOUHelp.in


ptrdiff_t l = q - p;
memcpy(r, p, l);
r += l;
memcpy(r, new,
newlen); r += newlen;
}
strcpy(r, p);

return ret;
}

Question 4: Writer an interactive C program to check whether the given string is


a palindrome or not, using pointers.
Solution :

#include<stdio.h>
#include<conio.h>
int main()
{
char str[30];
char *p,*t;
printf("Enter any string : ");
gets(str);
for(p=str ; *p!=NULL ;
p++); for(t=str, p-- ; p>=t; )
{
if(*p==*t)
{
p--;
t++;
}

For more IGNOU solved assignments please visit - www.IGNOUHelp.in


else
break;
}
if(t>p)
printf("is
palindrome"); else
printf("is Not
palindrome"); getch();
return 0;
}

Question 5: Write an interactive program called “WEIGHT CONVERTER” that


accepts the weight in milligrams / decigrams / centigrams / kilograms /ounces / pounds /
tons and displays its equivalent in grams .

Solution :

#include <stdio.h>

void print_converted(int pounds)

/* Convert U.S. Weight to Imperial and

International Units. Print the results */

{ int stones = pounds / 14;

int uklbs = pounds % 14;

float kilos_per_pound = 0.45359;

For more IGNOU solved assignments please visit - www.IGNOUHelp.in

float kilos = pounds * kilos_per_pound;


printf(" %3d %2d %2d %6.2f", pounds, stones, uklbs, kilos);

}
Main (int argc,char *argv[])

{ int pounds;

if(argc != 2)

{ printf ("Usage: convert weight_in_pounds"); exit(1);

Sscanf (argv[1], "%d", &pounds); /* Convert String to int */

Printf (" US lbs UK st. lbs INT Kg"); print_converted (pounds);

For more IGNOU solved assignments please visit - www.IGNOUHelp.in


Question 6. Write an interactive program to generate pay slips for the staff of size
12 employees (2 members are clerks, one computer operator, 6 salesmen, 3 helpers) ,
working in a small chemist retail shop.
Assumptions can be made wherever necessary. The payslip should display the
employee no., employee name, no. of days worked during the month, date of generation of
the payslip, month for which the salary is being paid, all the details of the payment,
deductions, gross-pay and net-pay.

Solution :

#include<stdio.h>
#include<conio.h> void main()
{
int n,i,k;
struct employee
{
char name[50],des[30],mon[10],level; int empid,accno;
float hra,da,cca,ca,gpf,grossal,totdeduc,netsal,basic;
}emp[10];
clrscr();
printf("ENTER THE NUMBER OF EMPLOYEE: ");
scanf("%d",&n); for(i=1;i<=n;i++)
{
printf("ENTER NAME OF THE EMPLOYEE:");
scanf("%s",emp[i].name);
printf("ENTER DESIGANTION OF THE EMPLOYEE:"); scanf("%s",emp[i].des);
printf("ENTER MONTH:"); scanf("%s",emp[i].mon); printf("ENTER EMPLOYEE ID:");
scanf("%d",&emp[i].empid); printf("ENTER ACCNO:");
scanf("%d",&emp[i].accno); printf("BASIC PAY: ");
scanf("%f",&emp[i].basic);
printf("ENTER CITY LEVEL: ");
scanf("%s",&emp[i].level);

For more IGNOU solved assignments please visit - www.IGNOUHelp.in


}

for(i=1;i<=n;i++)
{
emp[i].hra=emp[i].basic*0.30; if(emp[i].basic<=6500) emp[i].ca=100; else
{
if(emp[i].basic>6500&&emp[i].basic<=8000) emp[i].ca=400; else emp[i].ca=800;
}
emp[i].da=emp[i].basic/2; if(emp[i].level=='a'||emp[i].level=='A') emp[i].cca=400; else
{
if(emp[i].level=='b'||emp[i].level=='B') emp[i].cca=100;
else emp[i].cca=50;
}
emp[i].gpf=emp[i].basic * 0.075;
emp[i].grossal=emp[i].basic+emp[i].hra+emp[i].da+emp[ i].cca; emp[i].totdeduc=emp[i].gpf;
emp[i].netsal=emp[i].grossal-emp[i].totdeduc;
}

for(i=1;i<=n;i++)
{
do
{
clrscr();
printf("V R SIDDHARTHA ENGINEERNG COLLEGE");
printf("KANURU::VIJAYAWADA-7"); printf("PAY SLIP");

For more IGNOU solved assignments please visit - www.IGNOUHelp.in


printf("************************"); printf("Salary Slip for %s ",emp[i].mon);
printf("***********************"); printf(": %s : %d
",emp[i].name,emp[i].empid);

printf(":%s
:%d",emp[i].des,emp[i].accno);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
printf(" -
----");
printf("<-------------------
- EARNINGS >
D
E
D
U
C
T
I
<------------------- O >");
N
S
printf("BASIC=%f
.F.=%.2f",emp[i].basic,emp[i].gpf);
printf("D.A=%.2f TAX=",emp[i].da); printf("H.R.A=%.2f .F. LOAN=",emp[i].hra);
printf("C.C.A=%.2f
.I.C=",emp[i].cca); printf("--------------
------------------------
----------");
printf("GROSS SALARY=%.2f DEDUCTIONS=%.2f "
,emp[i].grossal,emp[i].totdeduc); printf("--------------------------------------
------------");
printf("NET SALARY=%.2f",emp[i].netsal); printf("--------------------------------------
------------");
printf("SIGNATURE"); printf("1 TO NEXT ......");
scanf("%d",&k); }while(k==2);
}
getch();
}

For more IGNOU Solved Assignments visit – www.IGNOUHelp.in

Get Daily Updates by Facebook:

https://www.facebook.com/IGNOUHelp.in

You might also like