Five Interesting Programs of C Language with Solution.
Prepared by Hitesh Vataliya
1. Write interactive C Program for create a simple multiple choice question (MCQ) examination of 25 questions for 50 marks along with evaluation process too.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int marks=0,i;
int a[25],s[]={3,2,2,1,2,4,2,1,4,3,1,3,2,1,2,3,1,2,3,4,2,1,4,1,1};
char q[25][1000]={"Which of the following function must contain in all c programs? \n1.system() \n2.start() \n3.main \n4.program() \nEnter your choise: ",
"What punctuation must used to the end of the line in c expression statement?\n1.dot\n2.semicolon\n3.colon\n4.quotes\nEnter your choise: ",
"What Symbol must used to beginning and ending of code block?\n1.()\n2.{}\n3.[]\n4.<>\nEnter your choise: ",
"Which value return to os after successfully completion of the c program?\n1. Zero\n2. One\n3. Two\n4.Ten\nEnter your choise: ",
"Which of the operator is used to compare two values?\n1. =\n2. ==\n3. :=\n4. +=\nEnter your choise: ",
"Which one of the following is not correct data type in c?\n1. int\n2. double\n3. float\n4. real\nEnter your choise: ",
"Choose the logical and operator?\n1. &\n2. &&\n3. &&&\n4. ||\nEnter your choise: ",
"Choose the Bitwise and operator?\n1. &\n2. &&\n3. &&&\n4. ||\nEnter your choise: ",
"Choose the Logical OR operator?\n1. &\n2. &&\n3. |\n4. ||\nEnter your choise: ",
"Choose the Bitwise OR operator?\n1. &\n2. &&\n3. |\n4. ||\nEnter your choise: ",
"Choose the Arithmetic operator?\n1. +\n2. ==\n3. &&\n4.||\nEnter your choise: ",
"Choose the increment operator?\n1. +\n2. -\n3. ++\n4. ||\nEnter your choise: ",
"Choose the multiplication operator?\n1. +\n2. *\n3. -\n4. >\nEnter your choise: ",
"Choose the assignment operator?\n1. =\n2. ==\n3. |\n4. ||\nEnter your choise: ",
"Choose the shorthand operator?\n1. =\n2. -=\n3. ==\n4. ||\nEnter your choise: ",
"Choose the ternary operator?\n1. &\n2. &&\n3. ?:\n4. ||\nEnter your choise: ",
"function is used to find size of string?\n1. strlen()\n2.strcmp()\n3.strrev\n4.strcat()\n Enter your choise: ",
"function is used to compare two strings?\n1. strlen()\n2.strcmp()\n3.strrev\n4.strcat()\n Enter your choise: ",
"function is used to find reverse of string?\n1. strlen()\n2.strcmp()\n3.strrev\n4.strcat()\n Enter your choise: ",
"function is used to merge strings?\n1. strlen()\n2.strcmp()\n3.strrev\n4.strcat()\n Enter your choise: ",
"function is used to find square root of number?\n1. pow()\n2.sqrt()\n3.root\n4.cos()\n Enter your choise: ",
"function is used to find power of number?\n1. pow()\n2.sqrt()\n3.root\n4.cos()\n Enter your choise: ",
"function is used to find cos of number?\n1. pow()\n2.sqrt()\n3.root\n4.cos()\n Enter your choise: ",
"function is used to find tangent of number?\n1. tan()\n2.sqrt()\n3.root\n4.cos()\n Enter your choise: ",
"function is used to find log of number?\n1. log()\n2.sqrt()\n3.root\n4.cos()\n Enter your choise: "};
for(i=0;i<25;i++)
{
printf("\n\n---Question %d---\n\n",i+1);
printf("%s",q[i]);
scanf("%d",&a[i]);
if(a[i]==s[i])
{
marks=marks+2;
}
}
printf("\n\n\tYou got %d marks out of 50\n\n",marks);
getch();
}
2. Write an interactive C program to illustrate BITWISE operators in C programming language.
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,b=8;
clrscr();
printf("\n\nBitwise and %d",a&b);
printf("\n\nBitwise OR %d",a|b);
printf("\n\nBitwise Ex OR %d",a^b);
printf("\n\nComplement %d",~a);
printf("\n\nShift Left %d",a<<1);
printf("\n\nShift Right %d",a>>1);
getch();
}
3. Write an interactive C program to take two single dimensional arrays of integers and merge them into a single dimensional array, excluding the common elements of both the arrays.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n=0,t=0,flag=0,s1,s2;
int a[50],b[50],c[100];
clrscr();
printf("size of array a : ");
scanf("%d",&s1);
printf("size of array b : ");
scanf("%d",&s2);
for(i=0;i<s1;i++)
{
printf("Enter Element a[%d] : ",i);
scanf("%d",&a[i]);
}
for(i=0;i<s2;i++)
{
printf("Enter Element b[%d] : ",i);
scanf("%d",&b[i]);
}
for(i=0;i<s1;i++)
{ flag=0;
for(t=0;t<n;t++)
{
if(c[t]==a[i])
{ flag=1;
break;
}
}
if(flag==0)
{
c[n]=a[i];
n++;
}
}
for(i=0;i<s2;i++)
{ flag=0;
for(t=0;t<n;t++)
{
if(c[t]==b[i])
{ flag=1;
break;
}
}
if(flag==0)
{
c[n]=b[i];
n++;
}
}
printf("\n\nArray after merge of two and excluding common elements\n");
printf("------------------------------------------------------------\n");
for(i=0;i<n;i++)
{
printf("%d \t",c[i]);
}
getch();
}
4. Write an interactive C program which illustrates the following concepts: (i) Function with no arguments and no return value. (ii) Function with arguments and no return value. (iii) Function with arguments and with return value.
#include<stdio.h>
#include<conio.h>
void fun1()
{
printf("\n-------------------\n");
printf("Hello, this is fun1");
printf("\n-------------------\n");
}
void funadd(int a,int b)
{
int ans=a+b;
printf("\nThe addition is %d\n",ans);
}
int funsqr(int x)
{
return x*x;
}
void main()
{
int s;
clrscr();
printf("\n\nFunction with no arguments and no return value\n\n");
fun1();
printf("\n\nFunction with arguments and no return value\n\n");
funadd(10,200);
printf("\n\nFunction with arguments and return value\n\n");
s=funsqr(9);
printf("\n\nThe square is : %d",s);
getch();
}
5. Write an interactive C program to manage the assignments at study centres for the first semester courses of MCA (MCS-011, 012, 13, 014, 015, MCSL-016 and MCSL-017). Maximum marks for each assignment is 100 marks and weightage is 25%. Attending the viva-voce at the study centre for each assignment is compulsory. Pass percentage in each assignment is 40%. (Note: Use Structures concept).
#include<stdio.h>
#include<conio.h>
struct Assignments
{
int enrolmentno;
int ma[7];
}s[60];
void main()
{ FILE *f;
int i,n;
clrscr();
f=fopen("mcasem1.txt","w");
for(n=0;n<60;n++)
{
printf("\n\nEnter student enrolment number : ");
scanf("%d",&s[n].enrolmentno);
for(i=0;i<7;i++)
{
printf("Enter marks of mcs0%d : ",i+11);
scanf("%d",&s[n].ma[i]);
}
}
fprintf(f,"enrolno\tmcs011\tmcs012\tmcs013\tmcs014\tmcs015\tmcsl016\tmcsl017");
for(n=0;n<60;n++)
{
printf("\n\n%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d",s[n].enrolmentno,s[n].ma[0],s[n].ma[1],s[n].ma[2],s[n].ma[3],s[n].ma[4],s[n].ma[5],s[n].ma[6]);
fprintf(f,"\n\n%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d",s[n].enrolmentno,s[n].ma[0],s[n].ma[1],s[n].ma[2],s[n].ma[3],s[n].ma[4],s[n].ma[5],s[n].ma[6]);
}
getch();
}
[Note : These Programs are asked in IGNOU MCA Sem 1 Assignment. In this blog you can find the solution of each question. ]
If you are interested for learning C Programming Language. VISIT : WEBSITE