Category Archives: C Theory

All important theory content placed here!

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… Read More »

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: 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);… Read More »

Write a program and flowchart to display the following pattern: 6m Jun2008

Write a program and flowchart to display the following pattern: 6m Jun2008 1 2 3 4 5 6 7 8 9 1 0 11 12 13 14 15 16 17 18 19 20 21   Code: #include<stdio.h> void main() { int I,J,C=1; clrscr(); printf(“Result :\n”); for(I=0;I<6;I++) { printf(“\n”); for(J=0;J<=I;J++) { printf(“%d “,C++); } printf(“\n”); }… Read More »

Give a brief note on null pointer assignment. Write a program to illustrate this concept. 6m Jun2008

Give a brief note on null pointer assignment. Write a program in ‘C’ to illustrate this concept. 6m Jun2008 Null Pointer Assignment It does make sense to assign an integer value to a pointer variable. An exception is an assignment of 0, which is sometimes used to indicate some special condition. A macro is used… Read More »

Write a program to read formatted data from the file. 6m Jun2008

Write a program to read formatted data from the file. 6m Jun2008 CODE:- #include<stdio.h> void main() { int account; char name[30]; double bal; FILE *fp; if((fp=fopen(“data.txt”,”r”))== NULL) printf(“FILE not present \n”); else do{ fscanf(fp,”%d%s%lf”,&account,name,&bal); if(!feof(fp)) { if(bal==0) printf(“%d %s %lf\n”,account,name,bal); } }while(!feof(fp)); getch(); } [codesyntax lang=”c”] #include<stdio.h> void main() { int account; char name[30]; double… Read More »

Differences between structure and union in C programming with example

What are the differences between structure and union? Give one illustrative example of usage of the union. 8m Jun2008 Structure in C programming Structure is commonly referred to as a user-defined data type. C’s structures allow you to store multiple variables of any type in one place (the structure). A structure can contain any of… Read More »

Write a macro to find the smallest number among 3 given numbers. 7m Jun2007

Write a macro to find the smallest number among 3 given numbers. 7m Jun2007 Code: #include<stdio.h> #define MIN(X,Y)(X<Y ? X:Y) #define SMALL(X,Y,Z)(MIN(X,Y)<Z ? MIN(X,Y):Z) void main() { int FIRST,SECOND,THIRD; clrscr(); printf(“ENTER NUMBERS TO COMPARE\n”); printf(“\nFIRST NUMBER : “); scanf(“%d”, &FIRST); printf(“\nSECOND NUMBER : “); scanf(“%d”, &SECOND); printf(“\nTHIRD NUMBER : “); scanf(“%d”, &THIRD); printf(“\nThe SMALLER NUMBER IS… Read More »

Design an algorithm, draw a corresponding flowchart and then write a program in C to convert a given string to lower case. 10m Jun2008

Design an algorithm, draw a corresponding flowchart and then write a program in C to convert a given string to lower case. 10m Jun2008   Algorithm Step 1: Input String Step 2: Initilise Pointer C to initial character of String Step 3: while(C != NULL) { if (*C>=’A’ && *C<=’Z’) { *C=*C+32 } Step 4:… Read More »

Write a program in ‘C’ language that accepts the name of a file as input and prints those lines of the file which have the word ‘this’. 10m Dec2007

Write a program in ‘C’ language that accepts the name of a file as input and prints those lines of the file which have the word ‘this’. 10m Dec2007    #include<stdio.h> void main() { FILE *fp; int cnt=0; char str[80],lines[400]; clrscr(); if ((fp=fopen(“test.txt”,”r”))== NULL) { printf(“File does not exist\n”); exit(0); } while(!(feof(fp))) { fgets(str,80,fp); if(strcmp(“this”,str))… Read More »

A program in ‘C’ language which accepts enrollment number as input and prints the name of student. pairs of students in the form of a matrix. 10m Dec2007

Write a program in ‘C’ language which accepts the enrollment number of a student as input and prints the name of that student. The program should initially store information about the (name, enrollment number) pairs of students in the form of a matrix. 10m Dec2007   #include<stdio.h> struct student { unsigned long int ENROL; char… Read More »