0

Write a c++ program to find sum and average of 2 numbers

20th Jun 2016, 2:48 PM
buncy
buncy - avatar
2 odpowiedzi
+ 1
#include <iostream.h> #includd<conio.h> void main() { int a,b,c,d; cout<<"enter two nos \n"; cin>>a>>b; c=a+b; cout<<"sum ="<<c<<"\n"; d=c/2; cout<<"avg="<<d<<"\n" getch (); }
20th Jun 2016, 6:42 PM
Anol Maria Jacob
Anol Maria Jacob - avatar
0
Hi buncy, this should be straightforward as C++ uses the same operators as known from mathematics. Therefore, I will not give you a program that answers your question. I will give you the also simple mathematics: avg = (a+b)/2 Wrap in a main function declare and define the variables a and b. Select a type for the variable avg, and output avg. Wrapping this code in a main function, types and output you learn in the very first lessons in SoloLearn C++. I hope you are not disappointed that you did not get running code. I'm trying to help you make the first step into C++ which actually includes "getting your hands dirty" and try coding. You can test it directly in SoloLearn C++ as SoloLearn C++ comes with a section "Code Playground" that is available in the menu of SoloLearn C++. Try it, and if you have some questions just return to this thread and I will help you.
20th Jun 2016, 3:13 PM
Stefan
Stefan - avatar