Monthly Archives: April 2016


Write a program that does not use the inbuilt string function to concatenate two strings 10m Jun2009

Write a program that does not use the inbuilt string function to perform the following: 10m Jun2009

(ii) To concatenate two strings

Code:-

#include<stdio.h>
void main()
{
void str_concat(char*,char*,char*);
char Str1[50],Str2[50],Str3[100];
clrscr();
printf(“\nENTER FIRST STRING TO CONCATE : “);
scanf(“%s”,&Str1);
printf(“\nENTER SECOND STRING TO CONCATE : “);
scanf(“%s”,&Str2);
str_concat(Str1,Str2,Str3);
printf(“\nSTR1 IS : %s”,Str1);
printf(“\nSTR2 IS : %s”,Str2);
printf(“\nSTR3 IS : %s”,Str3);
getch();
}
void str_concat(char *STR1,char *STR2,char *STR3)
{
while(*STR1)
{
*STR3=*STR1;
STR1++;
STR3++;
}

while(*STR2)
{
*STR3=*STR2;
STR2++;
STR3++;
}
*STR3=*STR1;

}

#include<stdio.h>
void main()
{
void str_concat(char*,char*,char*);
char Str1[50],Str2[50],Str3[100];
clrscr();
printf("\nENTER FIRST STRING TO CONCATE : ");
scanf("%s",&Str1);
printf("\nENTER SECOND STRING TO CONCATE : ");
scanf("%s",&Str2);
str_concat(Str1,Str2,Str3);
printf("\nSTR1 IS : %s",Str1);
printf("\nSTR2 IS : %s",Str2);
printf("\nSTR3 IS : %s",Str3);
getch();
}
void str_concat(char *STR1,char *STR2,char *STR3)
{
while(*STR1)
{
*STR3=*STR1;
STR1++;
STR3++;
}
while(*STR2)
{
*STR3=*STR2;
STR2++;
STR3++;
}
*STR3=*STR1;
}

Screen Shots:

C_program_String_Concate

C_program_String_Concate_Output

 

 

 

(a) Develop an algorithm, draw the corresponding flow chart and write a program in’C’ to print the sum of the digits of a three digit number. 10

Solved program can be found on this link http://cssimplified.com/c-programming/write-an-algorithm-and-draw-a-corresponding-flow-chart-to-print-the-sum-of-the-digits-of-a-given-number

 

(b) Write a program that does not use the inbuilt string function to perform the following: 10

 (i) To compare two strings

Solved program can be found on this link http://cssimplified.com/c-programming/write-a-program-that-does-not-use-the-inbuilt-string-functions-to-perform-the-following-10m-jun2006

 

(c) Write ‘C’ programs to read a string and check whether it is palindrome or not. 10

Solved program can be found on this link http://cssimplified.com/c-programming/design-an-algorithm-draw-a-corresponding-flowchart-and-write-a-c-program-to-check-whether-a-given-string-is-a-palindrome-or-not-10m-jun2006

 

(d) Write the output of the following program: 5

main( )

{

Int x=2, y=3, S1, S2;

S1= x+ (+ +y);

S2= + + x + y + +;

Printf (“%d%d%d%d\n”S1, S2, x, y);

}

 

Output: 6 7 3 5

 

(e) Differentiate between structure and union. 5

Solved program can be found on this link http://cssimplified.com/c-programming/what-are-the-differences-between-structure-and-union-give-example-of-usage-of-the-union-8m-jun2008

 

2. (a) Summarize the purpose of the format strings (like %s, %d, %c) that are corrunonly used within the printf function, with an example for each. 10

Solved program can be found on this link http://cssimplified.com/c-programming/summarize-the-purpose-of-the-format-strings-like-s-d-c-that-are-commonly-used-within-the-printf-function-with-an-example-for-each-10m-jun2006

 

Write a program in ‘C’ to check whether the given year is leap or not. Also explain the logic of the program. 8m Dec2008

Write a program in ‘C’ to check whether the given year is leap or not. Also explain the logic of the program. 8m Dec2008

The leap year formula is:

A leap year is divisable by 4, but not by 100 (except if divisable by 400.)

 

#include<stdio.h>
void main(){
int year;
clrscr();
printf(“Enter any year: “);
scanf(“%d”,&year);

if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf(“%d is a leap year”,year);
else
printf(“%d is not a leap year”,year);

getch();
}

Code:-

 

cc#include<stdio.h>
void main(){
int year;
clrscr();
printf("Enter any year: ");
scanf("%d",&year);
 
if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf("%d is a leap year",year);
else
printf("%d is not a leap year",year);
 
getch();
}

 

ScreenShot:-

C_program_Leap_Year

C_program_Leap_Year_Output

 

 

 

(c) Write a function definition to find the smallest among the given three numbers. 5

Solved program can be found on this link http://cssimplified.com/c-programming/write-a-macro-to-find-the-smallest-number-among-3-given-numbers-7m-jun2007

 

4. (a) Without using the’strcpy’function, write a program to copy contents of string 2 to string 1, and find the length of the copied string using pointers. 10

Solved program can be found on this link http://cssimplified.com/c-programming/write-a-program-that-does-not-use-the-inbuilt-string-functions-to-perform-the-following-10m-jun2006

 

5. (a) Design an algorithm and draw corresponding flow chart to convert a decimal number to its Hexadecimal equivalent. 10

Solved program can be found on this link http://cssimplified.com/c-programming/design-an-algorithm-and-draw-corresponding-flowchart-to-convert-a-decimal-number-to-its-hexadecimal-equivalent-10m-dec2005

 

(b) Explain the following storage class specifiers of a variable in terms of default value, lifetime, scope purpose and limitations (with an example) 10

Solved program can be found on this link http://cssimplified.com/c-programming/explain-various-types-of-storage-classes-in-c-with-example-for-each

Write a macro to find out whether the given character is lower case or not 7m Dec2008

Write a macro to find out whether the given character is lower case or not 7m Dec2008

3. (a) Write a macro to find out whether the given character is lower case or not. 7

#include <stdio.h>

//#define IS_UPPER_CASE(n) ((n) >= ‘A’ && (n) <= ‘Z’)
#define IS_LOWER_CASE(n) ((n) >= ‘a’ && (n) <= ‘z’)

//#define IS_ALPHABETIC(n) (IS_UPPER_CASE(n) || IS_LOWER_CASE(n))

void main()
{
char CH=’a';
clrscr();
if(IS_LOWER_CASE(CH))
printf(“\nYES, CHARACTER IS A LOWER CASE CHARACTER”);
else
printf(“\nNO, CHARACTER IS NOT A LOWER CASE CHARACTER”);
getch();
}

Code:-

 

#include <stdio.h>
 
//#define IS_UPPER_CASE(n) ((n) >= 'A' && (n) <= 'Z')
#define IS_LOWER_CASE(n) ((n) >= 'a' && (n) <= 'z')
 
//#define IS_ALPHABETIC(n) (IS_UPPER_CASE(n) || IS_LOWER_CASE(n))
 
void main()
{
char CH='a';
clrscr();
if(IS_LOWER_CASE(CH))
printf("\nYES, CHARACTER IS A LOWER CASE CHARACTER");
else
printf("\nNO, CHARACTER IS NOT A LOWER CASE CHARACTER");
getch();
}

 

Screenshot:-

C_program_Macro_Lower_Case

C_program_Macro_Lower_Output

Write a loop that calculate sum of the n elements of the series 5m Dec2008

Write a loop that calculate sum of the n elements of the series 5m Dec2008

Write a loop that calculate sum of the n elements of the series: 5

1+ 7 +13 +19 + 25 + …….

Write the loop in 3 different ways:

(i) using while loop

(ii) using do-while loop

 

#include<stdio.h>
void main()
{
int i,X,SUM=0;
clrscr();
printf(“\nGENERATED SERIES IS :- \n”);
i=1;
while(i<11)
{
X=i+(5*(i-1));
printf(” %d “,X);
SUM=SUM+X;
i++;
}
printf(“\n\nSUM OF GENERATED SERIES IS :- \t %d \n”,SUM);
getch();
}

code:-

#include<stdio.h>
void main()
{
int i,X,SUM=0;
clrscr();
printf("\nGENERATED SERIES IS :- \n");
i=1;
while(i<11)
{
X=i+(5*(i-1));
printf(" %d ",X);
SUM=SUM+X;
i++;
}
printf("\n\nSUM OF GENERATED SERIES IS :- \t %d \n",SUM);
getch();
}

Screenshot:-

C_program_Series01

 

C_program_Series02

C_program_Series03

C_program_Series_Output

When can two matrices of order m x n and p x q be multiptied? Also write a program in ‘C’ to multiply two such matrices. 10m Dec2008

When can two matrices of order m x n and p x q be multiptied? Also write a program in ‘C’ to multiply two such matrices. 10m Dec2008

 

The only condition which makes matrix multiplication possible is n should be equal to p (i.e. n==p) n of m x n Matrix and p of p x q Matrix

 

Code:

#include<stdio.h>
void main()
{
int A[3][3],B[3][3],C[3][3],I,J,K;
clrscr();
printf(“ENTER 3X3 MATRIX A VALUES\n”);
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
scanf(“%d”,&A[I][J]);
}
}
printf(“ENTER 3X3 MATRIX B VALUES\n”);
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
scanf(“%d”,&B[I][J]);
}
}
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
C[I][J]=0;
for(K=0;K<3;K++)
{
C[I][J]=C[I][J]+A[I][K]*B[K][J];
}
}
}
printf(“RESULT 3X3 MATRIX C VALUES ARE :\n”);
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
printf(“%d\t”,C[I][J]);
}
printf(“\n”);
}
getch();
}

#include<stdio.h>
void main()
{
int A[3][3],B[3][3],C[3][3],I,J,K;
clrscr();
printf("ENTER 3X3 MATRIX A VALUES\n");
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
scanf("%d",&A[I][J]);
}
}
printf("ENTER 3X3 MATRIX B VALUES\n");
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
scanf("%d",&B[I][J]);
}
}
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
C[I][J]=0;
for(K=0;K<3;K++)
{
C[I][J]=C[I][J]+A[I][K]*B[K][J];
}
}
}
printf("RESULT 3X3 MATRIX C VALUES ARE :\n");
for(I=0;I<3;I++)
{
for(J=0;J<3;J++)
{
printf("%d\t",C[I][J]);
}
printf("\n");
}
getch();
}

 Screen Shots:

C_program_Matrix_Multiplication

 C_program_Matrix_Multiplication_Output                                                       

 

2. (a) Write a program in ‘C’ to generate a progress report for students which displays the total marks, avetage, and grades. The input for the system is marks secured in five courses (Assignment and Term end Examination). Pass (40%) in both the components are compulsory. Grades may be given accordingly. Assumptions can be made if necessary and specify them. 10

Similar program can be found on this link http://cssimplified.com/c-programming/a-c-program-to-process-the-students-evolution-records-using-structures

 

(b) What is the difference between ” &” and. “&&’? Explain with an example. 5       

Solved program can be found on this link http://cssimplified.com/c-programming/explain-use-of-comma-operator-in-c-and-what-is-the-difference-between-and

Draw a corresponding flow chart to find the factorial of a given number using recursion. 10m Dec2008

1. (a) Design an algorithm, draw a corresponding flow chart and write a program in ‘C’, to find the factorial of a given number using recursion. 10m Dec2008

 

Flowchart:

FlowChart_Factorial_Recursive

Code:

#include<stdio.h>
void main()
{
int factorial();
int FACT,NUM;
clrscr();
printf(“ENTER NUMBER : “);
scanf(“%d”,&NUM);
if(NUM>0)
{
FACT=factorial(NUM);
printf(“\nFACTORIAL OF GIVEN NUMBER IS %d “,FACT);
}
else
printf(“\nERROR:GIVEN NUMBER IS %d NEGATIVE”,NUM);
getch();
}

int factorial(int N)
{
int RESULT;
if(N==1)
return(1);
else
RESULT=N*factorial(N-1);
return(RESULT);
}

#include<stdio.h>
void main()
{
int factorial();
int FACT,NUM;
clrscr();
printf("ENTER NUMBER : ");
scanf("%d",&NUM);
if(NUM>0)
{
FACT=factorial(NUM);
printf("\nFACTORIAL OF GIVEN NUMBER IS %d ",FACT);
}
else
printf("\nERROR:GIVEN NUMBER IS %d NEGATIVE",NUM);
getch();
}
int factorial(int N)
{
int RESULT;
if(N==1)
return(1);
else
RESULT=N*factorial(N-1);
return(RESULT);
}

 Screen Shots:

 C_program_Factorial

C_program_Factorial_Out

(b) Write a’C’ program to find whether a given five digits number is a palindrome. 10

Solved program can be found on this link http://cssimplified.com/c-programming/write-a-recursive-program-in-c-to-find-whether-a-given-five-digit-number-is-a-palindrome-or-not-10m-dec2005

 

(c) Write a program in’C’ to find all Armstrong numbers in the range of 0 and 999.

Hint: An Armstrong number is an integer such that sum of the cubes of its digits is equal to the number itself, e.g.: 153 is Armstrong number. 10

Solved program can be found on this link http://cssimplified.com/c-programming/a-c-program-to-find-all-armstrong-numbers-in-the-range-of-0-to-999

Write a program in 8086 assembly Ianguage that converts each character of string to upper case and to the next character 7m Jun2008

Write a program in 8086 assembly Ianguage that accepts a character string, of maximum 10 characters, from the keyboard, converts each character of string to upper case and converts each character to the next character. i.e. A to B, B to C,and so on. Finally display the string on the screen. 7m Jun2008

 

DATA SEGMENT
MSG1 DB 10,13,’ENTER ANY STRING :- $’
MSG2 DB 10,13,’LENGTH OF STRING IS :- $’
MSG3 DB 10,13,’REVERSE OF ENTERED STRING IS :- $’

P1 LABEL BYTE
M1 DB 0BH
L1 DB ?
P11 DB 0BH DUP (‘$’)

DATA ENDS

DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

DISPLAY MSG1

LEA DX,P1
MOV AH,0AH
INT 21H

DISPLAY MSG2

MOV DL,L1
ADD DL,30H
MOV AH,2
INT 21H

DISPLAY MSG3

LEA SI,P11

MOV CL,L1
MOV CH,0

CHECK:
CMP [SI],61H
JB DONE

CMP [SI],5BH

UPR: SUB [SI],20H

DONE: INC [SI]
INC SI
LOOP CHECK

DISPLAY P11

MOV AH,4CH
INT 21H
CODE ENDS
END START

 

DATA SEGMENT
MSG1 DB 10,13,'ENTER ANY STRING :- $'
MSG2 DB 10,13,'LENGTH OF STRING IS :- $'
MSG3 DB 10,13,'REVERSE OF ENTERED STRING IS :- $'
P1 LABEL BYTE
M1 DB 0BH
L1 DB ?
P11 DB 0BH DUP ('$')
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
DISPLAY MSG1
LEA DX,P1
MOV AH,0AH
INT 21H
DISPLAY MSG2
MOV DL,L1
ADD DL,30H
MOV AH,2
INT 21H
DISPLAY MSG3
LEA SI,P11
MOV CL,L1
MOV CH,0
CHECK:
CMP [SI],61H
JB DONE
CMP [SI],5BH
UPR: SUB [SI],20H
DONE: INC [SI]
INC SI
LOOP CHECK
DISPLAY P11
MOV AH,4CH
INT 21H
CODE ENDS
END START

Screen shots: -

Asm_program_UpperCase_and_next_char

After Execution: -

Asm_program_UpperCase_and_next_char_Out

 

 

5(c) What is the significance of FAT? What are the limitations of FAT 16? 4

Solved program can be found on this link http://cssimplified.com/computer-organisation-and-assembly-language-programming/what-is-the-significance-of-fat-what-are-the-limitations-of-fat-164m-jun2006

Explain the working of DVD-ROM with ihe help of block diagram. 4m Jun2008

Explain the working of DVD-ROM with the help of block diagram. 4m Jun2008

 

CD-ROM and DVD-ROM

Optical disks use Laser Disk Technology, which is the latest, and the most promising technology for high capacity secondary storage. The advent of the compact disk digital audio system, a non-erasable optical disk, paved the way for the development of a new low-cost storage technology. In optical storage devices the information is written using a laser beam. We will discuss here the use of some optical disks such as CD-ROM and DVD-ROM devices that are now becoming increasingly popular in various computer applications.

CD_DVD

 DVD-ROM (Digital Versatile Disk Read Only Memory):

DVD-ROM uses the same principle as a CD-ROM for reading and writing. However, a smaller wavelength laser beam is used. The total capacity of DVD-ROM is 8.5GB. In double-sided DVD-ROM two such disks are stuck back to back which allows recording on both sides. This requires the disk to be reversed to read the reverse side. With both side recording and with each side storing 8.5GB the total capacity is 17GB.

 

In both CD-ROMs and DVD-ROMs, the density of data stored is constant throughout the spiral track. In order to obtain a constant readout rate the disk must rotate faster, near the center and slower at the outer tracks to maintain a constant linear velocity (CLV) between the head and the CD-ROM/DVD-ROM platter. Thus CLV disks are rotated at variable speed. Compare it with the mechamism of constant angular velocity (CAV) in which disk is rotated at a constant speed. Thus, in CAV the density of information storage on outside sectors is low.

 

The main advantage of having CAV is that individual blocks of data can be accessed at semi-random mode. Thus the head can be moved from its current location to a desired track and one waits for the specific sector to spin under it.

The main disadvantage of CAV disk is that a lot of storage space is wasted, since the longer outer tracks are storing the data only equal to that of the shorter innermost track. Because of this disadvantage, the CAV method is not recommended for use on CD ROMs and DVD-ROMs.

 

What is the significance of FAT? What are the limitations of FAT 16? 4

Solved program can be found on this link http://cssimplified.com/computer-organisation-and-assembly-language-programming/what-is-the-significance-of-fat-what-are-the-limitations-of-fat-164m-jun2006

Explain the operation of a micro programmed control unit with the help of a diagram. 8m Jun2008

Explain the operation of a micro programmed control unit with the help of a diagram. 8m Jun2008

 

THE MICRO-PROGRAMMED CONTROL

The logic of the control unit is specified by a micro-program. A micro-program is also called firmware (midway between the hardware and the software). It consists of:

(a) One or more micro-operations to be executed; and

(b) The information about the micro-instruction to be executed next.

The general configuration of a micro-programmed control unit is demonstrated in Figure 5 below:

Control_Unit_micro_Prog

The micro-instructions are stored in the control memory. The address register for the control memory contains the address of the next instruction that is to be read. The control memory Buffer Register receives the micro-instruction that has been read. A micro-instruction execution primarily involves the generation of desired control signals and signals used to determine the next micro-instruction to be executed. The sequencing logic section loads the control memory address register. It also issues a read command to control memory. The following functions are performed by the micro-programmed control unit:

1. The sequence logic unit specifies the address of the control memory word that is to be read, in the Address Register of the Control Memory. It also issues the READ signal.

2. The desired control memory word is read into control memory Buffer Register.

3. The content of the control memory buffer register is decoded to create control signals and next-address information for the sequencing logic unit.

4. The sequencing logic unit finds the address of the next control word on the basis of the next-address information from the decoder and the ALU flags.

This decoder translates the opcode of the IR into a control memory address.