Category Archives: C Theory

All important theory content placed here!

Write an algorithm and draw flowchart to find whether a given string S1 is substring of another string S2. 10m Dec2007

Write an algorithm and draw flowchart to find whether a given string S1 is substring of another string S2. 10m Dec2007   Algorithm Step 1: Input String and Substring (Note: Substring should be smaller than String) Step 2: Find Length of String (Len1) and Find Length of Substring (Len2) Step 3: flag <- 0 Step… Read More »

List and explain the precedence of Arithmetic, Logical and Relational operators in ‘C’. 10m Dec2007

List and explain the precedence of Arithmetic, Logical and Relational operators in ‘C’. 10m Dec2007 C uses a certain hierarchy to solve such kind of mixed expressions. The hierarchy and associatively of the operators discussed so far is summarized in Table. The operators written in the same line have the same priority. The higher precedence operators are written… Read More »

Write the syntax for the declaration of a function. Also discuss the parameter passing methods with an example program. 10m Dec2007

Explanation of FUNCTION: A function is a block of code that has a name and it has a property that it is reusable i.e. it can be executed from as many different points in a C Program as required. Function groups a number of program statements into a unit and gives it a name. This… Read More »

Design an algorithm, draw a corresponding flow chart and write a ‘C’ program for Binary Search, to search a given number among the list of numbers. 10m Dec2007

Design an algorithm, draw a corresponding flow chart and write a ‘C’ program for Binary Search, to search a given number among the list of numbers. 10m Dec2007   Algorithm Step 1: Declare an array ‘k’ of size ‘n’ i.e. k(n) is an array which stores all the keys of a file containing ‘n’ records… Read More »

Design an algorithm, draw a corresponding flow chart and write a program in C, to swap the values using pass by value and pass by reference methods. 10m Jun2007

Design an algorithm, draw a corresponding flow chart and write a program in C, to swap the values using pass by value and pass by reference methods. 10m Jun2007  FlowChart: Program to swap two values (Pass By Value):- #include <stdio.h> main ( ) { int x = 2, y = 3; clrscr(); void swap(int, int);… Read More »

Write a program to generate the pattern 10m Jun2007

Write a program to generate the pattern 10m Jun2007 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5   Code:   #include<stdio.h> void main() { char C[]=”12345″; int I,J; clrscr(); printf(“Result :\n”); for(I=0;I<5;I++) { printf(“\n”); for(J=0;J<=I;J++) { printf(“%c “,C[J]); } printf(“\n”); } getch(); } [codesyntax lang=”c”] #include<stdio.h> void main()… Read More »

Explain the concept of a function returning a pointer with an example 6m Jun2007

Explain the concept of a function returning a pointer in C with an example 6m Jun2007 Function returning a pointer in C A function can also return a pointer to the calling program, the way it returns an int, a float or any other data type. To return a pointer, a function must explicitly mention… Read More »

Write a macro to find the sum of n numbers. 7m Jun2007

Write a macro to find the sum of n numbers. 7m Jun2007 Code: #include<stdio.h> # define SUM(n) ( (n * (n+1)) / 2 ) void main() { int num; clrscr(); printf(” Enter number : “); scanf(“%d”,&num); printf(“\n Sum of n numbers : %d “,SUM(num)); getch(); } [codesyntax lang=”c”] c#include<stdio.h> # define SUM(n) ( (n *… Read More »

Write a program in C, to copy file1 to another file2 in the same directory 7m Jun2007

Write a program in C, to copy file1 to another file2 in the same directory. 7m Jun2007 Code: #include<stdio.h> void main() { int ch,size=0; FILE *fp1; FILE *fp2; clrscr(); if((fp1=fopen(“readme.txt”,”r”))==NULL) { printf(“FILE DOES NOT EXIST\n”); exit(0); } if((fp2=fopen(“duplicate.txt”,”w”))==NULL) { printf(“FILE CAN NOT BE CREATED\n”); exit(0); } while(!feof(fp1)) { ch=getc(fp1); putc(ch,fp2); size++; } fclose(fp1); fclose(fp2); printf(”… Read More »

Draw a flow chart and write a program in C to sort a given list of numbers. 7m Jun2007

Draw a flow chart and write a program in C to sort a given list of numbers. 7m Jun2007   Flowchart: Code: #include<stdio.h> void main() { int I,J,Temp,List[]={6,3,0,4,8,2,5,9,1,7}; clrscr(); printf(“List Before Sorting :\n”); for(J=0;J<10;J++) { printf(“%d “,List[J]); } for(I=0;I<10;I++) { for(J=0;J<=I;J++) { if(List[J]>List[I]) { Temp=List[I]; List[I]=List[J]; List[J]=Temp; } } } printf(“\nList Before Sorting :\n”); for(J=0;J<10;J++)… Read More »