Monday, 30 November 2015

Function and types of it and String Management Programs.

Function And String Management Programs

Prepared By Hitesh Vataliya
For More Details : Click Here

1. Function and types of functions.

#include<stdio.h>
#include<conio.h>

// Function without any argument and without return type.
void funsum()
{
int a,b,sum=0;
a=11;
b=10;
sum=a+b;
printf("\n\nFunsum () The addition is %d",sum);
}

// Function with two arguments and without return type.
void fun2(int x,int y)
{
int sum=x+y;
printf("\n\nfun2() The sum is %d",sum);
}

// Function with two arguments and with return type.
int fun3(int n1,int n2)
{
return n1+n2;
}
void main()
{
int s;
clrscr();
funsum(); // call of function.
fun2(10,11);
s=fun3(10,11);
printf("\n\nfun3()  The sum is %d",s);
getch();
}

2. Create a program for calculator with help of functions for add,sub,mul,div.

#include<stdio.h>
#include<conio,h>
int funadd(int n1,int n2)
{
return n1+n2;
}
int funsub(int n1,int n2)
{
return n1-n2;
}
int funmul(int n1,int n2)
{
return n1*n2;
}
float fundiv(int n1,int n2)
{
return ((float)n1)/n2;
}

void main()
{
int ans,a,b;
        float d;
clrscr();
        printf("Enter 1 for addition \n\t Enter 2 for substraction \n\t Enter 3 for multiplication \n\t Enter 4 for division \n\t Enter you choise : ");
        scanf("%d",&c);
        switch(c)
       {
                 case 1: ans=funsum(a,b);
                             printf("The addition is %d",ans);
                             break;
                 case 2: ans=funsub(a,b);
                             printf("The substraction is %d",ans);
                             break;
                 case 3: ans=funmul(a,b);
                             printf("The multiplication is %d",ans);
                             break;
                 case 4: d=fundiv(a,b);
                             printf("The division is %f",d);
                             break;
                 default: printf("Invalid Choise");
                             break;
      }
       getch();
}

3. Write a program to find factorial of given number using recursive function.

#include<stdio.h>
#include<conio.h>
//function calls itself is known as recursion.
int fun1(int n); //factorial using recursion
void main()
{       int ans;
clrscr();
ans=fun1(5);
printf("\n\n\t\tThe factorial of 5 is %d",ans);
getch();
}
int fun1(int n)
{
if(n==0||n==1)
{
return 1;
}
else
{
return n*fun1(n-1);
}
}

4. Write a program to get fibonacci series as output using recursion.

#include<stdio.h>
#include<conio.h>

void fib(int a,int b,int n)
{
int c;
if(n>0)
{
c=a+b;
a=b;
b=c;
printf("%d ",c);
fib(a,b,n-1);
}
}
void main()
{      
clrscr();
printf("\n\n\t\t0 1 ");
fib(0,1,6);
getch();
}

5. Write a program to find occurrence of  character's from given string.
if name is "aakash" 
then output will be
char  occurrence
a         3
h         1
k         1
s         1

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[]="Software Programming";
int count[26]={0};
char k[26];
int l,i,j;
clrscr();
l=strlen(name);
for(i=0;i<26;i++)
{
k[i]=i+65;
}
strupr(name);  // used to convert name to upper case
for(i=0;i<l;i++)
{
for(j=0;j<26;j++)
{
if(k[j]==name[i])
{
count[j]++;
break;
}
}
}
printf("\n\n\t\tCharacter\t\tOccurances\n");
for(j=0;j<26;j++)
{
if(count[j]>0)
{
printf("\n\t\t%c\t\t\t\t%d",k[j],count[j]);
}
}
getch();
}

If you are interested for learning C Programming Language.  VISIT : WEBSITE

Friday, 27 November 2015

Array programs with example of searching and sorting techniques in C Language.

Array Programs in C Language.

Prepared By Hitesh Vataliya

1. Write a program to find sum of n integers stored in the given array.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100];
int i,sum=0,n;
clrscr();
printf("Enter total elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter value: ");
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
printf("\n\n The ans is %d",sum);
getch();
}


2. Write a program to find avg of 2 subject marks of 3 students using array.

#include<stdio.h>
#include<conio.h>
void main()
{
int marks1[3],marks2[3];
float avg[3];
int i,k,n;
clrscr();
for(i=0;i<3;i++)
{
printf("Enter Marks for subject1 : ");
scanf("%d",&marks1[i]);
printf("Enter Marks for subject2 : ");
scanf("%d",&marks2[i]);
avg[i]=(marks1[i]+marks2[i])/2.0;
}
for(i=0;i<3;i++)
{
printf("\n\navg of student %d is %f",i+1,avg[i]);
}
getch();
}

3. Write a program to find minimum number from given list of array elements.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100];
int i,min,n;
clrscr();
printf("Enter total elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter value: ");
scanf("%d",&a[i]);
}
min=a[0];
for(i=0;i<n;i++)
{
if(a[i]<min)
{
min=a[i];
}
}
printf("\n\n The min is %d",min);
getch();
}


4. Write a program to find maximum number from given list of array elements.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100];
int i,max=0,n;
clrscr();
printf("Enter total elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter value: ");
scanf("%d",&a[i]);
if(a[i]<0)
{
i--;
printf("\nEnter positive value\n");
}
}
for(i=0;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
printf("\n\n The max is %d",max);
getch();
}

5. Write a program to find or search number from given list of array elements.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100];
int i,k,n;
clrscr();
printf("Enter total elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter value: ");
scanf("%d",&a[i]);
}
printf("Enter value to search: ");
scanf("%d",&k);
for(i=0;i<n;i++)
{
if(a[i]==k)
{
printf("Element Found.");
break;
}
}
if(i==n)
{
printf("\n\n Element Not Found.");
}
getch();
}

6. Write a program to sort given list of array elements using bubble sort.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100];
int i,temp,n,j;
clrscr();
printf("Enter Size of an array: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter value : ");
scanf("%d",&a[i]);
}

for(i=0;i<n-1;i++)
{
for(j=0;j<n-(i+1);j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("\n\n\t\t%d",a[i]);
}
getch();
}

7. Write a program to sort given list of array elements using selection sort.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100];
int i,temp,n,j,minpos;
clrscr();
printf("Enter Size of an array: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter value : ");
scanf("%d",&a[i]);
}

for(i=0;i<n;i++)
{
minpos=i;
for(j=i+1;j<n;j++)
{
if(a[j]<a[minpos])
{
minpos=j;
}
}
temp=a[i];
a[i]=a[minpos];
a[minpos]=temp;
}
for(i=0;i<n;i++)
{
printf("\n\n\t\t%d",a[i]);
}
getch();
}

[Note : Here in this blog given some of array program to the candidates who are beginners in c programming. ]

If you are interested for learning C Programming Language Visit: Website

Five Interesting Programs of C Language with Solution.

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

If You wants to learn C Programming Language For BCA, MCA, Diploma, Degree Engineering (BE), ME, Then Visit : VATALIYA TUITION CLASSES.

FINAL YEAR PROJECT TRAINING

PHP PROJECT TRAINING

JAVA PROJECT TRAINING 

ASP.NET PROJECT TRAINING

IGNOU BCA/MCA

NIELIT O LEVEL/A LEVEL/B LEVEL/C LEVEL

GTU DIPLOMA/BE/ME IN COMPUTERS/IT