Posts

Program to find square of a number.

Program to find square of a number. #include <stdio.h> #include <conio.h> void main() { int a, b; clrscr(); printf ("Enter any number to find its square: "); scanf ("%d", &a); b = a * a; printf ("Square of %d is %d", a, b); getch(); }

What is Character set

Image
What is Character set A Character denotes any alphabets, digits and special symbols used to represent information  for Example alphabets A,B...Y,Z Or a,b...y,z Digits 0,1,2,3,4,5,6,7,8,9 Special symbols `~ !@#$%^&*()_+-=}{|":<>?/.,;'\][  Constants, variables and keywords The alphabets, digits and special symbols when properly combined from constants, variable and keywords. A constants is an entity that doesn't change, whereas, a variable is an entity that may change. A keyword is a word that carries special meaning. In any C program, we typically do lots of calculations. The result of these calculation are store in memory of computer, Like human memory, the memory of computer also consists of millions of cell. The calculated value are store in the brain. That way computer are calculation store in memory ( as hard disk etc). Since the value stored in each locations may change. In programming language, constants are often called literals, whe...

What is C

Image
 Learn Programming C  Now See First Topic- Getting Started What is C? C is a programming language developed AT Bell laboratories of USA in 1972. It was designed and written by Dennis Ritchie. C become popular because it is reliable, simple and technologies emerge and really good.  An opinion that is that is often heard today is " C has been already superseded by language like C, C# or Java. There are several reasons for this. There are as follows:- C++, C# or Java make use of a principle called object oriented programming (OOP) to organize the program,You would still need a good hold over the language elements of C and the basic programming skills. So it make more sense to first learn C and then migrate to C++, C#, Java . Though this two-step learning process may take more time, but at the end of it, you will definitely find it worth the trouble. Major part of popular operating systems like Window, Linux, UNIX, etc. and android are written in C. moreover, if one is t...

Program to find the length of the string entered by user

Program to find the length of the string entered by user #include <stdio.h> #include <conio.h> void main() { int i= 0; char ch, str[20]; clrscr(); printf ("Enter the string: "); gets(str); ch=str[0]; while (ch!='0') { i++; ch= str[i]; } printf ("Length is %d", i); getch(); }

Program to insert a user-defined element at specific location

Program to insert a user-defined element at specific location #include <stdio.h> #include <conio.h> void main() { int A[10], i, num, pos, n; clrscr(); printf ("Enter the number of elements: "); scanf ("%d", &n); printf ("Enter the data: "); for ( i=0; i<n; i++) { scanf ("%d", &A[i]); } printf ("Enter the new element value and it's position: "); scanf ("%d%d", &num, &pos); for ( i=n; i>pos; i- -) { A[i+1]=A[i]; } A[pos]=num; printf ("New array is: \n"); for (i=0;i<n+1;i++) { printf ("%d\t", A[i]); } getch(); }

Program to arrange the elements of an array using Bubble Sort

Program to arrange the elements of an array using Bubble Sort #include <stdio.h> #include <conio.h> void main() { int A[10], i, j, n, temp; clrscr(); printf ("Enter the number of elements: "); scanf ("%d", &n); printf ("Enter the data: "); for ( i=0; i<n; i++ ) { scanf ("%d", &A[i]); } for ( i=0; i<n; i++ ) { for ( j=0; j<n-i; j++ ) { if ( A[j] > A[j+1]) { temp = A[j]; A[j] = A[j+1]; A[j+1]=temp; } } } printf ("Sorted Array is "); //Sorted in Ascending Order for ( i=0; i<n; i++ ) { printf ("%d\t", A[i]); } getch(); }

Program to declare a user defined array and print the sum of odd and even numbers

Program to declare a user defined array and print the sum of odd and even numbers. #include <stdio.h> #include <conio.h> void main() { int a[10], i, sume=0, sumo= 0, n; clrscr(); printf ("Enter the size of an array: "); scanf ("%d", &n); if (n<=10) { printf ("Enter the array data: "); for (i=0;i<n;i++) { scanf ("%d", &a[i]); } for (i=0;i<n;i++) { if (a[i]%2==0) sume = sume + a[i]; else sumo = sumo + a[i]; } printf ("Sum of odd number = %d and sum of even number = %d", sumo, sume); } else printf ("\nSize is too large."); getch(); }

Program to print the sum of each row and each column of a matrix separately

Program to print the sum of each row and each column of a matrix separately #include <stdio.h> #include <conio.h> # define SIZE 3 void main() { int A[SIZE][SIZE]; int row, col, sum = 0; /* Input elements in matrix from user */ printf ("Enter elements in matrix of size %dx%d: \n", SIZE, SIZE); for (row=0; row<SIZE; row++) { for (col=0; col<SIZE; col++) { scanf ("%d", &A[row][col]); } } /* Calculate sum of elements of each row of matrix */ for (row=0; row<SIZE; row++) { sum = 0; for (col=0; col<SIZE; col++) { sum += A[row][col]; } printf ("Sum of elements of Row %d = %d\n", row+1, sum); } /* Find sum of elements of each columns of matrix */ for (row=0; row<SIZE; row++) { sum = 0; for (col=0; col<SIZE; col++) { sum += A[col][row]; } printf ("Sum of elements of Column %d = %d\n", row+1, sum); } getch(); }

Program to input two matrices and store their product in another third array

Program to input two matrices and store their product in another third array #include<stdio.h> #include<conio.h> void main() { int i, j, k, a[3][3], b[3][3], c[3][3]; clrscr(); printf ("Enter the elements of 1st array .\n"); for (i=1;i<=3;i++) { for (j=1;j<=3;j++) { scanf ("%d", &a[i][j]); } } printf ("Elements of 1st array are: \n"); for (i=1;i<=3;i++) { for (j=1;j<=3;j++) { printf ("%d\t", a[i][j]); } printf ("\n"); } printf ("Enter the elements of 2nd array .\n"); for (i=1;i<=3;i++) { for (j=1;j<=3;j++) { scanf ("%d", &b[i][j]); } } printf ("Elements of 2nd array are: \n"); for (i=1;i<=3;i++) { for (j=1;j<=3;j++) { printf ("%d\t", b[i][j]); } printf ("\n"); } printf ("The product of both the matrices are: \n"); for (i=1;i<...

Program to find the largest and smallest element of a 1D array

Program to find the largest and smallest element of a 1D array #include <stdio.h> #include <conio.h> void main() { int arr[10], i, max, min, a; clrscr(); printf ("Enter the number of the elements of an array: "); scanf ("%d", &a); printf ("Enter %d elements of the array: ", a); for ( i=0; i<a; i++ ) { scanf ("%d", &arr[i]); } max = arr[0]; min = arr[0]; for ( i=1; i<a; i++ ) { if ( arr[i]>max ) { max = arr[i]; } if ( arr[i]<min ) { min = arr[i]; } } printf ("Largest element is %d\n", max); printf ("Smallest element is %d", min); getch(); }

Program to access and print an array of 5 elements.

Program to access and print an array of 5 elements. #include <stdio.h> #include <conio.h> void main() { int num[5], a; clrscr(); printf ("Enter the elements: \n"); for ( a=0;a<5;a++ ) { scanf ("%d", &num[a]); } printf ("The elements are: \n"); for (a=0;a<5;a++) { printf ("%d\t", numb[a]); } getch(); }

Program to return a value from user-defined function.

Program to return a value from user-defined function. #include <stdio.h> #include <conio.h> int sum (); void main() { int a, b, c; clrscr(); printf ("Enter two integer values to add: "); scanf ("%d%d", &a, &b); c = sum (a, b); printf ("The addition is: %d", c); getch(); } int sum (int x, int y) { int add; add = x + y; return add; }

Program to implement break statement.

Program to implement break statement.  #include <stdio.h> #include <conio.h> int main() { int i; double number, sum = 0.0; for (i=1; i <= 10; ++i) { printf ("Enter a n%d: ", i); scanf ("%lf", &number); // If user enters negative number, loop is terminated if (number < 0.0) { break; } sum += number; // sum = sum + number; } printf ("Sum = %.2lf", sum); return 0; } 

Program to find predecessor & successor of a number.

Program to find predecessor & successor of a number. #include <stdio.h> #include <conio.h> void main() { int a, b, c; clrscr(); printf ("Enter a number to find it's predecessor & successor: \n"); scanf (%d, &a); b = a + 1; printf ("The successor of %d is: %d\n", a, b); c = a - 1; printf ("The predecessor of %d is: %d\n", a, c); getch(); }

Program to print following pattern:- * ** *** **** *****

Program to print following pattern:-        *      **    ***   ****  ***** #include <stdio.h> #include <conio.h> void main() { int i, j, rows=7; printf("The pattern is below: \n"); for(i=1; i<=rows; i++) { for(j=i; j<rows; j++) { printf(" "); } for(j=1; j<=i; j++) { printf("*"); } printf("\n"); } getch(); }

Program to print the following pattern:- * *** ***** ******* ********* *********** *************

Program to print the following pattern:-           * ***       *****     *******           *********                 ***********                       ************* #include <stdio.h> #include <conio.h> void main() { int a, b, rows= 7, k=0; clrscr(); printf("The pattern is below: \n"); for ( a=1; a<=rows; ++a, k=0) { for (b=1; b<=rows-a; ++b) { printf(" "); } while (k != 2*a-1) { printf("* "); ++k; } printf("\n"); } getch(); }

Program to find area of circle.

Program to find area of circle. #include <stdio.h> #include <conio.h> void main() { float r, area, pi= 3.14; clrscr(); printf ("Enter radius of the Circle: "); scanf ("%f", &r); area = pi * r * r; printf ("Area of Circle: %f", area); getch(); }

Program to print Fibonacci Series up-to n numbers.

Program to print Fibonacci Series up-to n numbers. #include <stdio.h> #include <conio.h> void main() { int a, b, x=0, y=1, z; clrscr(); printf ("Enter the number of terms for Fibonacci Series: "); scanf ("%d", &a); printf ("\nFibonacci Series is: "); for (b = 1; b <= a; ++b) { printf ("%d\t", x); z = x + y; x = y; y = z; } getch(); }

Program to find cube of a number.

Program to find cube of a number. #include <stdio.h> #include <conio.h> void main() { int a, b; clrscr(); printf ("Enter any number to find its cube: "); scanf ("%d", &a); b = a * a * a; printf ("Cube of %d is %d", a, b); getch(); }

Program to find square of a number.

Program to find square of a number. #include <stdio.h> #include <conio.h> void main() { int a, b; clrscr(); printf ("Enter any number to find its square: "); scanf ("%d", &a); b = a * a; printf ("Square of %d is %d", a, b); getch(); }