Documentos de Académico
Documentos de Profesional
Documentos de Cultura
10060
1. w/r a program to accept 10 no. from user and display the largest and smallest no. between them
using UDF.
#include<stdio.h>
#include<conio.h>
int large();
void small(int);
struct num
{
int n[10];
}b;
void main()
{
int i,k=0;
clrscr();
printf("enter ten number");
for(i=0; i<10; i++)
{
scanf("%d",&b.n[i]);
}
k=large ();
small(k);
getch();
}
int large()
{
int i,j,tem=0;
for(i=0; i<10; i++)
{
for(j=0; j<10; j++)
{
if(b.n[j]>=tem)
{
tem=b.n[j];
}
}
}
printf("\nlargest value is = %d\n",tem);
return(tem);
}
void small(int tep)
{
int i,j;
for(i=0; i<10; i++)
{
for(j=0; j<10; j++)
{
if(b.n[j]<=tep)
{
tep=b.n[j];
}
}
1
roll no. 10060
}
printf("\nsmallest value is = %d",tep);
}
Output:
2. w/r a program to create structure employee which include emp id, emp name, emp designation, emp
salary. Accept all employee data and print the detail of employee who is working as manager.
#include<stdio.h>
#include<conio.h>
FILE *fp;
int resize=0;
struct emp
{
int emp_id;
char emp_name[20];
char emp_designation[10];
int emp_salary;
}e[2];
void insert();
void display();
void main()
{
int no;
clrscr();
/*printf("enter \n1 insert employe value\n2 show employe detail");
scanf("%d",&no);
if(no==1)
{
insert();
}
else if(no==2)
{
display();
}
else
{
printf("wrong");
2
roll no. 10060
} */
insert();
display();
getch();
}
void insert()
{
int i=0,k=0;
for(i=0; i<2; i++)
{
printf("\nenter emp_id = ");
scanf("%d",&e[i].emp_id);
printf("\nenter emloye name = ");
scanf("%s", e[i].emp_name);
printf("\nenter employe designation = ");
scanf("%s", e[i].emp_designation);
printf("\nenter employe salary = ");
scanf("%d",&e[i].emp_salary);
}
k++;
getch();
}
void display()
{
int i,g=0;
for(i=0; i<2; i++)
{
if(e[i].emp_designation == "manager")
{
printf("\nemp_id is = %d",e[i].emp_id);
printf("\nemloye name is = %s", e[i].emp_name);
printf("\nemploye designation is = %s", e[i].emp_designation);
printf("\nemploye salary is = %d",e[i].emp_salary);
}
else
{
printf("manager is not find");
}
}
g++;
getch();
}
Output:
3
roll no. 10060
3. write menu driven program that will perform following task (matrix order is 2*2 ) 1. Matrix addition, 2.
Matrix subtraction, 3. Matrix division.
#include<stdio.h>
#include<conio.h>
void main()
int i,j,a[2][2],b[2][2],c[2][2],no;
clrscr();
scanf("%d",&a[i][j]);
scanf("%d",&b[i][j]);
printf("\naddition is \n");
c[i][j]=0;
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);
printf("\n");
printf("\nsubtraction is \n");
c[i][j]=0;
c[i][j]=a[i][j]-b[i][j];
printf("%d\t",c[i][j]);
5
roll no. 10060
printf("\n");
printf("\ndivision is \n");
c[i][j]=0;
c[i][j]=a[i][j]/b[i][j];
printf("%d\t",c[i][j]);
printf("\n");
getch();
Output:
6
roll no. 10060
4. w/r a command line program to copy a file.
#include<stdio.h>
#include<conio.h>
FILE *fs,*ft;
int i;
char ch;
clrscr();
if(argc != 3)
printf("inproper argument");
exit(1);
fs=fopen(argv[1],"r");
if(fs==NULL)
exit(1);
ft=fopen(argv[2],"w");
if(ft==NULL)
exit(1);
while(1)
7
roll no. 10060
{
ch=fgetc(fs);
if(ch==EOF)
break;
else
fputc(ch,ft);
fclose(fs);
fclose(ft);
getch();
return(0);
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,no=0,pas=0,*p,v;
char str[20],name[10],surn[10];
clrscr();
printf("enter your surname ");
scanf("%s", surn);
printf("enter your name ");
scanf("%s", name);
printf("enter no.");
scanf("%d",&pas);
p=&pas;
strcat(surn,name);
strcpy(str,surn);
8
roll no. 10060
no=strlen(surn);
printf("\n");
if(strcmp(surn,str)==0)
{
printf("\n your no is = %d",*p);
printf("\n your name is = ");
for(i=0; i<=no; i++)
{
printf("%c", surn[i]);
}
}
getch();
}
output:
#include<stdio.h>
#include<conio.h>
#include<string.h>
union Data
{
int i;
float f;
char str[20];
}d;
void main()
{
clrscr();
d.i=20;
printf("\nthe value of i is %d ",d.i);
d.f=220.5;
printf("\nthe value of f is %f ",d.f);
strcpy(d.str,"c programming");
printf("\nthe value of str is %s ",d.str);
9
roll no. 10060
7. w/r a c program to open two text file and campare both file whether they are same or note.
#include<stdio.h>
#include<conio.h>
void main()
FILE *fp,*ft;
int i,co=0;
char ch,cj;
clrscr();
fp=fopen("emp1.txt","r");
ft=fopen("emp2.txt","r");
while(1)
ch=fgetc(fp);
cj=fgetc(ft);
break;
if(ch==cj)
10
roll no. 10060
}
else
co++;
if(co == 0)
printf("file is same");
else
getch();
Output:
8. w/r a menu driven program using UDF. 1 count occurrence of character, 2 replace a character, 3
reverce a char of array, 4 exite.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void occurance();
void replace();
void reverse();
11
roll no. 10060
char str[20];
int n,num=0;
void main()
clrscr();
printf("enter string");
scanf("%s",str);
n=strlen(str);
occurance();
replace();
reverse();
getch();
void occurance()
int i,co=0;
char ch[1];
scanf("%s",&ch[0]);
printf("%c",str[i]);
if(str[i] == ch[0])
co++;
12
roll no. 10060
printf("\ncharcter %c occurances is = %d\n",ch[0],co);
void replace()
int i;
char ca[1],cb[1];
scanf("%s",&ca);
scanf("%s",&cb);
if(str[i]==ca[0])
str[i]=cb[0];
puts(str);
void reverse()
strrev(str);
puts(str);
Output:
13
roll no. 10060
9. w/r a c program to store item information into a file, inventory which contains the information about
item_no, item_name, qty and price. Read the information from file and display information tabular
form. Use structure or union.
#include<stdio.h>
#include<conio.h>
struct product
int no;
char name[10];
int qty;
float price;
}p;
void write();
void read();
FILE *fp;
void main()
int i;
clrscr();
write();
14
roll no. 10060
read();
getch();
void write()
fp=fopen("p1.txt","w");
scanf("%d",&p.no);
scanf("%s",&p.name);
scanf("%d",&p.qty);
scanf("%f",&p.price);
fwrite(&p,sizeof(p),1,fp);
fclose(fp);
void read()
fp=fopen("p1.txt","r");
fclose(fp);
Output:
15
roll no. 10060
10.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,j,cn=0;
char str[10],tem;
clrscr();
printf("enter string\n");
scanf("%s", str);
cn=strlen(str);
for(i=0; i<=(cn-1); i++)
{
for(j=0; j<=(cn-1); j++)
{
if(str[j]<=str[j-1])
{
tem=str[j];
str[j]=str[j-1];
str[j-1]=tem;
}
tem=0;
}
}
printf("\n%s",str);
getch();
}
OUTPUT:
16