Posts

Showing posts from March, 2021

bubble sort in c

  // bubble sort #include <stdio.h> int main () {     int i, j,c,n,array[ 100 ],swap;     printf ( "enter the elements of for which you want to sort:" );     scanf ( "%d" ,&n);     printf ( "enter the %d \n elements" );     for (i= 0 ;i<n;i++)     {         scanf ( "%d" ,&array[i]);     }         for (i= 0 ;i<(n- 1 );i++)         {             for (j= 0 ;j<(n-i- 1 );j++)             {                 if (array[j]<array[j+ 1 ])                 {                     swap=array[j];                     array[j]=array[j+ 1 ];                     array[j+ 1 ]=swap;                                      }         }     }             printf ( "sorted list in ascending order:" );             for (i= 0 ;i<n;i++)             {                 printf ( "%d\n" ,array[i]);                              }             return 0 ;              }

nested structure in c and using that finding the distance between two place

 // using structure add two distance  #include<stdio.h>  struct distance {     int feet;     float inch;           }; struct moredistance {     int meter;     float centi; } distance1, distance2,sum; int main() {   printf("enter the distance1  in feet:\n");  scanf("%d",&distance1.meter);    printf("enter the distance 2 in inch\n");  scanf("%f",&distance2.centi);  sum.meter=distance1.meter+distance2.centi;      printf("sum of distance1 and distance 2 is %d",sum.meter);   }  

New project

 <!doctype html> <html > <head> <title> </title> </head> <body> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body {    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample {    width: 50%;    background-color: lightblue;    height: 200px;    font-size: 18px; } @media only screen and (max-width: 700px) {    body {       margin: 0;       padding: 0;    }    .sample {       width: 100%;    } } </style> </style> </head> <body> <h2>The news which always give you updates   </h2> <p></p> <body> <img  height="100" width="100" class="img-header" src="https://images.vexels.com/media/users/3/129616/isolated/preview/fb517f8913bd99cd48ef00facb4a67c0-businessman-avatar-silhouette-by-vexels.png"> </body>  <ul>   <li><a href="#home"   oncli

new style

 fun main() {     val border = "%" printBoarder(border) println(" the queen of jhansi") printBoarder(border) } fun printBoarder(border:String) {     repeat(23)     {         print("=")     }     println() }

Printing Queen of Jhansi

 fun main() { printBoarder() println(" the queen of jhansi") printBoarder() } fun printBoarder() {     repeat(23)     {         print("=")     }     println() }

Android Development Basic

  fun main () {         val age = 5 * 365     val name = "Rover"         println ( "Happy Birthday, ${name}!" )         // Let's print a cake!     println ( "   ,,,,,   " )     println ( "   |||||   " )     println ( " =========" )     println ( "@@@@@@@@@@@" )     println ( "{~@~@~@~@~}" )     println ( "@@@@@@@@@@@" )         // This prints an empty line.     println ( "" )     println ( "You are already ${age} days old, ${name}!" )     println ( "${age} days old is the very best age to celebrate!" ) }

write a program to overload the function ++ and -- for the prifix and suffix in c++

 // write a program to overload the function ++ and -- for the prifix and suffix #include<iostream> using namespace std; class number {     float x;     public:     number(float k)     {         x=k;;     }          void operator ++(int)     {         x++;              }     void operator --()     {         --x;     }     void show()     {         cout<<"\n x="<<x;              } }; int main() {     number N(2.3);     cout<<"/n befor the incrimination";     N.show();     cout<<"\n after incrimination :";     N++;     N.show();     cout<<"\n after discrimination";     --N;     N.show();      }

Vowel or Consonant

  //check whether the alphabate is vowel or consonat #include <stdio.h> int main () {     char ch;     printf ( "enter the alphabate which you want to check: " );     scanf ( "%c" ,&ch);     if (ch== 'a' ||ch== 'e' ||ch== 'i' ||ch== 'o' ||ch== 'u' ||ch== 'A' ||ch== 'E' ||ch== 'I' ||ch== 'O' ||ch== 'U' )     {                       printf ( "it is a vowel:" );     }     else         printf ( "it is a consonant" ); }

Check whether the number is prime or not

  // check whether the number is prime or not #include <stdio.h> int main () {     int i,j= 2 ,n;     printf ( "enter the number which you want to take check wheter the number is prime or not\n" );     scanf ( "%d" ,&i);     for (j= 2 ;j<=n;n++);     {         if (n%i== 0 )         {             printf ( "%d is print" ,n);                      }         else             printf ( "the number is not prime" );              }                       }

square of the number

  // square of the given number #include <stdio.h> int main () {     int i,sqN,n;     printf ( "enter the number:" );     scanf ( "%d" ,&n);     sqN=n*n;     printf ( "the square of given number is %d" ,sqN);      }

Average of the number

  // average of the number #include <stdio.h> int main () {     int i,n,x;     float avg,sum= 0 ;     printf ( "enter the value which you want to take for the average:" );     scanf ( "%d" ,&n);         for (i= 1 ;i<=n;i++)     {         printf ( "x=" );         scanf ( "%d" ,&x);         sum +=x;     }              avg=sum/n;         printf ( "%f" ,avg);     }

check whether the number is armstrong number or not

  // add digits of the number using recurssion #include <stdio.h> int main (){     int i,j,k,n,b= 0 ;     printf ( "enter the number which you want to check that wheter the number is armstrong or not:" );     scanf ( "%d" ,&n);     j=n;     while (n> 0 )     {         i=n% 10 ;         b=b+i*i*i;         n=n/ 10 ;     }     if (b==j)     {         printf ( "it is the armstrong number:" );              }     else         printf ( "it is not the armstrong number:" );      }

using recursion find the sum of the digit

  // add digits of the number using recurssion #include <stdio.h> int add_digits ( int ); int main () {     int n,result;     printf ( "enter the number whose sum of digit you wnat:" );     scanf ( "%d" ,&n);     result= add_digits (n);     printf ( "%d" ,result);     return 0 ; } int add_digits ( int n) {     static int sum= 0 ;     if (n== 0 ){         return 0 ;     }     sum=n% 10 + add_digits (n/ 10 );     return (sum);                }

Addition of the every single digit of the number like 434= 4+3+4

  // addition of the elements of number #include <stdio.h> int main () {     int i,j,n,sum= 0 ,remainder;     printf ( "enter the number which you want to print:\n" );     scanf ( "%d" ,&n);     while (n!= 0 )     {         remainder =n% 10 ;         sum=sum+remainder;         n=n/ 10 ;     }     printf ( "%d" ,sum); }

Addition of number using an array

  // add n number using an array #include <stdio.h> int main () {     int array[ 100 ],a,b,n,sum;     printf ( "enter the value through which you want to add:" );     scanf ( "%d" ,&n);     printf ( "enter %d integers:" ,n);     for (a= 0 ;a<=n;a++)     {         scanf ( "%d" ,&array[a]);         sum= sum+ array[a];     }     printf ( "%d" ,sum);     }

Adding of n numbers using for loop

  #include <stdio.h> int main () {     int i,j,m,n,sum= 0 ;     printf ( "enter the number :" );     scanf ( "%d" ,&n);     printf ( " enter   %d integer" ,n);     for (i= 0 ;i<n;i++)     {         scanf ( "%d" ,&m);         sum=sum+m;     }     printf ( "the sum of the entered number is = %d" ,sum);     }

Working of 3d array

// //   Created by ANKIT KUMAR on 26/03/21. // #include <stdio.h> int main () {     int i,j,k,a[ 3 ][ 3 ][ 3 ];     for (i= 0 ;i< 3 ;i++)     for (j= 0 ;j< 3 ;j++)     for (k= 0 ;k< 3 ;k++)     a[i][j][k]=i+j+k;     for (i= 0 ;i< 3 ;i++)     {         printf ( "\n" );                   for (j= 0 ;j< 3 ;j++)     {         for (k= 0 ;k< 3 ;k++)         printf ( "%3d" ,a[i][j][k]);         printf ( "\n" );     }     } }  

Binary file

  #include <iostream> #include <fstream> using namespace std; struct Student { int roll; string name; }; int main() { fstream fout; int i; fout.open("student.dat", ios::out | ios::binary); if(!fout) { cout<<"File could not be opened"; return 1; } Student st[3]; for(i = 0; i < 3; i++) { cout<<"Enter Student"<<i + 1<<" details(roll no, name): "; cin>>st[i].roll; cin>>st[i].name; } for(i = 0; i < 3; i++) { fout.write((char *)&st[i], sizeof(Student)); } fout.close(); if(!fout.good()) { cout<<"File corrupted while writing"; return 1; } }