Custom Search

Friday 2 December 2011

Difference between c and c++, Where C and C++ Differ, 10 Major Differences Between C And C++, C & C++ in Details

Difference between c and c++, Where C and C++ Differ, 10 Major Differences Between C And C++, C & C++ in Details

1.C does not support new or delete commands. The memory operations to free or allocate memory in c are carried out by malloc() and free().


2. C follows the procedural programming paradigm while C++ is a multi-paradigm language(procedural as well as object oriented)

In case of C, importance is given to the steps or procedure of the program while C++ focuses on the data rather than the process.
Also, it is easier to implement/edit the code in case of C++ for the same reason.

3. In case of C, the data is not secured while the data is secured(hidden) in C++

This difference is due to specific OOP features like Data Hiding which are not present in C.

4. C is a low-level language while C++ is a middle-level language

C is regarded as a low-level language(difficult interpretation & less user friendly) while C++ has features of both low-level(concentration on whats going on in the machine hardware) & high-level languages(concentration on the program itself) & hence is regarded as a middle-level language.

5. C uses the top-down approach while C++ uses the bottom-up approach

6. Although most good C code will follow this convention, in C++ it is strictly enforced that all functions must be declared before they are used. This code is valid C, but it is not valid C++:
#include <stdio.h>
int main()
{
    foo();
    return 0;
}

int foo()
{
    printf( "Hello world" );
}

In case of C, the program is formulated step by step, each step is processed into detail while in C++, the base elements are first formulated which then are linked together to give rise to larger systems.

7. C is function-driven while C++ is object-driven

Functions are the building blocks of a C program while objects are building blocks of a C++ program.

8. C++ supports function overloading while C does not

Overloading means two functions having the same name in the same program. This can be done only in C++ with the help of Polymorphism(an OOP feature)

9. We can use functions inside structures in C++ but not in C.

In case of C++, functions can be used inside a structure while structures cannot contain functions in C.

10. The NAMESPACE feature in C++ is absent in case of C

C++ uses NAMESPACE which avoid name collisions.
For instance, two students enrolled in the same university cannot have the same roll number while two students in different universities might have the same roll number. The universities are two different namespace & hence contain the same roll number(identifier) but the same university(one namespace) cannot have two students with the same roll number(identifier)

11. The standard input & output functions differ in the two languages

C uses scanf & printf while C++ uses cin>> & cout<< as their respective input & output functions

12. C++ allows the use of reference variables while C does not

13. In c declaring the global variable several times is allowed but this is not allowed in c++.

14. main Doesn't Provide return 0 Automatically

In C++, you are free to leave off the statement 'return 0;' at the end of main; it will be provided automatically:
int main()
{
    printf( "Hello, World" );
}
but in C, you must manually add it:
int main()
{
    printf( "Hello, World" );
    return 0;
}

Wednesday 30 November 2011

Write a trigger that check the student_id must be start with ‘M’. PL/SQL trigger that check the student_id must be start with ‘M’


Write a trigger that check the student_id must be start with ‘M’. PL/SQL trigger that check the student_id must be start with ‘M’

create table student_id(sno varchar2(10));

insert into student_id values(‘&sno’)

SQL> select * from student_id;


SNO

---------

1

2

3

4

set serveroutput on

create or replace trigger tri30 before insert on student_id for each row

declare

tsno student_id.sno%type;

begin

tsno:=:new.sno;

dbms_output.put_line(tsno);

if tsno not like 'M%' then

raise_application_error(-20005,'Invalid Number');

end if;

end;

Write a trigger that check the mark is not zero or negative, PL/SQL trigger that check the mark is not zero or negative


Write a trigger that check the mark is not zero or negative, PL/SQL trigger that check the mark is not zero or negative


create table astd(mark number(3));


insert into astd values(&mark);

SQL> select * from astd;


MARK

---------

23

0

800

0

0


set serveroutput on

create or replace trigger tri29 before insert on astd for each row

declare

tmark astd.mark%type;

begin

tmark:=:new.mark;

if tmark>700 or tmark<0 then

raise_application_error(-20003,'Invalid Mark');

end if;

end;

Write a Trigger to ckeck the Pincode is exactly six degit or not., Write a PL/SQL Trigger to ckeck the Pincode is exactly six degit or not


Write a Trigger to ckeck the Pincode is exactly six degit or not.,  Write a PL/SQL Trigger to ckeck the Pincode is exactly six degit or not

create table citypin(

pin number(10));


insert into citypin values(&pin);


SQL> select * from citypin;


PIN

---------

2434355

3435465

122

123235467


set serveroutput on

create or replace trigger tri28 before insert on citypin for each row

declare

tpin citypin.pin%type;

begin

tpin:=:new.pin;

if length(to_char(tpin))!=6 then

raise_application_error(-20002,'Your Pincode is Invalid');

end if;

end;

Write a PL/SQL function to find the sum of digits of accepted nos.


Write a PL/SQL function to find the sum of digits of accepted nos.

set serveroutput on

create or replace function sm(no in number)return number as

i number(4);

sm number(4);

rem number(4);

num number(4);

begin

num:=no;

sm:=0;

i:=0;

while i<=num+1

loop

rem:=mod(num,10);

dbms_output.put_line(rem);

sm:=sm+rem;

num:=num/10;

i:=i+1;

end loop;

return sm;

end;
------------

set serveroutput on

declare

nos number(10);

ans number(3);

begin

nos:=&nos;

ans:=sm(nos);

dbms_output.put_line('Sum of Digit is '||ans);

end;

Write a function in PL/SQL to check whether the given number is prime or not.


Write a function in PL/SQL to check whether the given number is prime or not.

set serveroutput on

create or replace function prime(n in number) return varchar2 is

i number(10);

pr number(10);

res varchar2(10);

begin

pr:=1;

for i in 2..n/2 loop

if mod(n,i)=0 then

pr:=0;

end if;

end loop;


if pr=1 then

res:='prime';

else

res:='Not Prime';

end if;

return res;

end;

To run:= select prime(5) from dual;

Write a PL/SQL block to raise the salary by 20% of given employee on following table.., PL/SQL Program to raise the salary by 20% of given employee on following table


Write a PL/SQL block to raise the salary by 20% of given employee on following table.., PL/SQL Program to raise the salary by 20% of given employee on following table

Emp_Salary (eno, ename, city, salary)

Table Creation…

eno number primary key,

ename char(15),

city char(15),

sal number(10,2));

insert into empsal values(1,'Hiral','Mehsana',20000);

insert into empsal values(2,'Pinkey','Mehsana',15000);

insert into empsal values(3,'Dhruvi','Mehsana',10000);


Program…

declare

n number;

s number(10,2);

begin

n:=&n;

--select sal into s from empsal where eno=n;

update empsal set sal=sal+(sal*0.20) where eno=n;

end;

Write a PL/SQL block to display the Information of given student on following table Stud (sno, sname, address, city)., PL/SQL Program to display the Information of given student on following table Stud (sno, sname, address, city)


Write a PL/SQL block to display the Information of given student on following table Stud (sno, sname, address, city)., PL/SQL Program to display the Information of given student on following table Stud (sno, sname, address, city)


Table Creation…
create table stud(

sno number primary key,

sname char(15),

addr varchar(30),

city char(15));

insert into stud values(1,'hiral','2,krishna society','Mehsana.');

insert into stud values(2,'pinky','4,Kalyaneshwer society','Mehsana.');

insert into stud values(3,'Dhruvi','24,Pushpavati society','Mehsana');


Program…


declare

no number;

n number;

name char(15);

add varchar(50);

c char(15);

begin

n:=&n;

select sno,sname,addr,city into no,name,add,c from stud where sno=n;

dbms_output.put_line('The Sno is ' || no);

dbms_output.put_line('The Sname is ' || name);

dbms_output.put_line('The address is ' || add);

dbms_output.put_line('The city is ' || c);

end;

Write a PL/SQL block to find the sum of first 100 odd nos. and even nos). PL/SQL Program to find the sum of first 100 odd nos. and even nos


Write a PL/SQL block to find the sum of first 100 odd nos. and even nos). PL/SQL Program to find the sum of first 100 odd nos. and even nos

declare

odd number:=0;

even number:=0;

i number;

begin

for i in 1..100

loop

if(i mod 2 = 0) then

even:=even+i;

else

odd:=odd+i;

end if;

end loop;

dbms_output.put_line('The Sum of 100 even nos is ' || even);

dbms_output.put_line('The Sum of 100 odd nos is ' || odd);

end;

Write a PL/SQL block to find the maximum number from given three numbers, PL/SQL Program to find the maximum number from given three numbers


Write a PL/SQL block to find the maximum number from given three numbers, PL/SQL Program to find the maximum number from given three numbers

declare

a number;

b number;

c number;

begin

a:=&a;

b:=&b;

c:=&c;


if (a>b and a>c) then

dbms_output.put_line('a is maximum ' || a);

elsif (b>a and b>c) then

dbms_output.put_line('b is maximum ' || b);

else

dbms_output.put_line('c is maximum ' || c);

end if;

end;

Monday 21 November 2011

C /C++ Program to enter elements of integer array & display the sum, C or C++ Program to display numbers with the help of array.


C /C++ Program to enter elements of integer array & display the sum, C or C++ Program to display numbers with the help of array.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i,a[5],sum=0;
clrscr();
printf("Enter the 5 numbers:\n");
for(i=0;i<5;i++)
 {
  scanf("%d", &a[i]);
  sum=sum+a[i];
 }
  printf("\n");
for(i=0;i<5;i++)
 {
  printf("a[%d]=%d\n",i+1,a[i]);
 }
 printf("\nsum=%d\n",sum);
 getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

C/ C++ Program to print Quadratic Equation by entering numbers from users, Procedure to print Quadratic Equation with Output


C/ C++ Program to print Quadratic Equation by entering numbers from users, Procedure to print Quadratic Equation with Output

Program:-
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,r1,r2;
clrscr();
printf("Enter the values of a,b,c:\n");
scanf("%f %f %f", &a, &b, &c);
d= b*b - 4*a*c;
printf("discriminant is:%f", d);
if(d<0)
{
printf("\nRoots are Imaginary");
}
else
{
r1= (-b+ sqrt(d))/(2*a);
r2=( -b- sqrt(d))/(2*a);
printf("\n%f %f",r1,r2);
}
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the result

C/C++ Program to print star pattern, Program to print star pattern in pyramid form, Program to print star pattern in decreasing form.


C/C++ Program to print star pattern, Program to print star pattern in pyramid form, Program to print star pattern in decreasing form.

Program:-

#include<stdio.h>
#include<conio.h>
void main()
{ int i,j;
clrscr();
for(i=1;i<6;i++)
{ printf("\n");
for(j=1;j<=i;j++)
{ printf("*");
}}
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

C/C++ Program that will scan a character string passed as an argument & convert all lowercase characters into uppercase characters.


C/C++ Program that will scan a character string passed as an argument & convert all lowercase characters into uppercase characters. 


Program

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void convupper (char s[10]);
void main()
{
char str[10];
clrscr();
printf("Enter the string:");
scanf("%s",str);
convupper(str);
getch();
}
 void convupper(char s[10])
 {
 int i;
 for(i=0;i<10;i++)
 if(islower (s[i]))
 {
 s[i]=toupper(s[i]);
 }
 printf("%s",s);
 getch();
 }


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.

C/C++ Program to write a function that will interchange the value of two variable, Program to interchange values of 2 variables


C/C++ Program to write a function that will interchange the value of two variable, Program to interchange values of  2 variables

Program
#include<stdio.h>
#include<conio.h>
void interchange(int, int);
void main()
{
int x,y;
clrscr();
printf("Enter two Numbers:\n");
scanf("%d %d", &x, &y);
printf("\nOriginal value is:%d %d", x,y);
interchange(x,y);
getch();
}
void interchange(int m,int n)
{
int temp;
temp=m;
m=n;
n=temp;
printf("\nThe value after interchange is: %d %d",m,n);
}

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.

Wednesday 9 November 2011

Header File Definition, Various Header File use in C, Use of Header File, Name Description of Various Header Files, Use of , , , C Library Header File, various header files in c language with ites use

Header File Definition, Various Header File use in C, Use of Header File, Name  Description of Various Header Files, Use of <float.h>, <ctype.h>, <stdio.h>, C Library Header File, various header files in c language with ites use

Header File Definition
Header files allow programmers to separate certain elements of a program's source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers. Programmers who wish to declare standardized identifiers in more than one source file can place such identifiers in a single header file, which other code can then include whenever the header contents are required. This is to keep the interface in the header separate from the implementation. The C standard library and C++ standard library traditionally declare their standard functions in header files.

Use of Header Files

Header files are included into a program source file by the ‘#include’ preprocessor directive. The C language supports two forms of this directive; the first,

#include "header"
is typically used to include a header file header that you write yourself; this would contain definitions and declarations describing the interfaces between the different parts of your particular application. By contrast,

 #include <file.h>
is typically used to include a header file file.h that contains definitions and declarations for a standard library. This file would normally be installed in a standard place by your system administrator. You should use this second form for the C library header files.


Name--Description

  • <assert.h>--Contains the assert macro, used to assist with detecting logical errors and other types of bug in debugging versions of a program.
  • <complex.h>--A set of functions for manipulating complex numbers.
  • <ctype.h>--Contains functions used to classify characters by their types or to convert between upper and lower case in a way that is independent of the used character set (typically ASCII or one of its extensions, although implementations utilizing EBCDIC are also known).
  • <errno.h> --For testing error codes reported by library functions.
  • <fenv.h>--For controlling floating-point environment.
  • <float.h>--Contains defined constants specifying the implementation-specific properties of the floating-point library, such as the minimum difference between two different floating-point numbers (_EPSILON), the maximum number of digits of accuracy (_DIG) and the range of numbers which can be represented (_MIN, _MAX).
  • <inttypes.h>--For precise conversion between integer types.
  • <iso646.h>--For programming in ISO 646 variant character sets.
  • <limits.h>--Contains defined constants specifying the implementation-specific properties of the integer types, such as the range of numbers which can be represented (_MIN, _MAX).
  • <locale.h>--For setlocale and related constants. This is used to choose an appropriate locale.
  • <math.h>--For computing common mathematical functions.
  • <setjmp.h>--Declares the macros setjmp and longjmp, which are used for non-local exits.
  • <signal.h> --For controlling various exceptional conditions.
  • <stdarg.h>--For accessing a varying number of arguments passed to functions.
  • <stdbool.h>--For a boolean data type.
  • <stdint.h>--For defining various integer types.
  • <stddef.h>--For defining several useful types and macros.
  • <stdio.h>--Provides the core input and output capabilities of the C language. This file includes the venerable printf function.
  • <stdlib.h>--For performing a variety of operations, including conversion, pseudo-random numbers, memory allocation, process control, environment, signalling, searching, and sorting.
  • <string.h>--For manipulating several kinds of strings.
  • <tgmath.h>--For type-generic mathematical functions.
  • <time.h>--For converting between various time and date formats.
  • <wchar.h>--For manipulating wide streams and several kinds of strings using wide characters - key to supporting a range of languages.
  • <wctype.h>


Saturday 16 April 2011

Program to read two matrices and print addition & subtraction of the matrices through array, Matrices Addition & Subtraction in single program


Program to read two matrices and print addition & subtraction of the matrices through array, Matrices Addition & Subtraction in single program 

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,r1,c1,r2,c2,a[10][10], b[10][10], c[10][10];
clrscr();
printf("Enter the rows & column of 1st matrices:\n");
scanf("%d %d",&r1, &c1 );
printf("\nEnter the rows & column of 2nd matrices:\n");
scanf("%d %d",&r2, &c2);
if((r1==r2)&&(c1==c2))
{
printf("\nMatrices addition is possible\n");
}
else
{
printf("\nMatrices addition is not possible\n");
exit(0);
}
printf("\nEnter the first matrices:\n");
for(i=0;i<r1;i++)
{
 for(j=0;j<c1;j++)
 {
 scanf("%d",&a[i][j]);
 }
}
printf("\nFirst Matrices is:\n");
 for(i=0;i<r1;i++)
{
 printf("\n");
 for(j=0;j<c1;j++)
 {
 printf("%d\t",a[i][j]);
 }
}
printf("\n");
printf("\nEnter second Matrices:\n");
for(i=0;i<r2;i++)
{
 for(j=0;j<c2;j++)
 {
 scanf("%d",&b[i][j]);
 }
}
printf("\nSecond Matrices is:\n");
for(i=0;i<r2;i++)
{
 printf("\n");
 for(j=0;j<c2;j++)
 {
 printf("%d\t",b[i][j]);
 }
}
printf("\n");
printf("\nMatrices addition is:\n");
for(i=0;i<r1;i++)
{
 printf("\n");
 for(j=0;j<r2;j++)
 {
 c[i][j] = a[i][j] + b[i][j];
 printf("%d\t",c[i][j]);
 }
}
printf("\n");
printf("\nMatrices subtraction is:\n");
 for(i=0;i<r1;i++)
 {
 printf("\n");
 for(j=0;j<r2;j++)
 {
 c[i][j] = a[i][j] - b[i][j];
 printf("%d\t", c[i][j]);
 }
}
getch();
}

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.

Click here to check the output

C/ C++ Program to print numbers in increasing order in pyramid form, C program to print 122333444455555.


C/ C++ Program to print numbers in increasing order in pyramid form, C program to print 122333444455555.



Program

#include<stdio.h>
#include<conio.h>
void main()
{ int i,j;
clrscr();
for(i=1;i<6;i++)
{ printf("\n");
for(j=1;j<=i;j++)
{ printf("%d",j);
}}
getch();
}

Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

C/C++ Program to sort the integer array in ascending order, C/C++ Program for Bubble Sorting in Array, Program to enter 10 numbers & arrange them in ascending order.


C/C++ Program to sort the integer array in ascending order,  C/C++ Program for Bubble Sorting in Array, Program to enter 10 numbers & arrange them in ascending order.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10],temp=0;
clrscr();
printf("Enter the 10 Numbers:\n");
for(i=0;i<10;i++)
{
scanf("%d", &a[i]);
}
for(i=0;i<10;i++)
{
 for(j=0;j<9;j++)
 {
 if(a[j] > a[j+1])
 { temp=a[j];
  a[j]=a[j+1];
  a[j+1]=temp;
 } } }
printf("Array in ascending order is:\n");
for(i=0;i<10;i++)
{
 printf("%d ",a[i]);
}
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.

C /C++ Program for Multiplication of Two Matrices, C /C++ Program to enter elements of integer array & display its Multiplication, C or C++ Program to display numbers with the help of array & show its Multiplication.


C /C++ Program for Multiplication of Two Matrices, C /C++ Program to enter elements of integer array & display its Multiplication, C or C++ Program to display numbers with the help of array & show its Multiplication

Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,r1,c1,r2,c2,a[10][10], b[10][10], c[10][10];
clrscr();
printf("Enter the rows & column of 1st matrices:\n");
scanf("%d %d",&r1, &c1 );
printf("\nEnter the rows & column of 2nd matrices:\n");
scanf("%d %d",&r2, &c2);
if(c1==r2)
{
printf("\nMatrices multiplication is possible\n");
}
else
{
printf("\nMatrices multiplication is not possible\n");
exit(0);
}
printf("\nEnter the first matrices\n");
for(i=0;i<r1;i++)
{
 for(j=0;j<c1;j++)
 {
 scanf("%d",&a[i][j]);
 }
}
printf("\nFirst Matrices is:\n");
 for(i=0;i<r1;i++)
{
 printf("\n");
 for(j=0;j<c1;j++)
 {
 printf("%d\t",a[i][j]);
 }
}
printf("\n");
printf("\nEnter second matrices\n");
for(i=0;i<r2;i++)
{
 for(j=0;j<c2;j++)
 {
 scanf("%d",&b[i][j]);
 }
}
printf("\nSecond matrices is:\n");
for(i=0;i<r2;i++)
{
 printf("\n");
 for(j=0;j<c2;j++)
 {
 printf("%d\t",b[i][j]);
 }
}
printf("\n");
printf("\nMatrices multiplication is\n");
for(i=0;i<r1;i++)
{
 printf("\n");
 for(j=0;j<c2;j++)
 {
  c[i][j]=0;
  for(k=0;k<c1;k++)
  {
 c[i][j] = c[i][j]+(a[i][k] * b[k][j]);
  }
 }
}
for(i=0;i<r1;i++)
{
 printf("\n");
 for(j=0;j<c2;j++)
 {
printf("%d\t",c[i][j]);
 }
}
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

C/C++ Program to sort the integer array in descending order, Program to enter 10 numbers & arrange them in descending order.


C/C++ Program to sort the integer array in descending order,  Program to enter 10 numbers & arrange them in descending order.

Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10],temp=0;
clrscr();
printf("Enter the 10 Numbers:\n");
for(i=0;i<10;i++)
{
scanf("%d", &a[i]);
}
for(i=0;i<10;i++)
{
 for(j=0;j<9;j++)
 {
 if(a[j] < a[j+1])
 { temp=a[j];
  a[j]=a[j+1];
  a[j+1]=temp;
 } } }
printf("Array in descending order is:\n");
for(i=0;i<10;i++)
{
 printf("%d ",a[i]);
}
getch();
}


Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h" 
2.)  for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.


Click here to check the output

Laptops