Prog 13. WAP To Add Two Distance Using Functions (Use Feet and Inches)
Prog 13. WAP To Add Two Distance Using Functions (Use Feet and Inches)
Prog 13. WAP to Add two distance Using Functions (Use feet and inches).
#include<stdio.h>
#include<conio.h>
struct book{
int id;
char title[20];
char author[20];
}book[10];
void main()
{
int n,i;
clrscr();
printf("Enter Number of books");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter Book ID\n");
scanf("%d",&book[i].id);
printf("Enter Book Title\n");
scanf("%s",&book[i].title);
printf("Enter Author's Name\n");
scanf("%s",&book[i].author);
}
for(i=0;i<n;i++)
{
printf("Book %d Id %d\n",i+1,&book[i].id);
printf("Book %d Title %s\n",i+1,&book[i].title);
printf("Book %d Author %s\n",i+1,&book[i].author);
}
getch();
}
Output :
Prog 13. WAP to Add two distance Using Functions (Use feet and inches).
#include <stdio.h>
#include<conio.h>
struct distance{
int feet;
int inch;
} d1,d2,sum;
void main()
{
clrscr();
printf("1st distance\n");
printf("Enter feet: ");
scanf("%d",&d1.feet);
printf("Enter inch: ");
scanf("%d",&d1.inch);
printf("2nd distance\n");
printf("Enter feet: ");
scanf("%d",&d2.feet);
printf("Enter inch: ");
scanf("%d",&d2.inch);
sum.feet=d1.feet+d2.feet;
sum.inch=d1.inch+d2.inch;
while(sum.inch>12)
{
++sum.feet;
sum.inch=sum.inch-12;
}
printf("Sum of distances=%d.%d feet",sum.feet,sum.inch);
getch();
}
Output:
Prog 14. WAP To Print And Display Emplyee record using array of
structure.
#include<stdio.h>
#include<conio.h>
struct Employee
{
int Id;
char Name[25];
int Age;
long Salary;
}Emp[10];
void main()
{
int i,n;
clrscr();
printf("Enter Number of Employee\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter details of Employee %d",i+1);
printf("\n\tEnter Employee Id : ");
scanf("%d",&Emp[i].Id);
printf("\n\tEnter Employee Name : ");
scanf("%s",&Emp[i].Name);
printf("\n\tEnter Employee Age : ");
scanf("%d",&Emp[i].Age);
printf("\n\tEnter Employee Salary : ");
scanf("%ld",&Emp[i].Salary);
}
printf("\nDetails of Employees");
for(i=0;i<n;i++)
{
printf("\n%d\t%s\t%d\t%ld",Emp[i].Id,Emp[i].Name,Emp[i].Age,Emp[i].Salary);
}
getch();
}
Prog 15. WAP to enter name , roll no & marks of 3 subject and calculate
total and average.
#include<stdio.h>
#include<conio.h>
struct Student
{
int Roll;
char Name[25];
int Marks[3];
int Total;
float Avg;
};
void main()
{
int i;
struct Student S;
printf("\n\nEnter Student Roll : ");
scanf("%d",&S.Roll);
printf("\n\nEnter Student Name : ");
scanf("%s",&S.Name);
S.Total = 0;
for(i=0;i<3;i++)
{
printf("\n\nEnter Marks %d : ",i+1);
scanf("%d",&S.Marks[i]);
S.Total = S.Total + S.Marks[i];
}
S.Avg = S.Total / 3;
printf("\nRoll : %d",S.Roll);
printf("\nName : %s",S.Name);
printf("\nTotal : %d",S.Total);
printf("\nAverage : %f",S.Avg);
getch();
}
Prog 17. WAP to display ID name and Marks of a student using structure.
#include<stdio.h>
#include<conio.h>
struct Student
{
int Roll;
char Name[25];
int Marks[3];
int Total;
float Avg;
};
void main()
{
int i;
struct Student S;
printf("\n\nEnter Student Roll : ");
scanf("%d",&S.Roll);
printf("\n\nEnter Student Name : ");
scanf("%s",&S.Name);
S.Total = 0;
for(i=0;i<3;i++)
{
printf("\n\nEnter Marks %d : ",i+1);
scanf("%d",&S.Marks[i]);
S.Total = S.Total + S.Marks[i];
}
S.Avg = S.Total / 3;
printf("\nRoll : %d",S.Roll);
printf("\nName : %s",S.Name);
printf("\nTotal : %d",S.Total);
printf("\nAverage : %f",S.Avg);
getch();
}
Prog 18. WAP to Display ID , Name, And Percentage using Structure and
Function.
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
int id;
char name[20];
float percentage;
};
void func(struct student record);
int main()
{
struct student record;
clrscr();
record.id=21;
strcpy(record.name, "Sunil");
record.percentage=75;
func(record);
getch();
return 0;
}
void func(struct student record)
{
printf("ID is : %d\n",record.id);
printf("Name is : %s\n",record.name);
printf("Percentage is : %f\n",record.percentage);
}
Output:
Prog 20. WAP For Finding Prime Number Between Two Interval Using
Functions.
#include<stdio.h>
#include<conio.h>
int prime(int num);
int main()
{
int n1,n2,i,flag;
clrscr();
printf("Enter two numbers(intervals): ");
scanf("%d %d",&n1, &n2);
printf("Prime numbers between %d and %d are: ", n1, n2);
for(i=n1+1;i<n2;++i)
{
flag=prime(i);
if(flag==0)
printf("%d ",i);
}
getch();
return 0;
}
int prime(int num)
{
int j,flag=0;
for(j=2;j<=num/2;++j){
if(num%j==0){
flag=1;
break;
}
}
return flag;
}
Output: