C program to add two numbers using structure

#include<stdio.h> #include<conio.h> struct sum { int a; int b; }; void main() { int sum1; struct sum s; clrscr(); printf(“Enter two numbers:”); scanf(“%d%d”,&s.a,&s.b); sum1=s.a+s.b; printf(“nSum=%d”,sum1); 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 »

C program to concatenate two strings without using strcat() function

#include<stdio.h> #include<conio.h> void main() { char s1[30],s2[30],s3[60]; int i,j; clrscr(); printf(“Enter first string:”); gets(s1); printf(“Enter second string:”); gets(s2); for(i=0;s1[i]!=’’;++i) s3[i]=s1[i]; for(j=0;s2[j]!=’’;++j) s3[i+j]=s2[j]; s3[i+j]=’’; printf(“nThe concatenated string is: %s”,s3); getch(); }

Basic Structure of C Program

Here you will learn about basic structure of C program.   Any C program is consists of 6 main sections. Below you will find brief explanation of each of them. Basic Structure of C Program Documentation Section This section consists of comment lines which include the name of programmer, the author and other details like …

Basic Structure of C Program Read More »