MCS 011 SOLVED ASSIGNMENTS

7,858 views

Published on

IGNOU UNIVERSITY SOLVED ASSIGNMENTS

Published in: Education, Technology
1 Comment
5 Likes
Statistics
Notes
No Downloads
Views
Total views
7,858
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
180
Comments
1
Likes
5
Embeds 0
No embeds

No notes for slide

MCS 011 SOLVED ASSIGNMENTS

  1. 1. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com Course Code : MCS-011 Course Title : Problem Solving and Programming Assignment Number : MCA(1)/011/Assign/13 Maximum Marks : 100 Weightage : 25% Last Dates for Submission : 15th October, 2013 (For July 2013 Session) 15th April, 2014 (For January 2014 Session) 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)
  2. 2. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com printf("perfect no =%dn",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
  3. 3. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com 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
  4. 4. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com 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 */
  5. 5. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com 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++; }
  6. 6. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com else break; } if(t>p) printf("nString is palindrome"); else printf("nString 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;
  7. 7. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com 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); }
  8. 8. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com 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("n ENTER NAME OF THE EMPLOYEE:"); scanf("%s",emp[i].name); printf("n ENTER DESIGANTION OF THE EMPLOYEE:"); scanf("%s",emp[i].des); printf("n ENTER MONTH:"); scanf("%s",emp[i].mon); printf("n ENTER EMPLOYEE ID:"); scanf("%d",&emp[i].empid); printf("n ENTER ACCNO:"); scanf("%d",&emp[i].accno); printf("nENTER BASIC PAY: "); scanf("%f",&emp[i].basic); printf("ENTER CITY LEVEL: "); scanf("%s",&emp[i].level);
  9. 9. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com } 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("ntt V R SIDDHARTHA ENGINEERNG COLLEGE"); printf("nttt KANURU::VIJAYAWADA-7n"); printf("ntttt PAY SLIP");
  10. 10. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com printf("nttt************************"); printf("nttt Salary Slip for %s ",emp[i].mon); printf("nttt***********************"); printf("nn tNAME: %s tttEMPID: %d ",emp[i].name,emp[i].empid); printf("nn tDESIGNATION:%s ttACCNO:%d",emp[i].des,emp[i].accno); printf("n----------------------------------------- ----n"); printf("<----------EARNINGS----------> <------- DEDUCTIONS------------>n"); printf("n BASIC=%f ttttP.F.=%.2f",emp[i].basic,emp[i].gpf); printf("nn D.A=%.2f ttttINCOME TAX=",emp[i].da); printf("nn H.R.A=%.2f ttttP.F. LOAN=",emp[i].hra); printf("nn C.C.A=%.2f ttttL.I.C=",emp[i].cca); printf("nn--------------------------------------- ----------"); printf("nn GROSS SALARY=%.2f ttTOTAL DEDUCTIONS=%.2f " ,emp[i].grossal,emp[i].totdeduc); printf("nn--------------------------------------- ------------"); printf("nnttt NET SALARY=%.2f",emp[i].netsal); printf("nn--------------------------------------- ------------"); printf("nnnttttttEMPLOYEE SIGNATURE"); printf("nnnPRESS 1 TO NEXT ......"); scanf("%d",&k); }while(k==2); } getch(); } For More Ignou Solved Assignments Please Visit - www.ignousolvedassignments.com
  11. 11. For more IGNOU solved assignments please visit - www.ignousolvedassignments.com Connect on Facebook : https://www.facebook.com/pages/IgnouSolvedAssignmentscom/346544145433550 Subscribe and Get Solved Assignments Direct to your Inbox : http://feedburner.google.com/fb/a/mailverify?uri=ignousolvedassignments_ com

×