Monthly Archives: November 2017


Write an interactive C program to append the contents of a file at the end of another file without using any built-in functions – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS
Course Code: MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/2017-18
Maximum Marks : 100

Write a program to find the largest element in an array using Recursion – IGNOU MCA Assignment 2017 – 18

Program:

#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp1,*fp2,*ftemp;
char CH;
int c;
clrscr();
fp1=fopen(“TEST1.txt”,”r”);
fp2=fopen(“TEST2.txt”,”r”);
if(fp1==NULL||fp2==NULL)
{
perror(“Error has occured”);
printf(“Press any key to Exit…”);
exit(EXIT_FAILURE);
}
ftemp=fopen(“TEST3.txt”,”w”);
if(ftemp==NULL)
{
perror(“Error has occured”);
printf(“Press any key to Exit…”);
exit(EXIT_FAILURE);
}
while(1)
{ CH=fgetc(fp1);
if(feof(fp1)) break;
fputc(CH,ftemp);
}
fputc(‘\n’,ftemp);
while(1)
{ CH=fgetc(fp2);
if(feof(fp2)) break;
fputc(CH,ftemp);
}
printf(“\nTwo files merged in another file…”);
fclose(fp1);
fclose(fp2);
fclose(ftemp);
getch();
}

Code:

#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp1,*fp2,*ftemp;
char CH;
int c;
clrscr();
fp1=fopen("TEST1.txt","r");
fp2=fopen("TEST2.txt","r");
if(fp1==NULL||fp2==NULL)
{
perror("Error has occured");
printf("Press any key to Exit...");
exit(EXIT_FAILURE);
}
ftemp=fopen("TEST3.txt","w");
if(ftemp==NULL)
{
perror("Error has occured");
printf("Press any key to Exit...");
exit(EXIT_FAILURE);
}
while(1)
{ CH=fgetc(fp1);
if(feof(fp1)) break;
fputc(CH,ftemp);
}
fputc('\n',ftemp);
while(1)
{ CH=fgetc(fp2);
if(feof(fp2)) break;
fputc(CH,ftemp);
}
printf("\nTwo files merged in another file...");
fclose(fp1);
fclose(fp2);
fclose(ftemp);
getch();
}

Screen Shots:

C_Program_File_Append

C_Program_File_Append_Output

Write an interactive C program to calculate the sum of array element using pointer – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS
Course Code: MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/2017-18
Maximum Marks : 100

Write a program to find the largest element in an array using Recursion – IGNOU MCA Assignment 2017 – 18

Program:

#include<stdio.h>
void main()
{
int ARRAY[]={1,2,3,4,5,6,7,8,9,0};
int I,*PTR,SUM=0;
clrscr();
PTR=&ARRAY;
while(*PTR)
{
SUM = SUM + *PTR;
PTR++;
}
printf(“SUM OF ARRAY IS = %d”,SUM);
getch();
}

Code:

#include<stdio.h>
void main()
{
int ARRAY[]={1,2,3,4,5,6,7,8,9,0};
int I,*PTR,SUM=0;
clrscr();
PTR=&ARRAY;
while(*PTR)
{
SUM = SUM + *PTR;
PTR++;
}
printf("SUM OF ARRAY IS = %d",SUM);
getch();
}

Screen Shots:

C_program_Sum_of_Array_Ptr

C_program_Sum_of_Array_Ptr_Output

Write a C program to determine a given matrix is a sparse matrix – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS
Course Code: MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/2017-18
Maximum Marks : 100

Write a program to find the largest element in an array using Recursion – IGNOU MCA Assignment 2017 – 18

Program:

#include<stdio.h>
void main()
{
int MATRIX[10][10];
int I,J,M,N;
int COUNT=0;
clrscr();
printf(“ENTER THE ORDER OF MATRIX\n”);
scanf(“%d %d”,&M,&N);
printf(“ENTER THE CO-EFFICIENTS OF MATRIX\n”);
for(I=0;I<M;I++)
{
for(J=0;J<N;J++)
{
scanf(“%d”,&MATRIX[I][J]);
if(MATRIX[I][J]==0)
{
COUNT++;
}
}
}
if(COUNT>((M*N)/2))
printf(“THE GIVEN MATRIX IS A SPARSE MATRIX\n”);
else
printf(“THE GIVEN MATRIX IS NOT A SPARSE MATRIX\n”);
printf(“THERE ARE %d NUMBERS OF ZEROS”,COUNT);
getch();
}

Code:

#include<stdio.h>
void main()
{
int MATRIX[10][10];
int I,J,M,N;
int COUNT=0;
clrscr();
printf("ENTER THE ORDER OF MATRIX\n");
scanf("%d %d",&M,&N);
printf("ENTER THE CO-EFFICIENTS OF MATRIX\n");
for(I=0;I<M;I++)
{
for(J=0;J<N;J++)
{
scanf("%d",&MATRIX[I][J]);
if(MATRIX[I][J]==0)
{
COUNT++;
}
}
}
if(COUNT>((M*N)/2))
printf("THE GIVEN MATRIX IS A SPARSE MATRIX\n");
else
printf("THE GIVEN MATRIX IS NOT A SPARSE MATRIX\n");
printf("THERE ARE %d NUMBERS OF ZEROS",COUNT);
getch();
}

Screen Shots:

C_program_Sparse_Matrix

C_program_Sparse_Matrix_Output

Write a program to find the largest element in an array using Recursion – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS
Course Code: MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/2017-18
Maximum Marks : 100

Write a program to find the largest element in an array using Recursion – IGNOU MCA Assignment 2017 – 18

 Program:

#include<stdio.h>
int LARGE=-1;
void main()
{
int NUM[10],I;
void largest_rec(int *);
clrscr();
printf(“ENTER TEN NUMBERS TO COMPARE\n”);
for(I=0;I<10;I++)
{
printf(“\nENTER NUMBER : “);
scanf(“%d”,&NUM[I]);
}
largest_rec(NUM);
printf(“\nTHE LARGER NUMBER IS %d”,LARGE);
getch();
}

void largest_rec(int *TEMP)
{
if(*TEMP)
{
if(LARGE<*TEMP)
LARGE=*TEMP;
largest_rec(TEMP+1);
}
}

Code:

#include<stdio.h>
int LARGE=-1;
void main()
{
int NUM[10],I;
void largest_rec(int *);
clrscr();
printf("ENTER TEN NUMBERS TO COMPARE\n");
for(I=0;I<10;I++)
{
printf("\nENTER NUMBER : ");
scanf("%d",&NUM[I]);
}
largest_rec(NUM);
printf("\nTHE LARGER NUMBER IS %d",LARGE);
getch();
}
void largest_rec(int *TEMP)
{
if(*TEMP)
{
if(LARGE<*TEMP)
LARGE=*TEMP;
largest_rec(TEMP+1);
}
}

Screen Shots:

C_program_Largest_Recursion

C_program_Largest_Recursion_Output

A C program to separate even and odd of array put them in two arrays – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS
Course Code: MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/2017-18
Maximum Marks : 100

Write a C program to separate even and odd numbers of an array and put them in two arrays.- IGNOU MCA Assignment 2017 – 18

 

Program:

#include<stdio.h>
void main()
{
int I,J=0,K=0,NUM[]={1,2,3,4,5,6,7,8,9,10},EVEN[10],ODD[10];
clrscr();
printf(“\nNUMBERS IN AN ARRAY ARE : \n”);
for(I=0;I!=10;I++)
printf(“%d\t”,NUM[I]);
for(I=0;I!=10;I++)
{
if(NUM[I]%2==0)
{
EVEN[J++]=NUM[I];
}
else if(NUM[I]%2!=0)
{
ODD[K++]=NUM[I];
}
}
EVEN[J]=ODD[K]=NULL;
printf(“\nTOTAL EVEN NUMBER ARE : \n”);
for(I=0;EVEN[I]!=NULL;I++)
printf(“%d\t”,EVEN[I]);
printf(“\n”);
printf(“\nTOTAL ODD NUMBER ARE : \n”);
for(I=0;ODD[I]!=NULL;I++)
printf(“%d\t”,ODD[I]);
getch();
}

Code:

#include<stdio.h>
void main()
{
int I,J=0,K=0,NUM[]={1,2,3,4,5,6,7,8,9,10},EVEN[10],ODD[10];
clrscr();
printf("\nNUMBERS IN AN ARRAY ARE : \n");
for(I=0;I!=10;I++)
printf("%d\t",NUM[I]);
for(I=0;I!=10;I++)
{
if(NUM[I]%2==0)
{
EVEN[J++]=NUM[I];
}
else if(NUM[I]%2!=0)
{
ODD[K++]=NUM[I];
}
}
EVEN[J]=ODD[K]=NULL;
printf("\nTOTAL EVEN NUMBER ARE : \n");
for(I=0;EVEN[I]!=NULL;I++)
printf("%d\t",EVEN[I]);
printf("\n");
printf("\nTOTAL ODD NUMBER ARE : \n");
for(I=0;ODD[I]!=NULL;I++)
printf("%d\t",ODD[I]);
getch();
}

Screen Shots:

C_program_Separate_Even_Odd

C_program_Separate_Even_Odd_output

A C program to convert an octal number to its equivalent decimal number – IGNOU MCA Assignment 2017 – 18

MASTER OF COMPUTER APPLICATIONS
Course Code: MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/2017-18
Maximum Marks : 100
Weightage : 25%

Draw a flow chart and write its corresponding C program to convert an octal number to its equivalent decimal number.- IGNOU MCA Assignment 2017 – 18

 

Flowchart:

FlowChart_Octal_2_Decimal

#include<stdio.h>
#include<math.h>
void main ()
{
int oct,dec=0,i=0;
clrscr();
printf(“Enter any Octal number : “);
scanf(“%d”,&oct);
while(oct!=0)
{
dec=dec+(oct%10)*pow(8,i++);
oct=oct/10;
}
printf(“Decimal = %d\n”, dec);
getch();
}

Code:

#include<stdio.h>
#include<math.h>
void main ()
{
int oct,dec=0,i=0;
clrscr();
printf("Enter any Octal number : ");
scanf("%d",&oct);
while(oct!=0)
{
dec=dec+(oct%10)*pow(8,i++);
oct=oct/10;
}
printf("Decimal = %d\n", dec);
getch();
}

Screen Shots:

C_program_Octal_to_Decimal

C_program_Octal_to_Decimal_Output