Posts

c patterns level 2

Image
/******************************************************************************                             Online C Compiler.                 Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> int main() {     int i,j,k=1,l=9,tmp;     for(i=1,k=1;i<=10;i++,k=k+2,l--){           tmp=l;         for(j=1;j<=19;j++){                     if(j<=k){                        if(j<=i) {                ++tmp;                if(tmp!=10) printf("%d",tmp);                else printf("0");            }            else {                --tmp;                if(tmp!=10) printf("%d",tmp);                else printf("0");            }           }                                                     }                        

patterns programs in c

Image
/******************************************************************************                             Online C Compiler.                 Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> int main() {     int i,j,k,l;     for(i=1;i<=9;i++){               for(j=1;j<=5;j++){                      if(i<6){if(j<6-i) printf("  ");             else printf("* ");         }         else{             if(j<=i-5) printf("  ");             else printf("* ");         }               }         printf("\n");           }     return 0; } /******************************************************************************                             Online C Compiler.                 Code, Compil

task : debug the prime number logic

#include <stdio.h> #include <math.h> void main(){   int x,n=0,i; scanf("%d",&x); for(i=0;i<(int)sqrt(x);i++){     if(x%i==0){     n=1;     break;     }     } if(n==1) printf("not"); else printf("PRIME"); }

reverse of given string worlds c program -asr

Image
#include <stdio.h> void main(){         int i=0,len,num=0,a[10],j,f,l;     char s[100];                 while(1){         s[i]=getchar();         if(s[i]=='\n'){                 len=i;           //get chatacters                 s[i]=' ';        //set last character as space             break;   //break if enter pressed         }                 i++;     }         for(i=0;i<len;i++){     if(s[i]==' '){         a[num]=i+1;     //detect the positions where space is present         num++;     }     }    a[num]=len+1;    //insert length in top index + incremented for including the space that we assigned for(i=num;i>=0;i--){         f=a[i];     l=a[i-1]; for(j=l;j<f;j++){     printf("%c",s[j]);   //prints reverse     } } }

kite patterns in c

Image
/******************************************************************************                             Online C Compiler.                 Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> int main() {     int i,j,k;     for(i=1;i<=6;i++){             for(j=1;j<=5;j++){         if(i==1||i==5) {                        if(j==3) printf("*");             else printf(" ");                     }            if(i==2||i==4||i==6) {                        if(j>1&&j<5) printf("*");             else printf(" ");                     }            if(i==3) {                        printf("*");                               }                                     }         printf("\n"

beautiful stars pattern based on inputted number-asr

Image
/******************************************************************************                             Online C Compiler.                 Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> #include <stdlib.h> int main() {     char a[20],n[10]; int num[10],x=0; int i=0,big=1,j; while(1){ a[i]=getchar(); n[0]=a[i]; //assignt into n[0] otherwise will err...coz index start from 0 num[x]=atoi(n);    if(a[i]=='\n'){     break;    }  i++; x++; } big=num[0]; for(i=1;i<x;i++){       if(big<num[i])   {         big=num[i];      //finding big number from input       }    } for(i=0;i<=big;i++){      for(j=0;j<x;j++){             if(i==big)       {           printf("%d ",num[j]);  // print numbers in bottom       }  

aaabb to32 ,aabbb to a2b3 convert in c-asr

Image
/******************************************************************************     Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> int main() {   char s[10],c[10];   int i=1,j,tmp[10];   int p[10];   static int x,num=0;   s[0]='*';   c[0]='*';   tmp[0]=0;  printf("\nEnter a string\n");  while(1){     s[i]=getchar(); //reads single characters until enter pressed      if(s[i]==s[i-1])    //checks the previous character matched or not      { x++; tmp[num]=x; //increment x as much as character matches the previous characters insert into tmp      }      else{ x=1; c[num]=s[i-1]; num++;          tmp[num]=x;  //if not matched then x is 1 as above in sta