Type Here to Get Search Results !

C-Language Programs


C-Language Programs





 Introduction to C- Programming 


C- Programming is a language which is used to develop compiler for softwares like java compiler and . net compiler.

C- programming first introduced by dennis ritchie.

C- programming is basic language which help us to develop different softwares.


General syntax for C programming which is used C-Language Programs


Before we see the detail programming for C we have to know the basic syntax of C programming if we understand syntax of C it help us to solve the all program which we run in future.

In C-Language Programs basic syntax is as follow:-

Header file


int main()

{

variable declaration;

statement;

return 0;

}


Now, we see each property meaning which mention in the above syntax.


Header file


Header file contains the set of functions and this functions complete there related tasks.Header files are very important to declare in C-Language Programs.

Header file basically used to give the instructions to compiler to complete there task one by one

In C- programming some header files are pre defined.

Following are some pre defined header files.


1) # include <stdio.h> 


2) # include <conio.h> 


3) # include <string.h>


As per project requirement we also defined the header files which we called user defined header files.


4) # include <dmart.h>


Header file contains different set of functions and that functions perform there particular task in project.


1) # include <stdio.h> 


This header file contains following functions.


a) printf()


printf() function is defined in  # include <stdio.h> which is used to display message on screen.


b) scanf()


scanf() function is defined in # include <stdio.h> which is used to read or take value from user.


2) # include <conio.h>


This header file define following functions.


a) getch()


getch() function is defined in  # include <conio.h> this is used to get character from source code and hold screen to display the output.


b) clrscr()


clrscr() function is defined in # include <conio.h> it is help to clear screen from previous output.


3)int main ();

it is function which is used to perform specific operation.


the main does not return any value so we have to use int/ void before the main function.


4)Variable Declaration


it is used to store the value.

eg. int a=40;


here is a variable and value flow from this variable from right to left  40 store in 'a' variable.

flow per =88.99;


Types of Variables


a)Global variable


b)Local variable


a)Global variable


Such variable value will be accessible through out the program ( will work with in all function) Hence scope (working area ) is unlimited of global variables.


b)Local variable


Such variable value will be accessible only within function hence scope ( working area) is limited of local variable.


Note:- Return 0

the main function does not return any value, so we have to used return zero at the end of main function.


 Operators in C programming which help in C-Language Programs.

In C-Language Programs it is very important to no the working and proper implementation of operators so lets we see it one by one

1) Arithmetic Operator 


a)   +  pulse operator

b)   - minus operator 

c)  * star operator

d) %  mod operator

e) /  division


2)Relation operator/conditional operator


a)  >        - greater than

b)  <        - Less than

c)  >=      -greater than equal to

d)  <=      -less than equal to

e)  ==      -equal to equal to


3)Logical operator

a)  &&     - and operator.

b) //     - or operator.

c)  !       - not operator.


4)Incremental and decrement operator

a) post increment       a ++

b) pre increment         ++a

c) post decrement      a--

d) pre decrement        --a


Lets we see C-Language Programs .C-Language Programs programs save by 
"file name.c"

 Program 1.C (First save the file )

 Here we just print the name of  india and pune
 

# include<stdio.h>

int main ()

    printf(" \n welcome to India");

   printf("\n  welcome to Pune");

   return 0;

}


o/p-welcome to india

     welcome to pune

Note- C-Language Programs \n is used to print output in one by one line

          


Program 2.C 


C-Language Programs .When variable value is given like below program then we have to mention that variable in int main().


Write a program to print sum of 3 numbers from given numbers.

a=100, b=200 , c=300


#include<stdio.h>

int main()

{

   int a=100,b=200,c=300;

   int s;

    s= a+b+c;

   printf("\n sum of all number is  %d", s);

   return 0;

}

o/p- sum of all number is 600


Note-  C-Language Programs %d is used to print the value of S variable which we pass in printf function without the %d we can print the value of s in C-Language Programs


Program 3.C 


Write a program to print sum of 3 numbers and also mean of the given numbers by using C-programming.

a=10, b=20 , c=30


#include<stdio.h>

int main()

{

   int a=10,b=20,c=30;

   int s;

  float m;

    s= a+b+c;

  m=s/3;

   printf("\n sum of all number is  %d", s);

   printf("\n mean is  %d", m);


   return 0;

}

o/p- sum of all number is 60

      mean is 20.

 Note-If we want to print the float value in C-Language Programs the print like this printf("\n mean is  %d 0.2f", m).


C-Language Programs to learn about the data types is very important so for to see other examples first we first the data types in C-Language Programing.


Data Types in C Programming

Understanding data types is crucial for managing different kinds of data in a program. Here are some commonly used data types in C:

  1. int: Used for storing integer values.

    • Format Specifier: %d
    • Example: int age = 25;
  2. float: Used for storing single-precision floating-point numbers.

    • Format Specifier: %f
    • Example: float salary = 7500.50;
  3. char: Used for storing a single character.

    • Format Specifier: %c
    • Example: char grade = 'A';
  4. char[size]: Used for storing a sequence of characters (a string).

    • Example: char name[20] = "John";

By understanding these data types, you can effectively manage and manipulate different forms of data in your C programs.

Conclusion

C programming is an essential starting point for anyone interested in learning the fundamentals of computer science and programming. It provides a strong foundation by introducing key concepts such as variables, data types, operators, and basic input/output operations. Mastering these basics through practice allows you to build the skills needed to tackle more advanced topics, including pointers, memory management, and data structures. Understanding C equips you with the knowledge to develop efficient software and contributes to a deeper comprehension of how computers operate at a low level.





Top Post Ad

Bottom Post Ad