Structure

C program that compare two given dates. To store a date use a structure that contains three members namely day, month and year. If dates are equal then display a message as EQUAL otherwise UNEQUAL

#include<stdio.h> #include<conio.h> struct date { int day; int month; int year; }; void main() { struct date d1,d2; clrscr(); printf(“Enter first date(dd/mm/yyyy):”); scanf(“%d%d%d”,&d1.day,&d1.month,&d1.year); printf(“nEnter second date(dd/mm/yyyy):”); scanf(“%d%d%d”,&d2.day,&d2.month,&d2.year); if((d1.day==d2.day)&&(d1.month==d2.month)&&(d1.year==d2.year)) printf(“nEQUAL”); else printf(“nUNEQUAL”); getch(); }

C++ program to add, subtract, multiply and divide two complex numbers using structures

#include<iostream.h> #include<conio.h> #include<math.h> struct complex { float rel; float img; }s1,s2; void main() { clrscr(); float a,b; cout<<“Enter real and imaginary part of 1st complex number:”; cin>>s1.rel>>s1.img; cout<<“Enter real and imaginary part of 2nd complex number:”; cin>>s2.rel>>s2.img; //Addition a=(s1.rel)+(s2.rel); b=(s1.img)+(s2.img); cout<<“nAddition: “<<“(“<<a<<“)”<<“+”<<“(“<<b<<“)”<<“i”; //Subtraction a=(s1.rel)-(s2.rel); b=(s1.img)-(s2.img); cout<<“nSubtraction: “<<“(“<<a<<“)”<<“+”<<“(“<<b<<“)”<<“i”; //Multiplication a=((s1.rel)*(s2.rel))-((s1.img)*(s2.img)); b=((s1.rel)*(s2.img))+((s2.rel)*(s1.img)); cout<<“nMultiplication: “<<“(“<<a<<“)”<<“+”<<“(“<<b<<“)”<<“i”; //Division a=(((s1.rel)*(s2.rel))+((s1.img)*(s2.img)))/(pow(s2.rel,2)+pow(s2.img,2)); b=(((s2.rel)*(s1.img))-((s1.rel)*(s2.img)))/(pow(s2.rel,2)+pow(s2.img,2)); …

C++ program to add, subtract, multiply and divide two complex numbers using structures Read More »