Skip to main content

Posts

C Programming

   C Programming A successor to the programming language B, C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to construct utilities running on Unix. It was applied to re-implementing the kernel of the Unix operating system.[6] During the 1980s, C gradually gained popularity. It has become one of the most widely used programming languages,[7][8] with C compilers from various vendors available for the majority of existing computer architectures and operating systems. C has been standardized by ANSI since 1989 (ANSI C) and by the International Organization for Standardization (ISO). C is an imperative procedural language. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support. Despite its low-level capabilities, the language was designed to encourage cross-platform programming. A standards-compliant C program written with portability ...
Recent posts

Program to find f(x) by Lagrange's interpolation method.

Program to find f(x) by Lagrange's interpolation method. CODE 👇 #include<stdio.h> #include<conio.h> void main() {     float x[10], y[10], temp = 1, f[10], sum, p;     int i, n, j, k = 0, c;     printf("How many record you will enter : ");     scanf("%d", &n);     for (i = 0; i < n; i++)     {         printf("\n\nenter the value of x%d: ", i);         scanf("%f", &x[i]);         printf("\n\nEnter the value of f(x%d): ", i);         scanf("%f", &y[i]);     }     printf("\n\nEnter X for finding f(x): ");     scanf("%f", &p);     for (i = 0; i < n; i++)     {         temp = 1;         k = i;         for (j = 0; j < n; j++)         {             if (k == j) ...

Program for Newton Raphson General.

  Program for Newton Raphson General. CODE 👇 #include<stdio.h> #include<math.h> int user_power, i = 0, cnt = 0, flag = 0; int coef[10] = {0}; float x1 = 0, x2 = 0, t = 0; float fx1 = 0, fdx1 = 0; int main() {     printf("PROGRAM FOR NEWTON RAPHSON GENERAL");     printf("\nEnter the total no. of power : ");     scanf("%d", &user_power);     for (i = 0; i <= user_power; i++)     {         printf("\nx^%d : ", i);         scanf("%d", &coef[i]);     }     printf("\n");     printf("\n\nThe Polynomial is ");     //printing coeff.     for (i = user_power; i >= 0; i--)     {         printf("%dx^%d", coef[i], i);     }     printf("\n\nIntial x1 -> ");     scanf("%f", &x1);     printf("Iteration\tX1\tFX1\tF'X1");     do     {   ...

Program to accept a number and print the factors of that number.

Program to accept a number and print the factors of that number. CODE 👇 #include<stdio.h> #include<conio.h> void main() {     int n, i;     printf("Enter a number : ");     scanf("%d", &n);     printf("Factors of %d are : ", n);     for (i = 1; i <= n; ++i)     {         if (n % i == 0)             printf("\n%d ", i);     } } 👉Execute👈 //OUTPUT

Program to calculate HCF & LCM.

  Program to calculate HCF & LCM. #include<stdio.h> #include<conio.h> void main() {     int a, b, x, y, t, hcf, lcm;     printf("Enter two numbers : ");     scanf("%d%d", &x, &y);     a = x;     b = y;     while (b != 0)     {         t = b;         b = a % b;         a = t;     }     hcf = a;     lcm = (x * y) / hcf;     printf("\nHighest Common Factor of %d and %d : %d", x, y, hcf);     printf("\nLeast Common Multiple of %d and %d : %d", x, y, lcm); } 👉Execute👈 //OUTPUT /* */

Program to accept two integer numbers and print the GCD(Greatest Common Divisor).

  Program to accept two integer numbers and print the GCD(Greatest Common Divisor). CODE 👇 #include<stdio.h> #include<conio.h> void main() {     int x, y, m, i;     printf("Enter 1st number : ");     scanf("%d", &x);     printf("Enter 2nd number : ");     scanf("%d", &y);     if (x > y)         m = y;     else         m = x;     for (i = m; i >= 1; i--)     {         if (x % i == 0 && y % i == 0)         {             printf("GCD of two number is : %d", i);             break;         }     } } 👉Excute👈 //OUTPUT                                                    ...

Program to find day on a particular date

Program to find day on a particular date CODE 👇 #include<stdio.h> int isLeapYear(int year){     if(year%4==0){         if(year%100==0 && year%400!=0){             return 0;         }         else{             return 1;         }     }     else{         return 0;     } } int main() {     int year, i;     int refYear=1600, leap=0;     int diff, totalDays,day,month, oddDays;     int lYear[]={3,1,3,2,3,2,3,3,2,3,2,3};         int nYear[]={3,0,3,2,3,2,3,3,2,3,2,3};     char  week[7][10]={"sunday",                    "monday",                    "tuesday",               ...

Program to calculate the determinant of 2×2 matrix.

Program to calculate the determinant of 2×2 matrix. CODE 👇 #include<stdio.h> #include<conio.h> void main() {     int a[2][2], i, j;     long determinant;     printf("Enter the 4 elements of matrix  :\n");     for (i = 0; i < 2; i++)     {         for (j = 0; j < 2; j++)         {             scanf("%d", &a[i][j]);         }     }     printf("\nThe matrix is : \n");     for (i = 0; i < 2; i++)     {         printf("\n");         for (j = 0; j < 2; j++)         {             printf("%d\t", a[i][j]);         }     }     determinant = a[0][0] * a[1][1] - a[1][0] * a[0][1];     printf("\nDeterminant of 2X2 matrix: %ld", determinant); } 👉 Execu...

Program to convert Binary to Decimal to Binary.

  Program to convert Binary to Decimal CODE 👇 #include<stdio.h> #include<math.h> #include<conio.h> int binary_decimal(int n); void main() {     int n;     char c;     printf("Enter Binary number :  ");     scanf("%d", &n);     printf("%d in binary = %d in decimal", n, binary_decimal(n));     getch(); } //Function to convert binary to decimal. int binary_decimal(int n) {     int decimal = 0, i = 0, rem;     while (n != 0)     {         rem = n % 10;         n /= 10;         decimal += rem * pow(2, i);         ++i;     }     return decimal; } 👉 Execut 👈 //OUTPUT /* Enter Binary number :  10110111 10110111 in binary = 183 in decimal */ Program to convert Decimal numbers to Binary . CODE 👇 #include<stdio.h> #include<conio.h> void main() {    ...

Program to accept three numbers from user and print them in ascending and decending order.

 Program to accept three numbers from user and print them in ascending and decending order. CODE 👇 #include<stdio.h> #include<conio.h> void main() {   int a,b,c;   printf("Enter numbers:");   scanf("%d %d %d",&a,&b,&c);   if ((a>=b)&&(a>=c))    {     if (b>=c)  {       printf("\nDesc : %d %d %d",a,b,c);       printf("\nAsc : %d %d %d",c,b,a);     } else  {       printf("\nDesc : %d %d %d",a,c,b);       printf("\nAsc : %d %d %d",b,c,a);     }   } else if ((b>=a)&&(b>=c))    {      if (a>=c)  {         printf("\nDesc : %d %d %d",b,a,c);      }   } else    {     if (b>=a)  {       printf("\nDesc : %d %d %d",c,b,a);       printf("\nAsc : %d %d %d",a,b,c); ...

Add Two Matrix.

Program to add two matrix. CODE 👇 #include<stdio.h> #include<conio.h> void main() {     int m, n, c, d, first[10][10], second[10][10], sum[10][10];      printf("Enter the number of rows and columns of matrix :");     scanf("%d%d", &m, &n);     printf("\nEnter the elements of first matrix : \n");     for (c = 0; c < m; c++)     {         for (d = 0; d < n; d++)         {             scanf("%d", &first[c][d]);         }     }     printf("\nEnter the elements of second matrix : \n");     for (c = 0; c < m; c++)     {         for (d = 0; d < n; d++)         {             scanf("%d", &second[c][d]);         }     }     printf("\nSum of entered matric...

Pattern 2

 //write C program to print the following pattern /* 1    2 2    3 3 3    4 4 4 4    5 5 5 5 5 */ #include<stdio.h> int main() { int i, j, N; printf("Enter N:- "); scanf("%d", &N); for(i=1; i<=N; i++) { for(j=1; j<=i; j++) { printf("%d ", i); } printf("\n"); } return 0; }

Pattern1

 //write C program to print the following pattern. /* 1    1 2    1 2 3    1 2 3 4    1 2 3 4 5*/ #include<stdio.h> int main() { int i, j; for(j=1;j<=5;j++) { for(i=1;i<=j;i++) printf("%5d", i); printf("\n\n"); } return 0; }

//write C program to input numer from to user and find all divisors of the the given number.

 //write C program to input numer from to user and find all divisors of the the given number. #include<stdio.h> int main() { int i, num; printf("Enter any number to find its factor: "); scanf("%d", &num); printf("\nAll factor of %d are : \n", num); for(i=1; i<=num; i++) { if(num % 1 == 0) { printf("%d, ", i); } } return 0; }

Do-While Loop

 //write C program to print  the numbers from 1 to 10 using do-while loop #include<stdio.h> int main() { int i=1; do { printf("%u\t", i); i=i+1; } while(i<=10); printf("\n"); return 0; }

Accept_Two_Numbers_And_ Perform_The_Following_Operations_Till_The_User.

Accept_Two_Numbers_And_ Perform_The_Following_Operations_Till_The_User. selects Exit.  i. Maximum  ii. Display all numbers between the two  iii. Sum and average  iv. EXIT */ #include<stdio.h> #include<stdlib.h> int main()  {        int n1,n2,i,ch,sum;       float avg;         printf("\n Enter number1 : ");       scanf("%d",&n1);       printf("\n Enter number2 : ");       scanf("%d",&n2);         printf("\n Menu : \n1. Maximum");       printf("\n 2. Display all numbers between %d and %d",n1,n2);       printf("\n 3. Sum and Average of two");       printf("\n 4. Exit\n Enter your choice (1-4) : ");       scanf("%d",&ch);         switch(ch)      {         case 1: if(n1>n2)           ...

Write a ‘C’ program to accept marks of 5 subjects of a student and calculate the grade using rules

Write a ‘C’ program to accept marks of 5 subjects of a student and calculate the grade using rules: &gt; 90 grade = O between 75 and 90 grade = A between 60 and 75 grade = B between 40 and 60 grade = C &lt; 40 grade = F  # include <stdio.h> int main ( ) { int phy , chem , bio , math , comp ; float per ; /* Input marks of five subjects from user */ printf ( "Enter five subjects marks: " ) ; scanf ( "%d%d%d%d%d" , & phy , & chem , & bio , & math , & comp ) ; /* Calculate percentage */ per = ( phy + chem + bio + math + comp ) / 5.0 ; printf ( "Percentage = %.2f\n" , per ) ; /* Find grade according to the percentage */ if ( per >= 90 ) { printf ( "Grade A" ) ; } else if ( per >= 80 ) { printf ( "Grade B" ) ; } else if ( per >= 70 ) { printf ( "Grad...

Write a ‘C’ program to calculate the GCD of two numbers.

Write a ‘C’ program to calculate the GCD of two numbers.  # include <stdio.h> int main () { int n1, n2, i, gcd; printf ( "Enter two integers: " ); scanf ( "%d %d" , &n1, &n2); for (i= 1 ; i <= n1 && i <= n2; ++i) { // Checks if i is factor of both integers if (n1%i== 0 && n2%i== 0 ) gcd = i; } printf ( "G.C.D of %d and %d is %d" , n1, n2, gcd); return 0 ; }  

Given_Number_Positive_Or_Negative

 //write 'C' a program accpet given number positive or negative #include <stdio.h> void main() { int num; printf("Enter the any number:- "); scanf("%d", &num); if (num==0) {     printf("Number is zero \n"); } else if (num>0) { printf("Given number is positive number"); } else { printf("Given number is negative number"); } }

Find_The_Volume_And_Surface_Area_Of_Cylinder

 // write a program to find the volume and surface area of cylinder #include<stdio.h> #include<math.h> int main() { float radius, height; float surface_area, volume; printf("Enter value for radius and height of a cylinder: \n"); scanf("%f%f", &radius, &height); surface_area = 2 * (22/7) * radius * (radius + height); volume = (22/7) * radius * radius * height; printf("Surface area of cylinder is: %3f", surface_area); printf("\n Volume of cylinder is: %3f", volume); }

Print_The_Final_Velocity_And_The_Distance_Travelled

 //write a program to accept intial velocity, acceleration and time. print the final velocity and the distance travelled. #include<stdio.h> void main() { float u, a, t, V, S; printf("\n Enter intial velocity :"); scanf("%f", &u); printf("\n Enter acceleration :"); scanf("%f", &a); printf("\n Enter time required :"); scanf("%f", &t); V = u+a*t; S = u*t+(1/2)*a*t*t; printf("\n the final velocity is %f", V); printf("\n\n The disatance travelled is %f \n\n", S); }

Celsious_Convert_In_Fahrenheit_And_Kelvin

 //write a program to temperature celsious to convert in fahrenheit and kelvin #include<stdio.h> int main() { float Celsious, Fahrenheit, Kelvin; printf("\n Enter temperature in Celsious :"); scanf("%f", &Celsious); Fahrenheit = 1.8*Celsious+32.0; Kelvin = 273.15+Celsious; printf("%0.2f Celsious = %0.2f fahrenheit \n", Celsious, Fahrenheit); printf("%0.2f Celsious = %0.2f Kelvin \n", Celsious, Kelvin); }

Surface_Area_of_Cubiod_And_Volume

 //write a program to find the volume and surface area of cubiod. #include<stdio.h> int main() { float w, l, h; float volume, area; printf("Enter the value width, length and height of cubiod \n"); scanf("%f%f%f", &w, &l, &h); area = 2*(w*l+l*h+h*w); volume = w*l*h; printf("surface area of cubiod is %3f", area); printf("\n volume of cubiod is %3f", volume); }

Inner_And_Outer_Radius. Perimeter_of_Ring

 //write a program to accept inner and outter radius of a ring. print the perimeter, area of the ring. #include<stdio.h> int main() { float r1, r2, area , perimeter; printf("\n Enter inner radius of ring :"); scanf("%f", &r1); printf("\n Enter outer radius of ring :"); scanf("%f", &r2); perimeter = (2*3.14)*(r1+r2); area = 3.14*(r1*r1) + (r2*r2); printf("\n Perimeter of cricle is %f", perimeter); printf("\n\n Area of circle is %f", area); }

Factorial_Using_Function

 //write a 'C' program to calculate the factorial of a number using function. #include<stdio.h> void main() { int ans, n; int fact(int n); printf("Enter the number:- "); scanf("%d", &n); ans=fact(n); printf("the factorial of %d is %d",n,ans); } int fact(int n) { int res=1, i; for(i=n; i>=1; i--) res=res*i; return(res); }

Factorial

 //write a program for factorial of a number #include<stdio.h> void main() { int n, i, ans=1; printf("Enter an integer: "); scanf("%d", &n); for (i=1; i<= n; i++) { ans=ans*i; } printf("Factorial of number %d is int", ans); }

Previous_And_Next_Charcter

//write a program to accept a character from the keyboard and display its previous and next character in order. #include<stdio.h> int main() { char ch; printf("Enter character \n"); scanf("%c", &ch); printf("Previous Character %c \n", ch-1); printf("Next Character %c \n", ch+1); }

ASCII

 //C program to print ASCII of any Character. #include<stdio.h> int main() { char c; printf("Enter any charater: "); scanf("%c", &c); printf("ASCII value of %c = %d", c, c); return 0; }

Arithmatic_Mean_And_Harmatic_Mean

 //write a program to accept two numbers and print arithmatic mean and harmatic mean of to numbers. #include<stdio.h> int main() { int a, h; float arithmatic, harmatic; printf("Enter two number A and H :"); scanf("%d%d", &a, &h); arithmatic = (a+h)/2; harmatic = a*h/(a+h); printf("\n arithmatic mean = %f \n harmatic mean = %f", arithmatic, harmatic); }

Cube

 //write a program to find cube of given number #include<stdio.h> int main() { float n, cuber; printf("Enter the number:-"); scanf("%float" &n); cuber = n*n*n; printf("Square of the number is %f", cuber); }

Check_Given_Number_Is_Even_Odd

 ///write a program to check given number is even or odd #include<stdio.h> void main() { int n; printf("\n enter the number :- "); scanf("%d",&n); if (n%2 == 0) printf("\n number is even %d", n); else printf("\n number is odd %d", n); }

Area_Of_Circle

 //write a program to find area of circle #include<stdio.h> void main() { float r, area; printf("Enter the radius:- "); scanf("%f", &r); area = 3.14*r*r; printf("Area of circle is %f", area); }