Category Archives: C Programs

All C programs placed here!

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 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 »

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 »

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 »

C029 A C program with a function that returns the minimum and the maximum value in an array of integers

void minmax(int array[],int length,int *min,int *max); //prototype Let’s identify variables needed for this program. In this program, we need several variables to store array of decimal numbers and count the length of array and store minimum and maximum of the array. First variable will be the one which will save the list of integers in… Read More »

C027 A C program that multiply two complex numbers

Let’s identify variables needed for the structure inside the program. In this complex structure, we need two variables to store real part and imaginary part of complex number. First variable will be the one which will save the real part of complex number and it will be REAL. Second variable will be the one which… Read More »

C026 A C program to process the students evaluation records using structures

Let’s identify variables needed for the structure inside the program. In this student structure, we need several variables to store string as name and number for enrollment number and marks of student appeared in the term end examination. First variable will be the one which will save the enrollment number and it will be ENROL.… Read More »

C025 A C program to input a string and output the reversed string using pointer notation

Let’s identify variables needed for this program. In this program, we need several variables to store string and count the number of characters in the given string. First variables will be the one which will save the string entered by the user and reverse of it. So it will be S[50] and R[50]. In C… Read More »