Recent Posts

Showing posts with label C programs. Show all posts
Showing posts with label C programs. Show all posts

Saturday, 8 December 2018

Program to get 1 string input and print it.

String:

String is a collection of two or more characters.
In the previous post we learn about what is string.and How it can be print.

Program to get one string input and print it.

#include<stdio.h>
#include<conio.h>
void main()
{
char text[50];
clrscr();
printf("type string");
scanf("%s",&text);
printf("string is = %s",text);
getch();
}


Explanation:

1. Void main():
This is the first statement of every 'C' program,without main() function 'C' program cannot be start.If we didn't include main() function in 'C' program then error will be occurred.so every 'C' program must start with main() function.

2.char:
Char is a data type which is used for print the string.

3.Clrscr();
This is the clrscr() function.This function is used to clear the screen.This function is used to clear the output of the previous output window.

4.Printf():
Printf is a function which used to print any text or value on the screen.The text you want to print is enclosed in  double quote.you can see the below example:
                                   printf ("Hello world");
in the above example hello world will be printed.

5.getch();
This function is used to hold the output window.otherwise when you run your code it will display the output window just for a second so it is necessary to use it in our program.If we want to hold our  output screen.




Tuesday, 31 July 2018

How to print pattern in C

In the previous post we learn about Program for palindrome number in C and Sum of digits in C and in this post we will learn how to create pyramid, half of pyramid and patterns using *

We can create pyramid, half pyramid and patterns by using loops if, if else.
you need to have the basic knowledge of loops if...else ,while, do while, continue and break.

Program to print patterns and pyramids and half pyramids :

1.Program to print half pyramid print using * :


#include <stdio.h>

#include <conio.h>

int main()

{

    int i, j, r;

   for(i=1; i<=5; i++)

    {

        for(j=1; j<=i; j++)

        {

            printf("* ");

        }

        printf("\n");

    }

    return 0;

}

Output:
*
**
***
****
*****
















Monday, 30 July 2018

Sum of digits in C

In the previous post we learn about What is palindrome number and How to write a program  for palindrome number.

In this post we will learn how to write a program for sum of digits in C.
Sum of digits means addition of two or more than two numbers for example number 456 will be 15.

456
4+5+6=15

Program for Sum of digits:




#include <stdio.h>

#include <conio.h>

int main()

{

    int n, num, rem, sum=0;

clrscr();

        printf("Enter number");

        scanf("%d",&num);

        while(num>0)

        {

        rem=num%10;

        sum=sum+rem;

        num=num/10;

}

    

    printf("sum of digit=%d",sum);

    getch();

}


Output:
  Enter number: 456
  Sum of digit: 15

Palindrome number in C


Here we will see what is palindrome number and how to write a program for palindrome number.

Palindrome number in C:

A palindrome number that remains the same when its digits are reversed like 323.



Below is the program for palindrome number:



#include <stdio.h>

#include <conio.h>



void main()

{

    int n,num,rem,sum=0;

    clrscr();

    printf("Enter number");

    scanf("%d", &num);

    n=num;

    while (num>0)

    {

        rem=num%10;

        sum=(sum*10) + rem;

        num=num/10;

    }

    if (n==sum)

    printf ("palindrome number");

    else 

    printf ("not palindrome number");

    getch();

}


Output:
 Enter number:313

palindrome number

Thursday, 18 January 2018

C Program to swap two numbers

In the previous post we learnt about Program for addition of two numbers.In this post we learnt about  How to get two numbers and swap it
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter value of a and b");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("after swapping a=%d\tb=%d",a,b);
getch();
}
Output:
Enter value of a and b : 5 7

after swapping:
a=7
b=5

Monday, 8 January 2018

addtion program in C

In the previous tutorial we learn about simple program How to write Hello world in 'C'.and in this post we will learn how to sum two numbers in c programming language.In this tutorial you will get simple addition of two numbers.user will input two numbers and the sum is calculated and printed on the screen.

Addition program in C:


#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr();
printf("enter two number");
scanf("%d%d",&a,&b);
printf("\n sum=%d",a+b);
getch();
}

Output:
enter two number: 5 5
sum: 10

Sunday, 31 December 2017

Hello world in C



In the previous post we learnt How to write 'C' program and Structure of 'C' program.In this post we will learn how to print Hello world in 'C' programming language.We have learned lot of information about C language if you didn't read you can read here C TUTORIAL.Now its time to start first 'C' program to print "Hello world in C".This is the first program "Hello world" write when start any programming language.

Hello world in C program

This is a program to print "Hello world" in C programming language.


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("Hello world");
getch();
}

Output:
Hello world

Explanation:

1. #include<stdio.h>: 
In C programming language every program must start with #include<stdio.h>.It is known as the preprocessor directive of C language.The C preprocessor is a program that process the source code before it passed to the C compiler.If we include this directives in our program then program is easy to read and modify. #include is used in C program for including the stdio.h header  file in C program.we can place directives anywhere in the program but most often they are placed at the beginning of the program.This processor directives do not require a semi colon at the end.

2. Void main():
This is the first statement of every 'C' program,without main() function 'C' program cannot be start.If we didn't include main() function in 'C' program then error will be occurred.so every 'C' program must start with main() function.Here void is a return data type of function.It means that the main() function will not return anything.

3.Clrscr();
This is the clrscr() function.This function is used to clear the screen.This function is used to clear the output of the previous output window.If we don't use this function in our program then output window will be messy.

4.Printf():
Printf is a function which used to print any text or value on the screen.The text you want to print is enclosed in  double quote.you can see the below example:
                                   printf("Hello world");
in the above example hello world will be printed.

4.getch();
This function is used to hold the output window.otherwise when you run your code it will display the output window just for a second so it is necessary to use it in our program.If we want to hold our  output screen.



I hope you will understand this post if you have any question then you can ask me in comments.

Friday, 29 December 2017

Structure of C Program


In the previous tutorial we learnt Rules for writing a 'C' Program.In this tutorial we will learn the Structure of C Program.The C program is the collection of instruction,and instruction is nothing but the statements in C.

Structure of C Program


#include<pre-processor directives>
[macro declaration and definition]
[global variable declaration]
main()
{
       local variable declaration with proper data type;
       :
       :
       statements;
       :
       :
}
[  user_defined_function_definition (arguments)]
       {
          statement_block;
        }
]

Explanation:

#include<pre-processor directives>:
     At this place we have to include all the header files,which are prototype for the statements, which are used in our program.

[Macro declaration and definition]:
     At this place we have to declare and define the definitions of the macro that are used in program.
It is optional.

[Global variable declaration]:
If we required global variables in our program then such variables are declared at this place.It is optional.

main():
This is the first statement of every 'C' program,without main() function 'C' program cannot be start.If we didn't include main() function in 'C' program then error will be occurred.So Every 'C' program must start with main() function.

Local variable declaration:
At this place we have to declare all the variables with proper data type,which are used in our program (in main() function).

Statements:
At this place, we have to write all the statements,which are used to solve the aim of program.

[User-defined-function-definition]:
If any user defined function is called in program,then its definition are given at this place.It is optional.

Example:

#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr();
printf("Enter value of a and b ");
scanf("%d %d",&a,&b);
printf("Sum=%d",a+b);
getch();
}

Sunday, 24 December 2017

How to write C Program

In the C programming language Data type, operator, identifiers, keywords, constants, and variables are the basic building blocks of C Program.Before starting program first we must know :

  1. What alphabet digit and special symbols are used in C.For writing a C program you must have the basic knowledge of following things.If you didn't read this topic you can read here by clicking these link:

                       
     2.  How to construct constant, variable and keywords by using this alphabets digits and special             symbols.
     3. How these are combined to form an instruction.
     4. A group of instruction would be combined to form an program.

Step to learning C program

Rules for writing a C programs and statements:
  1. Every C program should begin with 'main()' function.
  2. Blank spaces can be inserted in between two words to improve readability of the statement.However,no blank spaces are allowed inside a variable, constant and keyword.
  3. Usually all statements are  entered in lower case letters.
  4. C has no specific rules for the position at which a statement is to be written.So it is typically known as free-form language.
  5. Any C statement always end with a semicolon (;).

Followers

Popular Posts

Categories

social media

Text Widget

Powered by Blogger.

About Me

My name is junaid khan and i am a full time blogger and author of a blog tutorial called tutorialpointsolution.

String function

In the previous post we learn about what is String .we know that string is a collection of two or more characters.In string we can store al...

Search This Blog

Technology

Adbox

Recent Post

Breaking

Recent In Internet

Comments

Facebook

Pages

Comments

Pages

Recent

Pages

Technology