Posts

Showing posts from July, 2021

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:

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

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

C Program to implement Decrement Operator (--)

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

C Program to implement Increment Operator (++)

Image
 // C Program to implement Increment Operator (++) #include<stdio.h>                //header file declaration int main()                             // main method {         int p=1;                              //variable declaration         while(p<15)         {                   printf("Output is %d\n",p);                    //print output                 p++;                                         //increment operator         ...

C Program to find the Factorial of a number using For Loop

Image
   // C Program to find the Factorial of a number using For Loop #include<stdio.h>               //header file declaration int main()                               //main method {      int p, facto=1, num;                    //variable declaration      printf("Input Number:");      scanf("%d",&num);                             //Input number       for(p=1;p<=num;p++)                         // Loop      {            facto=facto*p;       }      printf("Factorial of %d is:%d",num, facto); ...

C Program to divide two numbers (Division Operator)

Image
  // C Program to divide two numbers  #include<stdio.h>                //header file declaration int main()                             //main method {      int n1, n2, div;                //variable declartion      printf("\n Input Two Numbers:");      scanf("%d %d", &n1,&n2);                //Input numbers      div=n1/n2;                //division opeartor      printf("The division of two numbers is: %d", div);        //print results      return 0; } OUTPUT:

C Program to multiply two numbers (Multiplication Operator)

Image
 // C Program to multiply two numbers  #include<stdio.h>                //header file declaration int main()                             //main method {      int n1, n2, mul;                //variable declartion      printf("\n Input Two Numbers:");      scanf("%d %d", &n1,&n2);                //Input numbers      mul=n1*n2;                //multiplication opeartor      printf("The multiplication of two numbers is: %d", mul);        //print results      return 0; } OUTPUT:

C Program to subtract two numbers (Subtraction Operator)

Image
  //  C Program to subtract two numbers  #include<stdio.h>                //header file declaration int main()                             //main method {      int n1, n2, sub;                //variable declartion      printf("\n Input Two Numbers:");      scanf("%d %d", &n1,&n2);                //Input numbers      sub=n1-n2;                //subtraction opeartor      printf("The subraction of two numbers is: %d", sub);        //print results      return 0; } OUTPUT:

C Program to add two numbers (Addition Operator)

Image
  // C Program to add two numbers #include<stdio.h>                    //header file declaration int main()                                    //main method {      int n1, n2, add;                    //variable declartion      printf("\n Input Two Numbers:");      scanf("%d %d", &n1,&n2);                    //Input numbers      add=n1+n2;                    //addition opeartor      printf("The addition of two numbers is: %d", add);          //print results      return 0; } OUTPUT :

C Program to Print and Display your name by User Input

Image
   // C Program to Print and Display your name by User Input #include<stdio.h>               //header file declaration int main()                                   //main method {     char name[10];                    //variable declaration     printf("Enter Name:");     scanf("%s", name);                    //input name     printf("My name is: %s", name);                    //print output     getch(); } OUTPUT :

C Program to print your Name

Image
 //C Program to print your name #include<stdio.h>                  //header file declaration int main ()                                         // main method {    printf("My name is: POOJA SHARMA");               //print your name    getch(); } OUTPUT:

C Basic Program to print a Welcome Message

Image
  // C Program to print a Welcome Message    # include <stdio.h> // Header file declaration int main()               // main method { printf("WELCOME TO POOJA BLOG ");          //print message return 0; } OUTPUT: