Posts

Use of file headers

  #include <iostream> #include <fstream> using namespace std; int main() { fstream fout; fout.open("test.txt", ios::out); fout<<"Hello Coders"; fout.seekp(6, ios::beg); fout<<"World"; fout.close(); } 

Factorial of a number using common way

  #include <stdio.h> int main () {     int i,fact= 1 ,n;     printf ( "enter the number:" );     scanf ( "%d" ,&n);     for (i= 1 ;i<=n;i++)     {                  fact= fact*i;     }     printf ( "%d=%d" ,n,fact); }

Factorial of a number using recursion

  // factorial of a number #include <stdio.h> #include <math.h> int fact ( int ); int main (){     int num,f;     printf ( "enter the number:" );     scanf ( "%d" ,&num);     f= fact (num);     printf ( "\n Factorial of (%d) is (%d)" ,num,f);      } int fact ( int f) {      if (f== 1 ) return f;     else         return f*(f- 1 ); }

Use of function in mathematics

  // use of function #include <stdio.h> #include <math.h> int main () {     printf ( "%g sqrt of= 9\n" , sqrt ( 9 ));     printf ( "%g =log of 9\n" , log ( 9 ));     printf ( "%g =8.8 after ceil \n" , ceil ( 8.8 ));     printf ( "8 to the power 2= %g\n" , pow ( 8 , 2 )); }

Use of Rand in c program

  // use of rand function #include <stdio.h> #include <stdlib.h> int main () {     int i;     for (i= 0 ;i< 16 ;i++)     {         printf ( "% 10d" , 1 +( rand ()% 6 ));         if (i% 5 == 0 )             printf ( "\n" );     } }

receiving the function from user defined without passing any value

#include <stdio.h> int main (){          int sum();     int a,s;     s = sum ();     printf ( "%d" ,s);     return 0 ; } int sum () {     int x,y,z;     printf ( "\n enter the three values " );     scanf ( "%d %d %d" ,&x,&y,&z);     return (x+y+z);      }     

Area of circle using Inline function

// //   main.cpp //   inline function // //   Created by ANKIT KUMAR on 24/03/21. // #include <iostream> using namespace std ;   float area ( int rad) {     float a;     a = 3.14 * rad * rad;     return a; } int main () { float ac; ac= area ( 15 );     cout <<ac; }