Posts

ANAGRAM FOR STRING

Image
Consider the following I/O samples. SAMPLE INPUT :  abcd cdba SAMPLE OUTPUT:   ANAGRAM C PROGRAM: #include<string.h> #include <stdio.h> int main() {     int i,arr[26]={0};     char s1[100],s2[100];     scanf("%s %s",s1,s2);     for(i=0;s1[i]!='\0';i++)         arr[s1[i]-'a']++;     for(i=0;s2[i]!='\0';i++)         arr[s2[i]-'a']--;     for(i=0;i<26;i++)     {         if(arr[i]!=0)         {             printf("Not a Anagram");             return 0;         }     }     printf("Anagram"); }   OUTPUT:      The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.  If you have any feedback about this article ...

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

Image
Consider the following I/O samples. SAMPLE INPUT :  200 300 SAMPLE OUTPUT:   204 208 212 216 220 224 228 232 236 240 244 248                                             252 256  260 264 268 272 276 280 284 288 292 296 C PROGRAM: #include <stdio.h> int checkLeapYear(int year) {     if( (year % 400==0)||(year%4==0 && year%100!=0) )         return 1;     else         return 0; }   int main() {     int i,n,s;     scanf("%d %d",&s,&n);     printf("Leap years from %d to %d:\n\n",s,n);     for(i=s;i<=n;i++)     {         if(checkLeapYear(i))             printf("%d ",i);     }     return 0; }   OUTPUT:      The ...

SWAP TWO NUMBERS USING BITWISE (XOR)

Image
Consider the following I/O samples. SAMPLE INPUT :  8000  200 SAMPLE OUTPUT:   200 8000 C PROGRAM: #include <stdio.h> int main() {      int a,b,t;     scanf("%d %d",&a,&b);     printf("\nBefore swapping : A = %d B = %d",a,b);     a^=b;                 b^=a;                 a^=b;       printf("\nAfter swapping : A = %d B = %d",a,b);     return 0; }   OUTPUT:      The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.  If you have any feedback about this article and want to improve this, please comment in the comment section.  

SWAP TWO NUMBERS WITHOUT USING A THIRD VARIABLE

Image
Consider the following I/O samples. SAMPLE INPUT :  600  1200 SAMPLE OUTPUT:   1200 600 C PROGRAM: #include <stdio.h> int main() {      int a,b,t;     scanf("%d %d",&a,&b);     printf("\nBefore swapping : A = %d B = %d",a,b);     a=a+b-(b=a);     printf("\nAfter swapping : A = %d B = %d",a,b);     return 0; } ANOTHER METHOD:                   a=a+b;                 b=a-b;                 a=a-b;   OUTPUT:      The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.  If you have any feedback about this article and want to improve this, please comment in the comment section.  

SUM OF DIGITS UNTIL IT CHANGES TO A SINGLE NUMBER

Image
Consider the following I/O samples. SAMPLE INPUT :  9863 == 9+8+6+3=26 == 2+6=8 SAMPLE OUTPUT:   8 C PROGRAM: #include <stdio.h> int main() {     int n;     scanf("%d",&n);     if(n%9 == 0)         printf("9");     else         printf("%d",n%9);     return 0; }   OUTPUT:      The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.  If you have any feedback about this article and want to improve this, please comment in the comment section.  

OCTAL TO BINARY CONVERSION

Image
Consider the following I/O samples. SAMPLE INPUT :  23 SAMPLE OUTPUT:   10011 C PROGRAM: #include <stdio.h> #include<math.h> int main() {    long int n, dec=0, bin=0, i=0;     scanf("%ld",&n);     while(n)     {         dec+=(n%10)*pow(8,i);         ++i;         n/=10;     }     i=1;     while(dec)     {         bin+=(dec%2)*i;         dec/=2;         i*=10;     }     printf("%ld",bin);     return 0; }   OUTPUT:      The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.  If you have any feedback about this article and want to improve this, please comment in the comment section.  

OCTAL TO DECIMAL CONVERSION

Image
Consider the following I/O samples. SAMPLE INPUT :  32 SAMPLE OUTPUT:   26 C PROGRAM: #include <stdio.h> int main() {     long int n, base=1, rem, ans=0;     scanf("%ld",&n);     while(n)     {         rem=n%10;         ans=ans+rem*base;         base=base*8;         n=n/10;     }     printf("%ld",ans);     return 0; }   OUTPUT:      The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.  If you have any feedback about this article and want to improve this, please comment in the comment section.