Friday 22 March 2013

Download PDF in All Page

Filled under:

How to Download PDF E-Book Using my Site

Show Right Side bar in Newest Education and Click Download as PDF Link

Then Click Download Button in Open New box.
Note: Make sure you open only one page one link.
Example: 
http://newesteducation.blogspot.in/2013/03/bca-html-programs.html 

Posted By New18:44

Sunday 17 March 2013

FYBCA Sem 2 C Programs

Filled under:

Advanced Programming Language of ‘C’

Program 1
//1. Write a program to check the no. is Palindrome or not using UDF.

#include<stdio.h>
#include<conio.h>
void pali(int n);
void main()
{
int n;
clrscr();
printf("Enter Number=");
scanf("%d",&n);
pali(n);
getch();
}
void pali(int n)
{
int x,y,s=0,m;
m=n;
while(n!=0)
{
x=n%10;
s=s*10+x;
y=n/10;
n=y;
}
if(m==s)
{
printf("%d is Palindrome Number",m);
}
else
{
printf("%d is Not Pelindrome Number",m);
}
}
Output
Enter Number=12
12 is Not Pelindrome Number
&
Enter Number=11
12 is Pelindrome Number

Program 2
//2. Write a program to find factorial of given no using UDF.

#include<stdio.h>
#include<conio.h>
void fact(int n);
void main()
{
int n;
clrscr();
printf("Enter Number:");
scanf("%d",&n);
fact(n);
getch();
}
void fact(int n)
{
int f=1,i;
for(i=n;i>=1;i--)
{
f=f*i;
}
printf("Factorial=%d\n",f);
}
Output
Enter Number:5
Factorial=120

Program 3
//3. Write a program to find factorial of given no using recursion.

#include<stdio.h>
#include<conio.h>
int fact(int n);
void main()
{
int a,n;
clrscr();
printf("Enter Number=");
scanf("%d",&n);
a=fact(n);
printf("fact=%d\n",a);
}
int fact(int n)
{
int f=1;
if(n==1)
{
return(1);
}
f=n*fact(n-1);
return(f);
}
Output
Enter Number=6
fact=720

Program 4
//4. Write a program to display first 25 terms of Fibonacci series using recursion.

#include<stdio.h>
#include<conio.h>
long int fibo(long int a,long int b,long int i);
void main()
{
long int a=0,b=1;
printf("Fibonacci Series\n");
printf("%d\n",a);
printf("%d\n",b);
fibo(a,b,23);
getch();
}
long int fibo(long int a,long int b,long int i)
{
long int c;
c=a+b;
printf("%ld\n",c);
a=b;
b=c;
if(i==1)
{
return(0);
}
fibo(a,b,i-1);
return(1);
}
Output
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368

Program 5
//5. Write a program using a recursive function to find the GCD(Greatest Common Divisor) of two Positive integer numbers.

#include<stdio.h>
#include<conio.h>
int gcd(int a,int b,int i);
void main()
{
int a,b,m;
clrscr();
printf("Enter Positive Number=");
scanf("%d",&a);
printf("Enter No b=");
scanf("%d",&b);
if(a<b)
{
m=a;
}
else
{
m=b;
}
gcd(a,b,m);
getch();
}
int gcd(int a,int b,int i)
{
if(a%i==0&&b%i==0)
{
printf("GCD=%d",i);
return(01);
}
else
{
gcd(a,b,i-1);
return(0);
}
}
Output
Enter Positive Number=12
Enter No b=25
GCD=1

Program 6
//6. Write a program to swap value of two integer number using UDF
Wrong Output
#include<stdio.h>
#include<conio.h>
void fun1(void);
void fun2(void);
void main()
{
int m=1000;
clrscr();
fun2();
printf("%d\n",m);
}
void fun1(void)
{
auto int m=10;
printf("%d\n",m);
}
void fun2(void)
{
int m=100;
fun1();
printf("%d\n",m);
getch();
}

Program 7
//7. Write a function prime that returns 1 if its argument is a prime and return zero Otherwise.

#include<stdio.h>
#include<conio.h>
int prime(int n);
void main()
{
int a,n;
printf("Enter Number:");
scanf("%d",&n);
a=prime(n);
if(a==1)
{
printf("%d is Prime Number\n",n);
}
else
{
printf("%d is Not Prime Number\n",n);
}
}
int prime(int n)
{
int i;
for(i=2;i<-1;i++)
{
if(n%i==0)
{
return(0);
}
}
return(1);
}
Output
Enter Number:5
5 is Prime Number

Program 8

Program 9

Program 10
//10. Write a program that uses a UDF to sort an array of integer.

#include<stdio.h>
#include<conio.h>
void sort(int x[]);
void main()
{
int a[5],i;
clrscr();
for(i=0;i<=4;i++)
{
printf("Enter Number:");
scanf("%d",&a[i]);
}
sort(a);
}
void sort(int x[])
{
int i,j,t;
for(i=0;i<=4;i++)
{
for(j=i+1;j<=4;j++)
{
if(x[i]>x[j])
{
t=x[i];
x[i]=x[j];
x[j]=t;
}
}
}
printf("sorted array=\n");
for(i=0;i<=4;i++)
{
printf("%d\n",x[i]);
}
}

Output
Enter Number:5
Enter Number:4
Enter Number:7
Enter Number:9
Enter Number:10
sorted array=
4
5
7
9
10

Program 11
//11. Write a program to search a number within an array using UDF.

#include<stdio.h>
#include<conio.h>
void search(int x[]);
void main()
{
int a[5],i;
clrscr();
for(i=0;i<=4;i++)
{
printf("Enter Value=");
scanf("%d",&a[i]);
}
search(a);
}
void search(int x[])
{
int n,i,f=0;
printf("Which value you want to search=");
scanf("%d",&n);
for(i=0;i<=4;i++)
{
if(x[i]==n)
{
f=1;
break;
}
}
if(f==1)
{
printf("%d is In the list",n);
}
else
{
printf("%d is Not in the list",n);
}
}
Output
Enter Value=5
Enter Value=7
Enter Value=10
Enter Value=13
Enter Value=5
Which value you want to search=6
6 is Not in the list

Program 12
//12. Write a program which explains the use of nesting of functions.

#include<stdio.h>
#include<conio.h>
void max(int x,int y);
void display(int m);
void main()
{
int x,y;
clrscr();
printf("Enter the value of x:");
scanf("%d",&x);
printf("Enter the value of y:");
scanf("%d",&y);
max(x,y);
}
void max(int x,int y)
{
int m;
if(x>y)
{
m=x;
}
else
{
m=y;
}
display(m);
}
void display(int m)
{
printf("Max=%d\n",m);
}
Output
Enter the value of x:5
Enter the value of y:6
Max=6

Program 13
//13. Write a function power that computes x raised to the power y for integers x and y and return Double-type value.

#include<stdio.h>
#include<conio.h>
double power(int x,int y);
void main()
{
int x,y;
double a;
clrscr();
printf("Enter No1:");
scanf("%d",&x);
printf("Enter No2:");
scanf("%d",&y);
a=power(x,y);
printf("Ans=%f\n",a);
}
double power(int x,int y)
{
int i;
double t=1;
for(i=1;i<=y;i++)
{
t=t*x;
}
return(t);
}
Output
Enter No1:5
Enter No2:3
Ans=125.0000000

Program 14
//14. Define a structure type struct personal that would contain person name, date of joining and salary using this structure to read this information of 5 people and print the same on screen.

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
struct personal
{
char name[20];
char date[20];
long int salary;
};
struct personal p[5];
clrscr();
for(i=0;i<=4;i++)
{
printf("Enter Detail Name, Date and Salary=");
scanf("%s%s%ld",p[i].name,p[i].date,&p[i].salary);
}
printf("\nName\t Date\t\t Salary\t");
for(i=0;i<=4;i++)
{
printf("\n%s \t%s \t%ld",p[i].name,p[i].date,p[i].salary);
}
getch();
}
Output
Enter Detail Name, Date and Salary=Nikulsinh
21-1-2012
5000
Enter Detail Name, Date and Salary=Gavarav
22-2-2012
5000
Enter Detail Name, Date and Salary=Dhrupal
21-1-2012
5000
Enter Detail Name, Date and Salary=Raj
21-3-2012
6000
Enter Detail Name, Date and Salary=Naman
21-1-2012
4500

Name                    Date                      Salary
Nikulsinh             21-1-2012            5000
Gavarav               22-2-2012            5000
Dhrupal                                21-1-2012            5000
Raj                          21-3-2012            6000
Naman                 21-1-2012            4500

Program 15
//15. Design a structure student record to contain name, branch and total marks obtained. Develop a program to read data for 10 students in a class and print them.

#include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
char branch[15];
int total;
};
void main()
{
struct student s[10];
int i;
clrscr();
for(i=0;i<10;i++)
{
printf("Enter Name, Branch, Total=");
scanf("%s%s%d",s[i].name,s[i].branch,&s[i].total);
}
getch();
}

Program 16
//16. Write a program using structure within structure.

//Wrong Output, check and Write on Note book
#include<stdio.h>
#include<conio.h>
struct student
{
int rollno;
char name[20];
 struct birthdate
 {
 int d;
 int m;
 int y;
 }bdate;
 };
void main()
{
struct student s1;
clrscr();
printf("Enter Roll No:");
scanf("%d",&s1.rollno);
printf("Enter Name:");
scanf("%d",s1.name);
printf("Enter Birthdate:");
scanf("%d/%d/%d",&s1.bdate.d,&s1.bdate.m,&s1.bdate.y);
printf("Given Student Date:");
scanf("%d%s%d/%d/%d",&s1.rollno,s1.name,s1.bdate.d,s1.bdate.m,s1.bdate.y);
getch();
}

Program 17
//17. Define a structure called cricket that will describe the following information Player name, Team name, runs using cricket, declare an array player with 10 elements and write a program to read the information about all 10 players and print a team-wise list containing names of players with their runs.

#include<stdio.h>
#include<conio.h>
struct cricket
{
char pname[20];
char tname[15];
int run;
};
void main()
{
struct cricket player[10],t;
int i,j;
clrscr();
for(i=0;i<5;i++)
{
printf("\n Enter Player Name, Team name and Run:");
scanf("%s%s%d",player[i].pname,player[i].tname,&player[i].run);
}
for(i=0;i<5;i++)
{
for(j=i;j<5;j++)
{
if(strcmp(player[i].tname,player[j].tname)<0)         //String Comparison
{
t=player[i];
player[i]=player[j];
player[j]=t;
}
}
}
printf("player\t name\t team name run\n");
for(i=0;i<5;i++)
{
printf("%-20s%-15s%-3d\n",player[i].pname,player[i].tname,player[i].run);
}
getch();
}
Output
Enter Player Name, Team name and Run: Nikulsinh India 600
Enter Player Name, Team name and Run: Gavarav India 500
Enter Player Name, Team name and Run: Priyank Pakistan 400
Enter Player Name, Team name and Run: Naman Pakistan 500
Enter Player Name, Team name and Run: Dhrupal India 500

player name       team name         run
Priyank                 Pakistan               400
Naman                 Pakistan               500
Nikulsinh             India                      600
Gavarav               India                      500
Dhrupal                                India                      500

Program 18
//18. In a program declare following structure member: name, code, age, weight and height. Read all members of the structure for 10 persons and find list of persons with all related data whose weight > 50 and height > 40 and print the same with suitable format and title.

#include<stdio.h>
#include<conio.h>
struct members
{
char name[20];
int code;
int age;
float weight;
float height;
};
void main()
{
struct members s[3];
int i;
float w,h;
clrscr();
for(i=0;i<3;i++)
{
printf("Enter Name, Code, Age, Weight, Height:");
scanf("%s%d%d%f%f",s[i].name,&s[i].code,&s[i].age,&w,&h);
s[i].weight=w;
s[i].height=h;
}
printf("\n\n\n");
for(i=0;i<3;i++)
{
if(s[i].weight>50&&s[i].height>40)
{
printf("%s\t %d\t %d\t %f\t %f\n",s[i].name,s[i].code,s[i].age,s[i].weight,s[i].height);
}
}
}
Output
Enter Name, Code, Age, Weight, Height : Nikulsinh
1
19
51
55
Enter Name, Code, Age, Weight, Height: Dhrupal
2
19
50
75
Enter Name, Code, Age, Weight, Height:              Gavarav
3
19
51
85

Nikulsinh             1              19           51.00000              55.0000
Gavarav               3              19           51.00000              85.0000

Program 19
//19. Write a program to print the value and address of the element.

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
int *p;
clrscr();
printf("Enter No=");
scanf("%d",&a);
printf("Value of a=%d\n",a);
printf("Address of a=%x\n",&a);
p=&a;
printf("Value of a=%d\n",a);
printf("Value of p=%x\n",p);
printf("Value of *p=%d\n",*p);
getch();
}

Output
Enter No=5
Value of a=5
Address of a=fff4
Value of a=5
Value of p=fff4
Value of *p=5

Program 20
//20. Write a program to accept 10 numbers and display its sum using pointer.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,*p,s=0;
clrscr();
for(i=0;i<10;i++)
{
printf("Enter value=");
scanf("%d",&a[i]);
}
p=a;
for(i=0;i<10;i++)
{
s=s+*(p+i);
}
printf("Sum=%d",s);
getch();
}

Output
Enter value=10
Enter value=11
Enter value=16
Enter value=17
Enter value=20
Enter value=18
Enter value=20
Enter value=21
Enter value=25
Enter value=28
Sum=186

Program 21
//21. Write a program to accept 10 numbers and sort them with use of pointer.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,*p,t;
clrscr();
for(i=0;i<10;i++)
{
printf("Enter Value=");
scanf("%d",&a[i]);
}
p=a;
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(*(p+i)>*(p+j))
{
t=*(p+i);
*(p+i)=*(p+j);
*(p+j)=t;
}
}
}
printf("\n\n sorted list=\n");
for(i=0;i<10;i++)
{
printf("%d\n",a[i]);
}
getch();
}

Output
Enter Value=1
Enter Value=2
Enter Value=5
Enter Value=10
Enter Value=25
Enter Value=3
Enter Value=7
Enter Value=8
Enter Value=9
Enter Value=13

sorted list=
1
2
3
5
7
8
9
10
13
25

Program 22
//22. Write a program to swap the two values using pointers and UDF.

#include<stdio.h>
#include<conio.h>
void swap(int *a,int *b);
void main()
{
int x,y;
clrscr();
printf("Enter value of x:");
scanf("%d",&x);
printf("Enter value of y:");
scanf("%d",&y);
swap(&x,&y);
printf("New x=%d\n",x);
printf("New y=%d\n",y);
}
void swap(int *a,int *b)
{
int t;
t=*a;
*a=*b;
*b=t;
}
Output
Enter value of x: 10
Enter value of y: 5
New x=5
New y=10

Program 23
//23. Write a program with structure and pointer.

#include<stdio.h>
#include<conio.h>
struct student
{
int no;
char name[20];
int per;
};
void main()
{
struct student st[3],*p;
clrscr();
for(p=st;p<st+3;p++)
{
printf("Enter Roll no, Name and Per\n");
scanf("%d%s%d",&p->no,p->name,&p->per);
}
printf("\n\n\n");
printf("Rollno    Name   Per\n");
for(p=st;p<st+3;p++)
{
printf("%d\t %s\t %d\n",p->no,p->name,p->per);
}
}
Output
Enter Roll no, Name and Per
1
Nikulsinh
70
Enter Roll no, Name and Per
2
Gavarav
80
Enter Roll no, Name and Per
3
Dhrupal
64

Rollno                   Name                    Per
1                              Nikulsinh             70
2                              Gavarav               80
3                              Dhrupal                                64

Program 24
//Error in this program
//24. Write a program using pointer to determine the length of a character string.

#include<stdio.h>
#include<conio.h>
void main()
{
char *s;
int i=0;
clrscr();
printf("Enter String=");
scanf("%s",s);
while(*(s+i)!="\0")
{
i++;
}
printf("length of string=%d",i);
}

Program 25
//25. Write a program using pointers to read an array of integers and print its elements in reverse order.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,*p;
clrscr();
for(i=0;i<5;i++)
{
printf("Enter Value=");
scanf("%d",&a[i]);
}
p=a;
printf("Reverse order\n");
for(i=4;i>=0;i--)
{
printf("%d\n",*(p+i));
}
}
Output
Enter Value=5
Enter Value=7
Enter Value=10
Enter Value=3
Enter Value=2
Reverse order
2
3
10
7
5

Program 26
// 26. Write a program using UDF and pointers to add two matrices and to return the resultant
matrix to the calling function.

Program 27
// 27. Create one text file store some information into it and print the same information on
Terminal.

#include<stdio.h>
#include<conio.h>
void main()
{
char s[100],t;
int i;
FILE *fp;
clrscr();
fp=fopen("my.txt","w");
printf("Enter your string=");
gets(s);
for(i=0;s[i]!='\0';i++)
{
putc(s[i],fp);
}
fclose(fp);
fp=fopen("my.txt","r");
while((t=getc(fp))!=EOF)
{
printf("%c",t);
}
fclose(fp);
getch();
}
Output
Enter your string=My Site newesteducation
My Site newesteducation
Note: Show text output in TC-> BIN-> my.txt file

Program 28
// 28. A file named data contains series of integer no. Write a c program to read that no. and then
Write all odd no into file named odd no. and write all even no into file named even no.
Display all the contents of these file on screen.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,num;
FILE *f1,*f2,*f3;
clrscr();
f1=fopen("data.txt","w");
for(i=0;i<10;i++)
{
printf("Enter Value=");
scanf("%d",&num);
if(num==-1)
break;
putw(num,f1);
}
fclose(f1);
f1=fopen("data.txt","r");
f2=fopen("odd.txt","w");
f3=fopen("even.txt","w");
while((num=getw(f1))!=EOF)
{
if(num%2==0)
{
putw(num,f3);
}
else
{
putw(num,f2);
}
}
fcloseall();
f2=fopen("odd.txt","r");
f3=fopen("even.txt","r");
printf("odd file data\n");
while((num=getw(f2))!=EOF)
{
printf("%d\n",num);
}
printf("Even file data\n");
while((num=getw(f3))!=EOF)
{
printf("%d\n",num);
}
fclose(f2);
fclose(f3);
getch();
}
Output
Enter Value=1
Enter Value=2
Enter Value=3
Enter Value=4
Enter Value=5
Enter Value=6
Enter Value=7
Enter Value=8
Enter Value=9
Enter Value=10
odd file data
1
3
5
7
9
Even file data
2
4
6
8
10
Note: Show text output in TC-> BIN-> odd.txt and even.txt files


Program 29
// 29. Write a c program to read data from keyboard, write it to a file called input and Display data
of input file on the screen.

#include<stdio.h>
#include<conio.h>
void main()
{
char s[100],t;
int i;
FILE *fp;
clrscr();
fp=fopen("input.txt","w");
printf("Enter your string=");
gets(s);
for(i=0;s[i]!='\0';i++)
{
putc(s[i],fp);
}
fclose(fp);
fp=fopen("input.txt","r");
while((t=getc(fp))!=EOF)
{
printf("%c",t);
}
fclose(fp);
getch();
}
Output
Enter your string=My Site Newesteducation
My Site Newesteducation
Note: Show text output in TC-> BIN-> input.txt file

Program 30
// 30. Write a program that counts the number of characters and number of lines in a file.

#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char t;
int c=0,l=0;
clrscr();
fp=fopen("my.txt","r");
while((t=getc(fp))!=EOF)
{
if(t!=' '&&t!='\n')
{
c++;
}
if(t=='\n')
{
l++;
}
}
fclose(fp);
printf("No of Character is %d\n",c);
printf("No of Line is %d\n",l);
getch();
}

Program 31
// 31. Write a c program to read mark data which contains roll no, name, sub1, sub2, sub3 file and
Generate the annual examination results are tabulated as follows:
Result
-------------------------------------------------------------------
Roll no Name Sub1 Sub2 Sub3 Total per% Class
--------------------------------------------------------------------

#include<stdio.h>
#include<conio.h>
void main()
{
int i,rno[5],s1[5],s2[5],s3[5];
int frno[5],fs1[5],fs2[5],fs3[5],ft[5];
float fper[5];
char name[5][20];
char fname[5][20],fclass[5][15];
FILE *fp;
fp=fopen("student.txt","w");
clrscr();
for(i=0;i<5;i++)
{
printf("Enter Rollno Name S1 S2 S3");
scanf("%d%S%d%d%d",&rno[i],name[i],&s1[i],&s2[i],s3[i]);
fprintf(fp,"%d\t%s\t%d\t%d\t%d\n",rno[i],name[i],s1[i],s2[i],s3[i]);
}
fclose(fp);
fp=fopen("student.txt","r");
printf("Result\n");
printf("===================================================================\n");
printf("Rno Name S1 S2 S3 Total Per Class\n");
for(i=0;i<5;i++)
{
fscanf(fp,"%d\t%s\t%d\t%d\t%d",&frno[i],fname[i],&fs1[i],&fs2[i],&fs3[i]);
ft[i]=fs1[i]+fs2[i]+fs3[i];
fper[i]=ft[i]/3.0;

if(fper[i]>70)
{
strcpy(fclass[i],"Distinction");
}
else if(fper[i]>=60)
{
strcpy(fclass[i],"First");
}
else if(fper[i]>=50)
{
strcpy(fclass[i],"Second");
}
else if(fper[i]>=35)
{
strcpy(fclass[i],"Pass");
}
else
{
strcpy(fclass[i],"*");
}
printf("%d\t%s\t%d\t%d\t%d\t%d\t%f\t%s\n",frno[i],fname[i],fs1[i],fs2[i],fs3[i],ft[i],fper[i],fclass[i]);
}
printf("====================================================================\n");
fclose(fp);
getch();
}

Program 32
// 32. Write a c program to input employee no, employee name and basic and to
store output into empdata file in following format.
A/c Department
------------------------------------------------------------------------------------------
Emp-No Name Basic DA HRA MA PF GROSS NET-PAY
------------------------------------------------------------------------------------------
1 xyz 5000 2500 500 100 500 8100 7600
2
3
-------------------------------------------------------------------------------------------
DA = 50% of Basic HRA =10% of Basic
MA = 100 PF = 10% of Basic
GROSS = BASIC + DA + HRA + MA NET-PAY = GROSS – PF


Program 33
// 33. Write a c program to read empin data file which contains empno, empname and basic. To
create empout data file as per practical no 23 format.

Program 34
// 34. Write a program using fseek and ftell functions.

Program 35
// 35. Two files DATA1 and DATA2 contain sorted lists of integers. Write a program to produce a
third file DATA which holds a single sorted, merged list of these two lists. Use command
line arguments to specify the file names.

Program 36
// 36. Write a program to work as a dos copy con command using command line argument.

Program 37
// 37. Write a C program to work as a dos type command using command line argument.

Program 38
// 38. Write a C program to work as a dos copy command using command line argument.

Program 39
// 39. Write programs which explain the use of memory allocation functions.

Program 40
// 40. Write a program which explains the use of macro.

Posted By New15:12