Posts

C Program to print Fibonacci Series

Image
 // C Program to print Fibonacci Series #include<stdio.h>      // header file declaration int main()    // main method {      int p1=0,p2=1,p3,i,num;    // variable declaration  printf("FIBONACCI SERIES\n");  printf("Input the number of elements:");      scanf("%d",&num);      printf("\n%d %d",p1,p2);    //printing 0 and 1      for(i=2;i<num;++i)//loop starts from 2   {       p3=p1+p2;       printf(" %d",p3);       p1=p2;       p2=p3;      }     getch();  }     OUTPUT:

C Program to swap two numbers using * and / without using third variable

Image
 // C Program to swap two numbers using * and / without using third variable #include<stdio.h>   //header file declaration  int main()    //main method {     int p=25, q=50;      //variable declaration printf("Before swapping values: p=%d q=%d\n",p,q);      //Before swapping value p=p*q;    q=p/q;        //use of * and / p=p/q;    printf("\nAfter swapping values: p=%d q=%d",p,q);     // After swapping value return 0;   } OUTPUT:

C Program to swap two numbers using + and - without third variable

Image
 // C Program to swap two numbers using + and  - without third variable #include<stdio.h>   //header file declaration  int main()    //main method {     int p=25, q=50;      //variable declaration printf("Before swapping values: p=%d q=%d\n",p,q);      //Before swapping value p=p+q;    q=p-q;    //use of + and - p=p-q;    printf("\nAfter swapping values: p=%d q=%d",p,q);     // After swapping value return 0;   } OUTPUT:

C Program to check whether Year is Leap or not

Image
 // C Program to check whether Year is Leap or not #include<stdio.h>  //header file declaration #include<conio.h>   void main()               // main method {     int year;  // variable declaration     printf("PROGRAM TO CHECK WHETHER YEAR IS LEAP OR NOT \n");     printf("Input year--- ");       scanf("%d", &year);  // Input year        if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))   //check condition     {           printf("It is a leap year", &year);       } else {          printf("It is not a leap year", &year);       }       getch(); }   OUTPUT:

C Program to Reverse a number

Image
//  C Program to Reverse a number #include<stdio.h>            //header file declaration  int main()                   // main method {     int p, rev=0, reminder;    // variable declaration printf("Input a number: ");       scanf("%d", &p);       while(p!=0)       {          reminder=p%10;          rev=rev*10+reminder;          p/=10;       }       printf("Reverse of a number: %d",rev);    // Display output   getch();   }    OUTPUT:

C Program to count the number of digits entered

Image
 // C Program to count the number of digits entered #include <stdio.h>  //header file declaration int main()  //main method {      int p, count=0;            // variable declaration      printf("Input Number--");            //Display input number     scanf("%d",&p);                                   while(p!=0)                                         {          p=p/10;          count++;      }      printf("\nThe number of digits are: %d",count);                ...

C Program to print a message without main() function

Image
 // C Program to print a message without main() function #include<stdio.h>                         //header file declaration #define start main                         // #define preprocessor directive void start() {     printf("WELCOME TO MY BLOG");                    //print message } OUTPUT:

C Program to implement Post-Decrement (p--)

Image
 // C Program to implement Post-Decrement (p--) #include<stdio.h>                    //header file declaration int main()                                // main method {      int p=15;                                //variable declaration      while(p-->10)                    //Post-decrement operator      {           printf("Output is: %d\n", p);                //print output       } getch(); } OUTPUT:     

C Program to implement Pre-Decrement Operator (--p)

Image
 // C Program to implement Pre-Decrement Operator (--p) #include<stdio.h>                    //header file declaration int main()                                // main method {      int p=15;                                //variable declaration      while(--p>10)                    //Pre-decrement operator      {           printf("Output is: %d\n", p);                //print output       } getch(); } OUTPUT:

C Program to implement Post-increment operator (p++)

Image
  // C Program to implement Post-increment operator (++p) #include<stdio.h>                         //header file declaration int main()                                        // main method {      int p=0;                                        //variable declaration      while(p++<10)                         //Post-increment operator      {           printf("Output is %d\n", p);                    //print output       } getch(); } OUTPUT: