#include
#include
struct student
{
char name[30];
float number;
}stud;
void main ()
{
char s1[30];
float f;
clrscr();
printf("\nEnter student name:");
scanf (" %s", stud.name);
printf("\nEnter student number:");
scanf (" %f", &f);
stud.number = f;
printf ("Name = %s \n", stud.name);
printf ("Number = %f \n", stud.number);
getch();
}
---------------------------------------------
25. Structure for a complex number:
#include
#include
struct real
{
int a;
int b;
}r1, r2;
void main()
{
clrscr();
printf("\nEnter real and imaginary part of first real no.:\n");
scanf("%d",&r1.a);
scanf("%d",&r1.b);
printf("\nEnter real and imaginary part of second real no.:\n");
scanf("%d",&r2.a);
scanf("%d",&r2.b);
printf("\nResult: %d+%di * %d+%di = %d+%di",r1.a, r1.b, r2.a, r2.b, r1.a*r2.a-r1.b*r2.b, r1.a*r2.b+r1.b*r2.a );
getch();
}
-------------------------------------------------------------
26. Return a complex number structure:
#include
#include
struct real
{
int a;
int b;
}r1, r2, r3;
void calculate(real a, real b)
{
printf("\nResult: %d+%di * %d+%di = %d+%di", a.a, a.b, b.a, b.b, a.a*b.a-a.b*b.b, r1.a*r2.b+r1.b*r2.a );
}
void main()
{
clrscr();
printf("\nEnter real and imaginary part of first real no.:\n");
scanf("%d",&r1.a);
scanf("%d",&r1.b);
printf("\nEnter real and imaginary part of second real no.:\n");
scanf("%d",&r2.a);
scanf("%d",&r2.b);
calculate(r1, r2);
getch();
}
No comments:
Post a Comment