Posts

Showing posts from April, 2020

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(); }

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(); }
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 find Fibonacci Series, Factorial or Multiplication Table of a number as per user's choice. #include <stdio.h> #include <conio.h> #include <stdlib.h> void fibonacci (); void factorial (); void multiplication (); void main() { int b, c; clrscr(); printf ("Enter your choice: "); printf ("\n1. Find the Fibonacci Series upto the number."); printf ("\n2. Find the Factorial of a number."); printf ("\n3. Find the Multiplication Table of a number."); printf ("\n4. Exit\n"); scanf ("%d", &b); switch (b) { case 1: fibonacci (); break; case 2: factorial (); break; case 3: multiplication (); break; case 4: exit (0); break; default: printf ("Enter the correct option."); } getch(); } void fibonacci () { int a, w, x= 0, y= 1, z; printf ("Enter a positive integer: "); scanf ("%d", &a); prin...
Program to print factors of a given number. #include <stdio.h> #include <conio.h> void main() { int a, num; clrscr(); printf ("Enter a number to find it's Factors: "); scanf ("%d", &num); printf ("Factors of the %d are: \n", num); for (a = 1; a <= num; a++) { if (num%a == 0) { printf ("%d\t", a); } } getch(); }
Program to find the greatest number between 3 numbers. #include <stdio.h> #include <conio.h> void main() { int a, b, c; clrscr(); printf ("Enter three numbers to find the greater: "); scanf ("%d%d%d", &a, &b, &c); if (a>b && a>c) { printf ("%d is the greatest number.", a); } else if (b>a && b>c) { printf ("%d is the greatest number.", b); } else if (c>a && c>b) { printf ("%d is the greatest number.", c); } else { printf ("An unknown error occurred!"); } getch(); }
Program to find the smallest number between 3 numbers. #include <stdio.h> #include <conio.h> void main() { int a, b, c; clrscr(); printf ("Enter three numbers to find the smallest: "); scanf ("%d%d%d", &a, &b, &c); if (a<b && a<c) { printf ("%d is the smallest number.", a); } else if (b<a && b<c) { printf ("%d is the smallest number.", b); } else if (c<a && c<b) { printf ("%d is the smallest number.", c); } else { printf ("An unknown error occurred!"); } getch(); }

Program to print multiplication tables from 11 to 20.

Program to print multiplication tables from 11 to 20. #include <tstdio.h> #include <tconio.h> void main() { int a, b; clrscr(); for ( a=11; a<=20; a++) { printf ("The multiplication table of %d is: \n", a); for ( b=1; b<=10; b++) { printf ("%d * %d = %d\n", a, b, a*b); } } getch(); }

All program

Image
All program 👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍 1.  Program to determine whether a person  has made profit or incurred loss. Also determine how much profit he made or loss he incurred. 2.  Program to pri nt table of 2 3.  Program to print multiplication tables from 11 to 20  4. program print 1 to 10 number .

Table Of Two👂

Image
                        Table Of Two👂 Program to print table of 2 #include <stdio.h> #include <conio.h> void main() { int num=2, r; clrscr(); printf ("The Table Of Number Two"); for (r=1;r<=10;r++) { printf ("%d * %d = %d", num, r, num*r); } getch(); } Output is ...

Program to print 1 to 10 numbers.

Program to print 1 to 10 numbers. #include <stdio.h> #include <conio.h> int main() { int i = 1; for (i = 1; i <= 10; i++) { printf ("%d", i); } return 0; } Output - 1 2 3 4 5 6 7 8 9 10

Program to calculate compound interest.

Program to calculate compound interest. #include <stdio.h> #include <conio.h> #include <math.h> void main() { int p,t; float r,amt,ci; clrscr(); printf ("Enter Principal Amount: "); scanf ("%d",&p); printf ("Enter Time: "); scanf ("%d",&t); printf ("Enter Rate of interest: "); scanf ("%f",&r); amt= p*pow((1+r/100),t); ci = amt-p; printf ("Simple interest: %7.2f ",ci); printf ("Total amount: %7.2f ",amt); getch(); }

Program to reverse a number using do-while loop.

Program to reverse a number using do-while loop. #include <stdio.h> #include <conio.h> void main() { int i, b=0, a=0; clrscr(); printf ("Enter a number: "); scanf ("%d", &i); printf ("The reverse is: "); do { a = i%10; b = i/10; i = b; printf ("%d", a); } while (i>0); getch(); }

Program to count number of digits using do-while loop.

Program to count number of digits using do-while loop. #include <stdio.h> #include <conio.h> void main() { int i, b=0, c=0; clrscr(); printf ("Enter a no: "); scanf ("%d", &i); do { b = i/10; i = b; c++; } while (i>0); { printf ("The no. of digits are: %d",c); } getch(); }

Program to find 5 subject marks and calculate percentage and division of student using nested else-if and logical operators.

Program to find 5 subject marks and calculate percentage and division of student using nested else-if and logical operators. #include <stdio.h> #include <conio.h> void main() { int a, b, c, d, e, sum, total = 100; float perc; clrscr(); printf ("Enter your marks of 5 subjects: \n"); scanf ("%d%d%d%d%d", &a, &b, &c, &d, &e); sum = a + b + c + d + e; perc = (sum*100)/total; printf ("The percentage of your marks is: %d \n", perc); if (total>=80) printf ("You've got 1st Division."); else if (total>=60) printf ("You've got 2nd Division."); else if (total>=40) printf ("You've got 3rd Division."); else printf ("You are FAIL!"); getch(); }

Program to find 5 subject marks and calculate percentage and division of student using if-else ladder.

Program to find 5 subject marks and calculate percentage and division of student using if-else ladder. #include <stdio.h> #include <conio.h> void main() { int a, b, c, d, e, sum, total = 100; float perc; clrscr(); printf ("Enter marks of 5 subjects: "); scanf ("%d%d%d%d%d", &a, &b, &c, &d, &e); sum = a + b + c + d + e ; perc = ((sum*100)/total); if (perc < 40) printf ("You are FAIL!"); else { if (perc >= 60) printf ("You have got 1st Division."); else { if (perc >= 50) printf ("You have got 2nd Division."); else printf ("You have got 3rd Division."); } } getch(); }

Program to determine whether a person has made profit or incurred loss. Also determine how much profit he made or loss he incurred.

Program to determine whether a person has made profit or incurred loss. Also determine how much profit he made or loss he incurred. #include <stdio.h> #include <conio.h> void main() { int cp, sp, profit, loss; printf ("Enter Selling Price and Cost Price"); scanf ("%d%d", &cp, &sp); if ( cp > sp ) { loss = cp - sp; printf ("Loss is of %d", loss); } else { profit = sp - cp; printf ("Profit is of %d", profit); } getch(); }

let c program

Image
                  (a) Ramesh's basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary. #include<stdio.h> float BASI , DA, HRA, GS ; void main() {     clrscr();     printf("Enter BASIC salary: ");     scanf("%f",&BASIC);     DA = BASIC*0.4;     HRA = BASIC*0.2;     GS = BASIC + DA + HRA;     printf("\nGross Salary = %f",GS); } —————————————————————————————————————————————————— (b) The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters. #include<stdio.h> float dist,meter,cm,feet,inch,mile,yard,nm; void main() {     clrscr();     printf("\n...