Thursday, 18 August 2022

 Variables in C are associated with data type. Each data type requires an amount of memory and performs specific operations.

There are some common data types in C −

  • int − Used to store an integer value.

  • char − Used to store a single character.

  • float − Used to store decimal numbers with single precision.

  • double − Used to store decimal numbers with double precision.


#include <stdio.h>

int main() {
   // datatypes
   int a = 10;
   char b = 'S';
   float c = 2.88;
   double d = 28.888;
   printf("Integer datatype : %d\n",a);
   printf("Character datatype : %c\n",b);
   printf("Float datatype : %f\n",c);
   printf("Double Float datatype : %lf\n",d);
   return 0;

 Control statement

if statement:- 


  1. #include<stdio.h>    
  2. int main(){    
  3. int number=0;    
  4. printf("Enter a number:");    
  5. scanf("%d",&number);    
  6. if(number%2==0){    
  7. printf("%d is even number",number);    
  8. }    
  9. return 0;  
  10. }    
  11. Program to find the largest number of the three.

    1. #include <stdio.h>  
    2. int main()  
    3. {  
    4.     int a, b, c;   
    5.      printf("Enter three numbers?");  
    6.     scanf("%d %d %d",&a,&b,&c);  
    7.     if(a>b && a>c)  
    8.     {  
    9.         printf("%d is largest",a);  
    10.     }  
    11.     if(b>a  && b > c)  
    12.     {  
    13.         printf("%d is largest",b);  
    14.     }  
    15.     if(c>a && c>b)  
    16.     {  
    17.         printf("%d is largest",c);  
    18.     }  
    19.     if(a == b && a == c)   
    20.     {  
    21.         printf("All are equal");   
    22.     }  
    23. }  
    if else- if statement

    1. #include<stdio.h>    
    2. int main(){    
    3. int number=0;    
    4. printf("enter a number:");    
    5. scanf("%d",&number);     
    6. if(number==10){    
    7. printf("number is equals to 10");    
    8. }    
    9. else if(number==50){    
    10. printf("number is equal to 50");    
    11. }    
    12. else if(number==100){    
    13. printf("number is equal to 100");    
    14. }    
    15. else{    
    16. printf("number is not equal to 10, 50 or 100");    
    17. }    
    18. return 0;  
    19. }    

Wednesday, 3 August 2022

c program structure

 

//C program structure

/**                    

// file: age.c             //Documentation

 * author: you

 * description: program to find our age.

 */

#include <stdio.h>      //Link

#define BORN 2000       //Definition

int age(int current);   //Global Declaration

int main(void)          //Main() Function

{

  int current = 2021;     //Local declaration

  printf("Age: %d", age(current));

  return 0;

}

int age(int current)

{         return current - BORN;   //Subprograms

 

}

 

Tuesday, 2 August 2022

 1) Demonstrate C programming Structure 

2) Use of data types 

3) Use of control statements

 4) Use of looping statements

 5) Demonstrate input output statements

 6) Use of user define function 

7) Demonstrate recursion function

 8) Use of array

 9) Demonstrate string library function 

10) Demonstrate structure