Category Archives: C Programs

All C programs placed here!

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: #include<stdio.h> #include<math.h>… Read More »

Write a macro to demonstrate #define, #if, #else preprocessor commands. 6m Jun 2010

Write a macro to demonstrate #define, #if, #else preprocessor commands. 6    Code: #include <stdio.h> #define CHOICE 100 int my_int = 0; #if (CHOICE == 100) void set_my_int() { my_int = 35; } #else void set_my_int() { my_int = 27; } #endif main () { set_my_int(); clrscr(); printf(“%d\n”, my_int); getch(); } [codesyntax lang=”c”] #include <stdio.h> #define… Read More »

Write a program in ‘C’ to find a sum of square of odd numbers. 6m Jun 2010

Write a program in ‘C’ to find a sum of square of odd numbers :- 12 +32+ 52+ 72 +92+ +N2   Code:- #include<stdio.h> void main() { int NUM,i,j,SUM=0; clrscr(); printf(“\nENTER INTERGER NUMBER : “); scanf(“%d”,&NUM); for(i=1;i<NUM+1;i++) { if(i%2!=0) { SUM=SUM+(i*i); } } printf(“\nTHE SUM OF SQUARE OF ODD NOS. TILL %d NO. IS : %d”,NUM,SUM);… Read More »

Write a Program in ‘C’ to copy one file to another. The program should read the filenames at command line. 10m Jun2009

Write a Program in ‘C’ to copy one file to another. The program should read the filenames at command line. 10m Jun2009 Code: #include<stdio.h> int main(int argc,char *argv[]) { FILE *fs,*ft; int ch; if(argc!=3) { printf(“Invalide numbers of arguments.”); return 1; } fs=fopen(argv[1],”r”); if(fs==NULL) { printf(“Can’t find the source file.”); return 1; } ft=fopen(argv[2],”w”); if(ft==NULL)… Read More »

Write a Program in ‘C’ to print the following output ‘n’ rows. 10m june2009

Write a Program in ‘C’ to print the following output ‘n’ rows. For example, if n=3, the following should be output by the program: 10m june2009   #include <stdio.h> void main() { int I,J,N=3,K=0,ODD=1,SPACE; clrscr(); SPACE=N; for(I=1;I<=N;I++) { for(J=1;J<SPACE;J++) { printf(” “); } K=0; for(J=1;J<=ODD;J++) { if(J<=I) { K++; } else { K–; } printf(“%d… Read More »

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

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

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

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

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 »