Posts

Showing posts from October, 2018

print an array in zigzag order

Image
int main() { int a[7]={3,4,6,2,1,8,9}; int flag =0,n=3,i=0,k; while(n) {     if(flag==0&&a[i]<a[i+1])     {             flag=1;       i++;     }     else{       k=a[i];       a[i]=a[i+1];       a[i+1]=k;       i++;           }     if(flag==1&&a[i]>a[i+1])     {          flag=0;         i++;     }     else     {       k=a[i];       a[i]=a[i+1];       a[i+1]=k;       i++;           }         n--; } for(i=0;i<7;i++) {   printf("%d\t",a[i]); } } OUTPUT:

Print 2-D array in spiral order

#include <stdio.h> int main() { int arr[3][3]= {                 {1, 2, 3},                 {4, 5, 6},                 {7, 8, 9},             };        spiral(arr);    return 0; } void spiral(int arr[3][3]) {     int top =0,right=2,left=0,bottom=2,dir =1, i;         while(top <= bottom && left <= right)     {         if (dir==1)         {             for( i =0;i<=2;++i)             {                 printf("%d",arr[top][i]);             }               ++top;               dir=2;   ...

HANGMAN GAME IN JAVASCRIPT

<html> <script> alert("Note: This ia a Game where You will guess words by using input as letters you shoud give input based on blankspaces && your guessing is limited to 15"); var words= ["javascript","monkey","amazing","pancake","album", "atlas", "bestseller", "booklet", "brochure", "codex", "compendium", "copy", "dictionary", "dissertation", "edition", "encyclopedia", "essay", "fiction", "folio", "handbook", "hardcover", "leaflet", "lexicon", "magazine", "manual", "monograph","nonfiction", "novel", "octavo", "offprint", "omnibus", "opus", "opuscule", "pamphlet", "paperback", ...

Converting Celsius to Fahrenheit and Fahrenheit to Celsius

#include <stdio.h> int main() { float c,f; int x; //press 1 if u want temperature in celsius //press 2 if u want temperature in fahrenheit printf("Enter your choice 1 || 2 \n"); scanf("%d",&x); switch(x) {   case 1:     printf("Enter the value of temperature in farenheit\n");     scanf("%f",&f);     c=f-32;     printf("The value of temperature in celsius is %1.f",c/9);     break;   case 2:     printf("enter the value of temperature in celsius\n");     scanf("%f",&c);     f= 9*c;     printf("The value of temperature in fahrenheit is %1.f",f+32);     break;   return 0; } }

Fibbonacci series

Image
int main() { int f1 =0,f2=1,f; for(int i=0;i<5;i++) {   f = f1 +f2;   f1=f2;   f2=f;   printf("%d\t",f); }   return 0; }

Selection sort

Image
void selectionSort(int A[],int n) {   for(int i=0;i<=4;i++)   {     int imin=i;     for(int j=i+1;j<=5;j++)     {       if(A[j]<A[imin])       {         imin = j;       }       int temp = A[i];       A[i] = A[imin];       A[imin] = temp  ;     }   } } int main() {   int A[]={2,4,7,1,5,3};   selectionSort(A,6);   for(int i=0;i<=5;i++)   {     printf("%d",A[i]);   }     return 0; }