Posts

Given a sentence, , print each word of the sentence in a new line.

#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() {     char *s,tmp;     int len,i;     s = malloc(1024 * sizeof(char));     scanf("%[^\n]", s);     s = realloc(s, strlen(s) + 1);     //Write your logic to print the tokens of the sentence here.         len=strlen(s);     for(i=0;i<len;i++){         tmp=s[i];         if(tmp==' '){     printf("\n");             continue; }         printf("%c",s[i]);             }     return 0; }

spiral like pattern program in c

#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() {     int n,i,j,boundry,num;     scanf("%d", &n); boundry=(n*2)-1;     for(i=0;i<boundry;i++){      for(j=0;j<boundry;j++){           if(i<j) num=i; else num=j;          if(num>=boundry-i) num=boundry-i-1;          if(num>=boundry-j-1) num=boundry-j-1;          printf("%d ",n-num);                //printf("sa");     }          printf("\n");     }         return 0; }

bitwise AND OR NOT operations between numbers c program

Image
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> //Complete the following function. void calculate_the_maximum(int n, int k) {   //Write your code here.     int a1=0,o1=0,xo1=0,tmp1,tmp2,tmp3;     int s[n+1],i,j;     for(i=0;i<n;i++){         s[i]=i+1;     }       for(i=0;i<n;i++){         for(j=i+1;j<n;j++){          if(o1<s[i]|s[j]){              tmp1=s[i]|s[j];              if(tmp1<k){                              o1=s[i]|s[j];                                      }                            }                                 tmp2=s[i]&s[j];            if(a1<tmp2){              if(k>tmp2) {a1=s[i]&s[j];                         // for testing           printf("\n %d&%d=%d & k=%d",s[i],s[j],s[i]&s[j],k);                         }                                               }                                 tmp3=s[i]^s[j];            if

C program to reverse a string without using any string functions-asr

Image
#include <stdio.h> #include <conio.h> void main() { char *s; int len,i=0; clrscr(); printf("\nENTER A STRING: "); gets(s); while(1){ if(s[i]=='\0'){ len=i; break; }          i++; }        for(i=len;i>=0;i--){ printf("%c",*(s+i));        } getch(); }

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"); }