Oct 5, 2019

Basic C++ Programs

C++ basic, fundamental C++ program
basic C++ programs
     
        Also See The Related Pages
      C++ programming Examples.  click it
      Variable Deceleration in C++ . click it
                Data Type in C++. click it









BASIC C++ PROGRAMS:
  The fundamental and basic programs and their result s are:
The given task is called problem and the solution will be solution program.

1.       Write a program that prints or display at output screen a statement such as ‘I love my country’.

Start from including header files which will be stdio.h.
Let’s start,
Note that in c we use small case letters for predefined/built-in function.

#include< stdio.h>
#include<conio.h>
void main (void)
{
printf (“i love my country”);
getch ();
}

Output will be on screen,
I love my country

In above program we use two headers stdio.h and conio.h where stdio means standard input/outputs, like scanf for get values and printf to print or display something may be statements or values at output screen. And conio console input/output, like getch used to get any character from keyboard which may be number, symbol, characters means any key from keyboard. We used getch () in this program to see our result otherwise program will show the results but in nanosecond and getch () will stop the screen/result until we press any key.

2.       Write a c program that take two integer values and display the sum of number.

#include<stdio.h>
#include<conio.h>
void main (void)
{
int num1, num2, sum;
printf (“enter num 1=”);
scanf (“%d”, &num1);
printf (“enter num 2=”);
scanf (“%d”, &num2);
sum = num1 + num2;
printf (“sum of given number =%d”, sum);
getch ();
}

Output will be on screen
Enter num1 = 4
Enter num2 = 5
Sum of given number = 9
In output the 4 and 5 gave at run time.
Above program int num1, num2 is used to define two integer variables.  printf is used to display the sentence enclosed in double quotation and scanf used to take input, %d is format specifier that explained what type of data type should input or output in printf also used %d which is also used to output what type of data type will outputs. &, it is address operator which indicate the input variable will store at the location after it mention such as here &num1 means the input will store at num1 location addressed.

3.       Write a program that take two integer values and display the product.

 #include< stdio.h>
#include<conio.h>
void main (void)
{
int num1, num2, prod;
printf (“enter num 1=”);
scanf (“%d”, &num1);
printf (“enter num 2=”);
scanf (“%d”, &num2);
prod = num1 * num2;
printf (“product of given number =%d”, prod);
getch ();
}

Output will be on screen
Enter num1 = 4
Enter num2 = 5
Product of given number =20
In output the 4 and 5  gave at run time.

4.       Write a program that take two integer values and display the quotients.

#include< stdio.h>
#include<conio.h>
void main (void)
{
int num1, num2, qout;
printf (“enter num 1=”);
scanf (“%d”, &num1);
printf (“enter num 2=”);
scanf (“%d”, &num2);
qout = num1/ num2;
printf (“Quotients  of given number =%d”, qout);
getch ();
}

Output will be on screen
Enter num1 = 20
Enter num2 = 5
Quotients of given number =4
In output the 20 and 5 gave at run time.
/ is used to divide and find quotients.

5.       Write a program that take two integer values and display the modules.

#include< stdio.h>
#include<conio.h>
void main (void)
{
int num1, num2, mod;
printf (“enter num 1=”);
scanf (“%d”, &num1);
printf (“enter num 2=”);
scanf (“%d”, &num2);
mod = num1% num2;
printf (“modules of given number =%d”, mod);
getch ();
}

Output will be on screen
Enter num1 = 18
Enter num2 = 4
Modules of given number =2
In output the 20 and 5  gave at run time.

% is used to find modules where %d is format specifier.


                                                                                                                                 Goto Computer label

0 comments:

Post a Comment

Please do not enter any spam link in the comment box