Vision and dreams are the blueprints of soul and achievements.
-Mohammed Ahmed F

Showing posts with label Program. Show all posts
Showing posts with label Program. Show all posts
Program to know the size of various Data types

Program to know the size of various Data types

#include <stdio.h>

main()
{


printf("short int is %2d bytes \n", sizeof(short int ));

printf("int is %2d bytes \n", sizeof(int ));

printf("int * is %2d bytes \n", sizeof(int *));

printf("long int is %2d bytes \n", sizeof(long int ));

printf("long int * is %2d bytes \n", sizeof(long int *));

printf("signed int is %2d bytes \n", sizeof(signed int ));

printf("unsigned int is %2d bytes \n", sizeof(unsigned int ));

printf("\n");

printf("float is %2d bytes \n", sizeof(float ));

printf(" float * is %2d bytes \n", sizeof(float *));

printf("double is %2d bytes \n", sizeof(double));

printf("double * is %2d bytes \n", sizeof(double *));

printf("long double is %2d bytes \n", sizeof(long double));

printf("\n");

printf("signed char is %2d bytes \n", sizeof(signed char));

printf("char is %2d bytes \n", sizeof(char));

printf("char * is %2d bytes \n", sizeof(char *));

printf("unsigned char is %2d bytes \n", sizeof(unsigned char));

}
Program to solve Quadratic Equation

Program to solve Quadratic Equation

#include<stdio.h>

#include<math.h>

int main()
{
  float a,b,c;
  float d,root1,root2;  

  printf("Enter a, b and c of quadratic equation: ");
  scanf("%f%f%f",&a,&b,&c);
   
  d = b * b - 4 * a * c;
  
  if(d < 0){
    printf("Roots are complex number.\n");
    printf("Roots of quadratic equation are: ");
    printf("%.3f%+.3fi",-b/(2*a),sqrt(-d)/(2*a));
    printf(", %.3f%+.3fi",-b/(2*a),-sqrt(-d)/(2*a));
  
    return 0; 
  }
  else if(d==0){
   printf("Both roots are equal.\n");
   root1 = -b /(2* a);
   printf("Root of quadratic equation is: %.3f ",root1);

   return 0;
  }
  else{
   printf("Roots are real numbers.\n");
   root1 = ( -b + sqrt(d)) / (2* a);
   root2 = ( -b - sqrt(d)) / (2* a);
   printf("Roots of quadratic equation are: %.3f , %.3f",root1,root2);
  }

  return 0;
}
Program to print Mean, Variance and Standard Deviation

Program to print Mean, Variance and Standard Deviation

#include <stdio.h>

#include <conio.h>
#include <math.h>
#define MAXSIZE 10

void main()
{
float x[MAXSIZE];
int   i, n;
float avrg, var, SD, sum=0, sum1=0;

clrscr();

printf("Enter the value of N\n");
scanf("%d", &n);

printf("Enter %d real numbers\n",n);
for(i=0; i<n; i++)
{
  scanf("%f", &x[i]);
}

/* Compute the sum of all elements */

for(i=0; i<n; i++)
{
  sum = sum + x[i];
}
avrg = sum /(float ) n;

/* Compute  variance  and standard deviation  */

for(i=0; i<n; i++)
{
  sum1 = sum1 + pow((x[i] - avrg),2);
}
var = sum1 / (float ) n;
SD = sqrt(var);

printf("Average of all elements  = %.2f\n", avrg);
printf("Variance of all elements = %.2f\n", var);
printf("Standard deviation       = %.2f\n", SD);
}  /*End of main()*/
Program to find the sum of given integer

Program to find the sum of given integer

#include<stdio.h>

void main()
{
long num, temp, digit, sum = 0;
printf("Enter the number\n");
scanf("%ld", &num);
temp = num;
while(num > 0)
{
  digit = num % 10;
  sum  = sum + digit;
  num /= 10;
}
printf("Given number =%ld\n", temp);
printf("Sum of the digits %ld =%ld\n", temp, sum);
}

OUTPUT:


Enter the number 235
Given number = 235
Sum of the digits 235=10
Program to understand the Arithmetic Operators

Program to understand the Arithmetic Operators

#include<stdio.h>
int main()

{

int i;

i = 5;


printf("The Value of i is : %d", i);

i = i  + 5;


printf("\nThe Value of i is : %d", i);

i = i - 2;


printf("\nThe Value of i is : %d", i);

i = i  * 2;


printf("\nThe Value of i is : %d", i);

i = i / 4;


printf("\nThe Value of i is : %d", i);

i++;


printf("\nThe Value of i is : %d", i);

i++;


printf("\nThe Value of i is : %d", i);

i --;


printf("\nThe Value of i is : %d", i);

getchar();
return (0) ;
}