C Programs - Unix
C Programs - Unix
#include<stdio.h>
void sum(void);
main()
{
sum();
}
void sum(void)
{
int num1, num2, num3;
printf("Enter two numbers: \n");
scanf("%d%d", &num1, &num2);
num3=num1+num2;
printf("Summation of %d and %d is %d \n", num1, num2, num3);
}
OUTPUT
Enter two numbers:
10
20
Summation of 10 and 20 is 30
OUTPUT
Enter two numbers
15
25
Largest Element = 25
OUTPUT
Value of P = 5
Address of P =134518200
OUTPUT
Hai
iaH
end = mid;
else
if(x[mid]<s)
start = mid+1;
else
flag=1;
}
return(flag);
}
OUTPUT
How many numbers? 10
Enter all the numbers in the list
8
15
23
25
36
45
50
62
65
78
Enter the number to be searched: 36
The number 36 is present in the list
Enter the number to be searched: 42
The number 42 is not present in the list
OUTPUT
Enter the values of n and r: 5 3
Value of ncr = 10
Enter the values of n and r: 10 5
Value of ncr = 252
return(s);
}
OUTPUT
---------------------------------------------------------------------x in degrees cos(x)
---------------------------------------------------------------------0 1.0
30 0.87
60 0.50
90 0.00
120 -0.50
150 -0.87
180 -1.00
for(j=0;j<l;j++)
{
*(*(c+i)+j)=0;
for(k=0;k<n;k++)
*(*(c+i)+j) = *(*(c+i)+j) + *(*(a+i)+k) * * (*(b+k)+j);
}
printf("\n Resultant matrix is\n");
for(i=0;i<m;i++)
{
for(j=0;j<l;j++)
printf("%6d", *(*(c+i)+j));
printf("\n");
}
return 0;
}
OUTPUT
For A matrix
How many rows and columns ? 3 3
Enter A matrix values
321
-2 0 4
3 2 -1
For B matrix
How many rows and columns? 3 3
Enter B matrix values
6 4 -1
212
4 -5 4
Resultant Matrix is
26 9 5
4 -28 18
18 19 -3
#include<stdio.h>
#include<ctype.h>
struct emp
{
int eno;
char ename[20];
float bpay;
};
FILE *efile;
int main()
{
struct emp erec;
efile = fopen("EMPLOY.DAT", "a");
printf("\nEnter the Employee number");
scanf("%d",&erec.eno);
printf("Employee Name");
scanf("%s",erec.ename);
printf("Basicpay");
scanf("%f",&erec.bpay);
fwrite(&erec,sizeof(erec),1,efile);
fclose(efile);
printf(" After Appending the content of file");
efile=fopen("EMPLOY.DAT","r");
printf("\n--------------------------------------------------");
printf("\n Emp.no Employee name Basic Pay");
printf("\n --------------------------------------------------");
fread(&erec,sizeof(erec),1,efile);
while (!feof(efile))
{
printf("\n %d \t %-20s %0.2f",erec.eno,erec.ename,erec.bpay);
fread(&erec, sizeof(erec),1,efile);
}
printf("\n --------------------------------------------------\n");
fclose(efile);
return 0;
}
OUTPUT
Enter the Employee number: 103
Employee name: zzzz
Basic Pay: 12000
After Appending the content of file
----------------------------------------------------------Emp.no Employee name Basic Pay
---------------------------------------------------------101 xxxx 65433.4
102 yyyy 7000.0
103 zzzz 12000.0