C
C
; = end of sentence
{ } = start and end of function
>> = insertion operator
<< = extraction operator
#include <iostream>
using namespace std;
int main()
{
int a;
c++ 101 1
cin>>a;
int b;
cin>>b;
int sum=a+b;
cout<<"sum=", sum;
}
if else ladder
if(savings>5000) if(savings>5000)
cout<<"laptop \n"; {
else if(savings>10000)
cout<<"nothing \n"; cout<<"macbook \
} else
cout<<"windows \
}
else if(savings>2000)
//code for if,else if, else cout<<"ipod \n";
#include <iostream> else
using namespace std; cout<<"nothing \n";
}
int main()
{
int savings;
cout<<"please enter your
c++ 101 2
cin>>savings;
//code for largest of 3 numb
if(a>b)
{
//code for odd or even
if(a>c)
#include <iostream>
{
using namespace std;
cout<<"largest n
}
int main()
else
{
{
int a;
cout<<"largest n
cout<<"enter a number: "
}
cin>>a;
}
else
if(a%2==0)
{
{
cout<<"number is eve if(b>c)
{
}
cout<<"largest n
else
}
{
cout<<"number is odd else
} {
cout<<"largest n
}
}
}
}
for loop
c++ 101 3
syntax :
for(initialisation; condition; update)
//body
int main()
{
int n;
cout<<"enter n: ";
cin>>n;
int i;
int sum=0;
for(i=1; i<=n; i++)
{
sum = sum + i;
}
cout<<"sum of n numbers is: "<<sum<<endl;
while loop
syntax :
while(condition)
{
//body
c++ 101 4
//code for accepting only positive numbers as input
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
while(n>0)
{
cout<<n<<endl;
cin>>n;
}
}
do while loop
syntax :
do {
//body
} while(condition);
int main()
{
int n;
cin>>n;
do{
cout<<n<<endl;
c++ 101 5
cin>>n;
}while(n>0);
}
c++ 101 6