Amatuer C++ Programs

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Amatuer C++ Programs as PDF for free.

More details

  • Words: 359
  • Pages: 5
C++ programes:--1>program for greater than,smaller than #include #include #include<math.h> main() { int a,b,c; clrscr(); cout<<"enter a,b,c"; cin>>a>>b>>c; if(a>b) if(a>c) cout<<"a is greater"; else cout<<"c is greater"; else if(b>c) cout<<"b is greater"; else cout<<"c is greater"; getch(); return 0; } 2>program for power(a,b) #include #include #include<math.h> main() { int a,b,c; clrscr(); cout<<"enter a,b"; cin>>a>>b; c=pow(a,b); cout<program to find area of rectangle and square #include<stdio.h> #include void main() { int B,a,b; float A clrscr(); printf("\nA"); printf("\nB"); //printf("\nCASE C"); scanf("%d%d%d",&A,&B);

if( A) { printf("\ncompute area of rectangle"); printf("\nenter value of a,b"); scanf("%d%d",&a,&b); A=1/2(a*b); printf("%f",A); } else { printf("\ncompute area of squqre"); printf("\nenter value of a,b); scanf("%d",&a); B=a*a; printf("%d",B); } getch(); } 4>progarm for equivalence of no. #include<stdio.h> #include void main() { int x,y; clrscr(); scanf("%d",&x); if(x>5) y=3; else y=4; printf("%d",y); getch(); } 5>program for insurance #include<stdio.h> #include void main() { char sex,ms; int age; clrscr(); printf("enter age,sex,martial ststus"); scanf("%d%c%c%c",&age,&sex,&ms); if(ms=='M') printf("driver is insured");

else { if(sex=='M') { if(age>30) printf("driver is insured"); else printf("driver is not insured"); } else { if(age>25) printf("driver is insured"); else printf("driver is not insured");

}

} } getch();

6>program for calculating profit and loss #include<stdio.h> #include void main() { float cost,sell,prof,loss,just_sold; clrscr(); printf("\nenter selling price"); scanf("%f",&sell); printf("\nenter cost price"); scanf("%f",&cost); prof=sell-cost; if(prof>0) printf("\nprofit=%f",prof); else { if(prof==0) printf("\nno gain no loss=%f",just_sold); else printf("\nloss=%f",loss); } getch(); } 7>program for finding quadratict equations(roots): #include<stdio.h> #include #include<math.h>

void main() { float a,b,c,discriminant,root1,root2; clrscr(); printf("i/ values of a,bandc"); scanf("%f,%f,%f",&a,&b,&c); discriminant=b*b-4*a*c; if(discriminant<0) printf("\nroots are imaginary"); else { root1=(-b+sqrt(discriminant)/(2.0*a)); root2=(-b-sqrt(discriminant)/(2.0*a)); printf("\nroot1=%f\nroot2=%f",root1,root2); } getch(); 8>program for swapping the no.s #include #include main() { int c,d; cout<<"enter c,d"; cin>>c>>d; d=d+c; c=d-c; d=d-c; cout<<"c="<program for simple interest #include #include void main() { int p,n; float r,si; clrscr(); p=1000; n=3; r=8.5; si=p*n*r/100; cout<<"si="<<si; getch(); 10>program for addition,multiplication,division and subtraction.

#include #include main() { int a,b; float ans; clrscr(); cout<<"enter a,b"; cin>>a>>b; ans=a+b; cout<<"nadd="<program for finding exponent #include<stdio.h> #include #define ACCURACY 0.0001 void main() { int n,count; float x,term,sum; clrscr(); printf("enter value of x"); scanf("%f",&x); n=term=sum=count=1; while(n<=100) { term=term*x/n; sum=sum+term; count=count+1; if(term

Related Documents

C Programs
April 2020 23
C++ Programs
November 2019 25
C++ Programs
June 2020 21
C Programs
November 2019 40