Monday, 20 February 2017

How to Write C++ code in Dev C++

There are some steps you must be taken care :
 1)In C we used "stdio.h"  as a common header file but in  C++  we used "iostream" header file .
 2)After writing header file write   using namespace std   .
 3)In C we write printf() and  scanf() but in  C++ we write cout<< and cin>> for output and taking       value respectively.
 THESE ARE THE SOME COMMON STEPS TO TAKE CARE WHILE WRITING THE C++ PROGRAM
 EXAMPLE:
       #include<iostream>
        using namespace std ;
       main()
     {
         cout<<"hello";
         int a,b,c;
         cout<<endl;    //to change the line
         cin>>a;
         cin>>b;
         c=a+b;
         cout<<"sum is :"<<c;
   }


Tuesday, 22 November 2016

USE OF CALLOC

#include<stdio.h>
#include<stdlib.h>
int main()
{
 int num,i,*ptr,sum=0;
 printf("enter number of elements:");
 scanf("%d",&num);
 ptr=(int*)calloc(num,sizeof(int));//only //difference is on the syntax there is comma //in caaloc and                                                                                  //*(star)in malloc
 if(ptr==NULL)
 {
  printf("error !memory not allocated ");
  exit(0);
 }
 printf("enter element of array:");
 for(i=0;i<num;i++)
 {
  scanf("%d",ptr+i);
  sum=sum+(*(ptr+i));
 
 }
 printf("SUM=%d",sum);
 free(ptr);
 return 0;
}