Results for C Tutorial

Multiplication Table using C program

January 04, 2020


C program to print Multiplication Table

                    Hello, In this blog we see the c program code to print multiplication table. In this program user give the input and depends on that integer number the multiplication table will displayed.

Code:
#include<stdio.h>
#include<conio.h>
void main()
{
 int s,i,a;
 clrscr();
    printf("Enter the number to print the multiplication table: ");
    scanf("%d",&s);
    printf("\n");
 for(i=1; i <= 10; i++)
 {
     printf("%d",s);
     printf(" * ");
     printf("%d",i);
     a=s*i;
     printf("=%d",a);
     printf("\n");
 }
getch();
}


         In the above code we use variable 's' to store the input value. And by using for loop the actual multiplication table is displayed.

Output:

Enter the number to print the multiplication table:7
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70


Multiplication Table using C program Multiplication Table using C  program Reviewed by Amit Waghmare on January 04, 2020 Rating: 5

Switch statement

August 19, 2019


Read any month number and display Month name in word
using of switch statement



Hello friends, in this blog we see the use of switch statement. Switch statement is also known as switch case because in this cases are executed according to user choices. This is multiple or multiway branching statement. Switch statement checks whether an expression matches any one of the constant value or not if not the control is transfer to the next statement. If none of any case matches the control is transfer to default condition.

Syntax:
                   switch(expression)
                         {case 1:
           statement 1;
           break;
                                  case 2:
           statement 2;
           break;
                                 case 3:
          statement 3;
          break;
.
.
.

       case n:
          statement n;
           break;
                                  default:
           statement;
                                 }
C program for read any month number and display Month name in word

#include<stdio.h>
#include<conio.h>
void main()
{
int n; //declar integer n
clrscr(); //to clear output screen
printf("Enter the month No:-> ");
scanf("%d",&n);  //store the input in n variable
   switch(n) //pass the value of n in switch case
   {
          case 1:
          printf("January\n");//if n=1 the Jaunary will print
                 break;
                 //to break or stop the execution and pointer goes to next step
          case 2:
          printf("February\n");
                 break;
          case 3:
          printf("March\n");
                 break;
          case 4:
          printf("April\n");
                 break;
          case 5:
          printf("MAy\n");
                 break;
          case 6:
          printf("June\n");
                 break;
          case 7:
          printf("July\n");
                 break;
          case 8:
          printf("August\n");
                 break;
          case 9:
          printf("September\n");
                 break;
          case 10:
          printf("October\n");
                 break;
          case 11:
          printf("November\n");
                 break;
          case 12:
          printf("December\n");
                 break;
          default:
          //if all 12 conditions are returns false then default will execute
          printf("Invalid Month number\nPlease try again ....\n");
                 break;
      }
getch();
}
________________________________________________________

Output:
Enter the month No:0
Invalid Month number
Please try again ....

Enter the month No:7
July

Enter the month No:3
March

Enter the month No:1
January

Enter the month No:9
September

Enter the month No:13
Invalid Month number
Please try again ....


Switch statement Switch statement Reviewed by Amit Waghmare on August 19, 2019 Rating: 5

Volume of cylinder C language

August 14, 2019
C program for volume of Cylinder

          Hello friends, in this blog we see the c program for finding the Volume of cylinder. To find the volume of a cylinder we must know the formula for calculating the area of cylinder i.e. vol = pie * r * r * h.
In this formula the value of is in float i.e. 3.14, so we are using float datatype and for store fractional value we use %f. By using the following program, we find the area of the cylinder.

C language code for Volume of cylinder:
#include<stdio.h>
#include<conio.h>

void main()
{
    float vol,pie=3.14;

    float r,h;

    clrscr();

    printf("ENTER THE VALUE OF RADIUS:");

    scanf("%f",&r);

    printf("ENTER THE VALUE OF HEIGHT:");

    scanf("%f",&h);

    vol = pie * r * r * h;

    printf("VOLUME OF CYLINDER IS : %f ",vol);

    getch();

}
Output:­
ENTER THE VALUE OF RADIUS: 7
ENTER THE VALUE OF HEIGHT :3
VOLUME OF CYLINDER IS: 461.58

ENTER THE VALUE OF RADIUS: 4.6
ENTER THE VALUE OF HEIGHT: 6.8
VOLUME OF CYLINDER IS: 451.80832



Volume of cylinder C language Volume of cylinder C language Reviewed by Amit Waghmare on August 14, 2019 Rating: 5

Area of circle in C language

August 14, 2019


C program for area of circle

          Hello friends, in this blog we see the c program for finding the area of the circle. To find the area of the circle we must know the formula for calculating the area of circle i.e. area = 3.14 * radius * radius.
In this formula, the value of is in float i.e. 3.14, so we are using float datatype and for store fractional value we use %f. By using the following program we find the area of the circle.

C language code for Area of Circle:
#include<stdio.h>
#include<conio.h>

void main()
{
   float radius, area;/* to accept floating number*/

   printf("\nEnter the radius of Circle : ");
           //take input from the user

   scanf("%f", &radius);
      /* to store the floating number,
       &radius is used to store the number in radius variable*/

   area = 3.14 * radius * radius;
    // formula and answer store in area variable

   printf("\nArea of Circle : %f  sq.unit", area);  // display answer
   getch();
}
_____________________________________________________________
Output:
Enter the radius of Circle:3
Area of Circle:28.26

Enter the radius of Circle:9.54
Area of Circle: 285.776424





Area of circle in C language Area of circle in C language Reviewed by Amit Waghmare on August 14, 2019 Rating: 5

Consonant and vowels

August 12, 2019




Count Consonant and Vowels

            Hello friends, here we are seeing the c program for the count the number of the vowel and consonant in the given string. We know a, e, i, o, u are five vowels. But how we check how many times the vowels and consonant have come in the sentence. So by using the following c program we easily count the number of vowels and consonant in the given string.


C language code for count the consonant and vowel:
#include<stdio.h>
#include<conio.h>
void main()
{
            int c=0,count=0;
            char s[1000];
            int i;
            clrscr();

printf("Enter the string:"); //for take a string from user

gets(s);//this function is use to store the string

    for(i=0;s[i]!='\0';++i); //for accessing each character from the string and count the character

    printf("Length of given string: %d\n", i);//print the no of character including space

while(s[c]!='\0')//string is not null
            {

              if(s[c]=='a' || s[c]=='A' || s[c]=='e'|| s[c]=='E' || s[c]=='i' ||
              s[c]=='I' || s[c]=='o' || s[c]=='O' || s[c]=='u' || s[c]=='U')
              //compares vowels with each and every character

              count++;// for counting the vowels

              c++; //go to next character

            }

            printf("The no of vowels in the given string is:%d\n",count);
            // no of vowels in a given string

            printf("Number of Consonent with spaces in the given string:%d\n",i-count);
            //no of the consonant in the given string

            getch(); //this function holds the output screen
}

Output:
Enter the string: c language
Length of given string:10
The no of vowels in the given string is:4
Number of Consonant with spaces in the given string:6



Consonant and vowels Consonant and vowels Reviewed by Amit Waghmare on August 12, 2019 Rating: 5

Number of vowels

August 11, 2019


Check the number of vowels in the given string


                 Hello friends, here we are seeing the c program for the count the number of the vowel in the given string. We know a, e, i, o, u are five vowels. But how we check how many times the vowels have come in the sentence. So by using the following c program we easily count the number of vowels in the given string.

C language code for count the vowel:

#include<stdio.h>

#include<conio.h>

void main()

{
int c=0,count=0;
char s[1000];
clrscr();
printf("Enter the string:");
gets(s);
while(s[c]!='\0')
            {
              if(s[c]=='a' || s[c]=='A' || s[c]=='e'|| s[c]=='E' || s[c]=='i' ||
              s[c]=='I' || s[c]=='o' || s[c]=='O' || s[c]=='u' || s[c]=='U')

            count++;
              c++;
            }
            printf("The no of vowels in the given string is:%d\n",count);
            getch();
}
______________________________________________
Output:
Enter the string: ccpptutoriallands_blogspot_com
The no of vowels in the given string is:8


Number of vowels Number of vowels Reviewed by Amit Waghmare on August 11, 2019 Rating: 5

C language code for palindrome string

July 23, 2019


               
                                           
                                       A palindrome is a string, integer number or another sequence of characters that reads the same backward as forward, such as madam or racecar or the number 76567. If we read madam from the front or back side then the spelling and pronunciation are same i.e. nayan=nayan. The actual code for the palindrome string is as follows:   



C language code for Palindrome string:

#include <stdio.h>om

#include <string.h>

void main()

{

  char a[100], b[100];

  clrscr();

  printf("Enter a string to check if it is a palindrome:\n");

  gets(a); //to accept the string from user



  strcpy(b,a);  // Copying input string

  strrev(b);  // Reversing the string by inbuild function strrev()



  if (strcmp(a,b)==0)  /* Comparing input string using

  inbuild function strcmp() with the given reverse string*/



  printf("The string is a palindrome.\n");/* when if condition

  is satisfy or true */


  else

    printf("The string is not a palindrome.\n");/* when if condition

    is not satisfy or false */

  getch();

}

------------------------------------------------------------------------------

Output:

Enter a string to check if it is a palindrome:

asdfdsa

The string is a palindrome.
C language code for palindrome string C language code for palindrome string Reviewed by Amit Waghmare on July 23, 2019 Rating: 5

Area of square

June 21, 2019


Area of Square


                    To calculate the area of the square we must know the formula area of the square is  area=side*side
                   To perform this operation in the c language first take the two variables as side and area to display or store the final answer. Then take the input from the user using scanf, then store that values in the side as shown in the code. Pass this variable in formulae to calculate the area of the square. Then the answer is stored in area variable, display area. Refer the following code to calculate the area of the square.  

C language code to calculate the area of square:

#include<stdio.h>

#include<conio.h>

int main()
 {
   int side, area;

   clrscr();

   printf("\nEnter the Length of Side : ");

   scanf("%d",&side);//to accept the side

   area=side*side;//formula to find the area of a square

   printf("\nArea of Square:%d",area);//To display the final answer

   getch();
}
-----------------------------------------------------------------------------------------
Output:
Enter the Length of Side: 5
Area of Square: 25

Area of square Area of square Reviewed by Amit Waghmare on June 21, 2019 Rating: 5

Area of Rectangle

June 21, 2019


Area of Rectangle

                          To calculate the area of the rectangle we must know the formula area of rectangle=Length*Breadth.
                              To perform this operation in the c language first take the three variables like length, breadth, and area to display or store the final answer. Then take the input from the user using scanf, then store that values in length and breadth as shown in the code. Pass these variables in formulae to calculate the area of the rectangle. Then the answer is stored in area variable, display area. Refer the following code to calculate the area of the rectangle.  

C language code to calculate area of Rectangle:

#include<stdio.h>
#include<conio.h>

void main()
{
   int length, breadth, area;

   clrscr();

   printf("\nEnter the Length of Rectangle:");

   scanf("%d",&length);           //to accept length of rectangle

   printf("\nEnter the Breadth of Rectangle:");

   scanf("%d",&breadth);        //to accept breadth of rectangle

   area=length*breadth;          //formula to find area of rectangle

   printf("\nArea of Rectangle:%d",area);//display area

   getch();
}
--------------------------------------------------------------------------------------
Output:
Enter the Length of Rectangle:6
Enter the Breadth of Rectangle:7
Area of Rectangle:42







Area of Rectangle Area of Rectangle Reviewed by Amit Waghmare on June 21, 2019 Rating: 5

Check given number is Palindrome or not.

June 20, 2019



                           
                                          First, we see what Palindrome number. If we are giving input as 1254 the program separates each and every integer no and rearrange it in a reverse manner and again see the original number is the same or not, the i.e original number is 1254 and reversed number is 4521, but 1254 is not equal to 4521. Then the output is like 1254 is not a Palindrome number. To see the demo of this code see the following code. 

C language code to check the given number is a palindrome or not:
#include<stdio.h>
#include<conio.h>
void main()
{
    int n, a = 0, r, ori_no;
    clrscr();
    printf("Enter an integer: ");
    scanf("%d", &n);

    ori_no = n;//to store the original number

    while( n!=0 ) //number must be a non zero integer number

    {
       //following formulas to check the given number is palindrome or not
r = n%10;
a = a*10 + r;
n /= 10;
    }

    // palindrome if ori_no and r are equal
    if (ori_no == a)
printf("%d is a palindrome.", ori_no);
    else
printf("%d is not a palindrome.", ori_no);

    getch();
}
-------------------------------------------------------------------------------
output:

Enter an integer:546
546 is not a palindrome.


Enter an integer:45654
45654 is not a palindrome.








Check given number is Palindrome or not. Check given number is Palindrome or not. Reviewed by Amit Waghmare on June 20, 2019 Rating: 5