Giter Site home page Giter Site logo

cprogrammingcurriculum's People

Contributors

fanmover avatar humover avatar sailcpu avatar

Watchers

 avatar  avatar  avatar

cprogrammingcurriculum's Issues

C Program to Calculate Standard Deviation

This program calculates the standard deviation of a individual series using arrays. Visit this page to learn about Standard Deviation.

To calculate the standard deviation, calculateSD() function is created. The array containing 10 elements is passed to the function and this function calculates the standard deviation and returns it to the main() function.

Output

Enter 10 elements: 1
2
3
4
5
6
7
8
9
10

Standard Deviation = 2.872281

C Program to Sort Elements in Lexicographical Order (Dictionary Order)

This program takes 10 words(strings) from the user and sorts them in lexicographical order.

To solve this program, a two-dimensional string str is created.

This string can hold maximum of 10 strings and each string can have maximum of 50 characters (including null character).

To compare two strings, strcmp() function is used. Also, we used strcpy() function to copy string to a temporary string temp.

Output

Enter 10 words:
C
C++
Java
PHP
Python
Perl
Ruby
R
JavaScript
PHP

In lexicographical order:
C
C++
Java
JavaScript
PHP
PHP
Perl
Python
R
Ruby

C program to count the number of vowels, consonants and so on

This program takes string input from the user and stores in variable line.

Initially, the variables vowels, consonants, digits and spaces are initialized to 0.

When the vowel character is found, vowel variable is incremented by 1. Similarly, consonants, digits and spaces are incremented when these characters are found.

Finally, the count is displayed on the screen.

Output

Enter a line of string: adfslkj34 34lkj343 34lk
Vowels: 1
Consonants: 11
Digits: 9
White spaces: 2

C Program to Add Two Distances (in inch-feet) System Using Structures

To understand this example, you should have the knowledge of following C programming topics:
In this program, a structure Distance is defined. The structure has two members inch (a float) and feet (an integer).

Two variables (d1 and d2) are created which stores two distances (in inch and feet). Then, the sum of two distances is stored in sumOfDistances structure and displayed on the screen.
Output

Enter information for 1st distance
Enter feet: 23
Enter inch: 8.6

Enter information for 2nd distance
Enter feet: 34
Enter inch: 2.4

Sum of distances = 57'-11.0"

C Program to Calculate Difference Between Two Time Periods

In this program, user is asked to enter two time periods and these two periods are stored in structure variables startTime and stopTime respectively.

Then, the function differenceBetweenTimePeriod calculates the difference between the time periods and the result is displayed in main() function without returning it (Using call by reference technique).

Output

Enter start time:
Enter hours, minutes and seconds respectively: 12
34
55
Enter stop time:
Enter hours, minutes and seconds respectively:8
12
15

TIME DIFFERENCE: 12:34:55 - 8:12:15 = 4:22:40

C Program to Add Two Complex Numbers by Passing Structure to a Function

To understand this example, you should have the knowledge of following C programming topics:
In this program, structures n1 and n2 are passed as an argument of function add().

This function computes the sum and returns the structure variable temp to the main() function.

Output

For 1st complex number
Enter real and imaginary part respectively: 2.3
4.5

For 2nd complex number
Enter real and imaginary part respectively: 3.4
5
Sum = 5.7 + 9.5i

Program to Check Whether a Character is Vowel or Consonant

image
The five alphabets A, E, I, O and U are called vowels. All other alphabets except these 5 vowel letters are called consonants.

This program assumes that the user will always enter an alphabet character.

Output

Enter an alphabet: G
G is a consonant.

C Program to Find Transpose of a Matrix

In this program, user is asked to entered the number of rows r and columns c. The value of r and c should be less than 10 in this program.

The user is asked to enter elements of the matrix (of order r*c).

Then, the program computes the transpose of the matrix and displays it on the screen.

Output

Enter rows and columns of matrix: 2
3

Enter element of matrix:
Enter element a11: 2
Enter element a12: 3
Enter element a13: 4
Enter element a21: 5
Enter element a22: 6
Enter element a23: 4

Entered Matrix:
2 3 4

5 6 4

Transpose of Matrix:
2 5

3 6

4 4

C Program to Concatenate Two Strings

You can concatenate two strings easily using standard library function strcat() but, this program concatenates two strings manually without using strcat() function.

Output

Enter first string: lol
Enter second string: :)
After concatenation: lol:)

构建2048程序框架

int matrix[16];
int score;
int maxNumber;
int line[4];
void display();
void clear();
void update();
void addElementRandom();
void compress();

Program to Check Whether a Number is Even or Odd

image
An even number is an integer that is exactly divisible by 2. Example: 0, 8, -24

An odd number is an integer that is not exactly divisible by 2. Example: 1, 7, -11, 15

Output

Enter an integer: -7
-7 is odd.

C Program to Add Two Matrix Using Multi-dimensional Arrays

In this program, user is asked to entered the number of rows r and columns c. The value of r and c should be less than 100 in this program.

The user is asked to enter elements of two matrices (of order r*c).

Then, the program adds these two matrices, saves it in another matrix (two-dimensional array) and displays it on the screen.

Output

Enter number of rows (between 1 and 100): 2
Enter number of columns (between 1 and 100): 3

Enter elements of 1st matrix:
Enter element a11: 2
Enter element a12: 3
Enter element a13: 4
Enter element a21: 5
Enter element a22: 2
Enter element a23: 3
Enter elements of 2nd matrix:
Enter element a11: -4
Enter element a12: 5
Enter element a13: 3
Enter element a21: 5
Enter element a22: 6
Enter element a23: 3

Sum of two matrix is:

-2 8 7

10 8 6

Program to Print ASCII Value

image
In C programming, a character variable holds ASCII value (an integer number between 0 an 127) rather than character itself. You will learn how to find ASCII value of a character in this program.

For example, ASCII value of 'A' is 65.

Output

Enter a character: G
ASCII value of G = 71

C Program to Access Elements of an Array Using Pointer

In this program, the elements are stored in the integer array data.

Then, using the for loop, each element in data is traversed and print using the pointer method.

Output

Enter elements: 1
2
3
5
4
You entered:
1
2
3
5
4

C Program to Multiply to Matrix Using Multi-dimensional Arrays

To multiply two matrices, the number of columns of first matrix should be equal to the number of rows to second matrix. This program displays the error until the number of columns of first matrix is equal to the number of rows of second matrix.
Output

Enter rows and column for first matrix: 3
2
Enter rows and column for second matrix: 3
2
Error! column of first matrix not equal to row of second.

Enter rows and column for first matrix: 2
3
Enter rows and column for second matrix: 3
2

Enter elements of matrix 1:
Enter elements a11: 3
Enter elements a12: -2
Enter elements a13: 5
Enter elements a21: 3
Enter elements a22: 0
Enter elements a23: 4

Enter elements of matrix 2:
Enter elements b11: 2
Enter elements b12: 3
Enter elements b21: -9
Enter elements b22: 0
Enter elements b31: 0
Enter elements b32: 4

Output Matrix:
24 29

6 25

C Program to Remove all Characters in a String Except Alphabet

This program takes a string from the user and stored in the variable line.

The, within the for loop, each character in the string is checked if it's an alphabet or not.

If any character inside a string is not a alphabet, all characters after it including the null character is shifted by 1 position to the left.

Output

Enter a string: p2'r-o@gram84iz./
Output String: programiz

Program to Find the Size of int, float, double and char

image
Q:declares 4 variables of type int, float, double and char. Then, the size of each variable is evaluated using sizeof operator.

Output

Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte

Program to Find LCM of two Numbers

image

The LCM of two integers n1 and n2 is the smallest positive integer that is perfectly divisible by both n1 and n2 (without a remainder). For example: the LCM of 72 and 120 is 360.

Output

Enter two positive integers: 72
120
The LCM of 72 and 120 is 360.

C Program Swap Numbers in Cyclic Order Using Call by Reference

Three variables entered by the user are stored in variables a, b and c respectively.

Then, these variables are passed to the function cyclicSwap(). Instead of passing the actual variables, addresses of these variables are passed.

When these variables are swapped in cyclic order in the cyclicSwap() function, variables a, b and c in the main function are also automatically swapped.

Output

Enter a, b and c respectively: 1
2
3
Value before swapping:
a = 1
b = 2
c = 3
Value after swapping:
a = 3
b = 1
c = 2

C Program to Copy String Without Using strcpy()

You can use the strcpy() function to copy the content of one string to another but, this program copies the content of one string to another manually without using strcpy() function.

Output

Enter String s1: programiz
String s2: programiz

C Program to Find the Frequency of Characters in a String

In this program, the string entered by the user is stored in variable str.

Then, the user is asked to enter the character whose frequency is to be found. This is stored in variable ch.

Now, using the for loop, each character in the string is checked for the entered character.

If, the character is found, the frequency is increased. If not, the loop continues.

Finally, the frequency is printed.

Output

Enter a string: This website is awesome.
Enter a character to find the frequency: e
Frequency of e = 4

Program to Find GCD of two Numbers

image

The HCF or GCD of two integers is the largest integer that can exactly divide both numbers (without a remainder).

Output:
Enter two positive integers: 81
153
GCD = 9

Program to Find Factorial of a Number

image

The factorial of a positive number n is given by:

factorial of n (n!) = 123*4....n

The factorial of a negative number doesn't exist. And, the factorial of 0 is 1, 0! = 1

Output

Enter an integer: 10
Factorial of 10 = 3628800

C Program to Store Information(name, roll and marks) of a Student Using Structure

In this program, a structure, student is created.

This structure has three members: name (string), roll (integer) and marks (float).

Then, a structure variable s is created to store information and display it on the screen.

Output

Enter information:
Enter name: Jack
Enter roll number: 23
Enter marks: 34.5
Displaying Information:
Name: Jack
Roll number: 23
Marks: 34.5

Program to Swap Two Numbers

image

Output

Enter first number: 1.20
Enter second number: 2.45

After swapping, firstNumber = 2.45
After swapping, secondNumber = 1.20

C Program to Find Largest Number Using Dynamic Memory Allocation

Depending upon the number of elements, the required size is allocated which prevents the wastage of memory. If no memory is allocated, error is displayed and the program is terminated.

Output

Enter total number of elements(1 to 100): 10

Enter Number 1: 2.34
Enter Number 2: 3.43
Enter Number 3: 6.78
Enter Number 4: 2.45
Enter Number 5: 7.64
Enter Number 6: 9.05
Enter Number 7: -3.45
Enter Number 8: -9.99
Enter Number 9: 5.67
Enter Number 10: 34.95
Largest element: 34.95

C Program to Multiply two Matrices by Passing Matrix to a Function

This program asks the user to enter the size of the matrix (rows and column).

Then, it asks the user to enter the elements of those matrices and finally adds and displays the result.

To perform this task three functions are made:

To takes matrix elements from user enterData()
To multiply two matrix multiplyMatrices()
To display the resultant matrix after multiplication display()

utput

Enter rows and column for first matrix: 3
2
Enter rows and column for second matrix: 3
2
Error! column of first matrix not equal to row of second.

Enter rows and column for first matrix: 2
3
Enter rows and column for second matrix: 3
2

Enter elements of matrix 1:
Enter elements a11: 3
Enter elements a12: -2
Enter elements a13: 5
Enter elements a21: 3
Enter elements a22: 0
Enter elements a23: 4

Enter elements of matrix 2:
Enter elements b11: 2
Enter elements b12: 3
Enter elements b21: -9
Enter elements b22: 0
Enter elements b31: 0
Enter elements b32: 4

Output Matrix:
24 29

6 25

Program to Display Fibonacci Sequence

image
The Fibonacci sequence is a series where the next term is the sum of pervious two terms. The first two terms of the Fibonacci sequence is 0 followed by 1.

The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21

Visit this page to learn about Fibonacci sequence.

Output:
Enter the number of terms: 10
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34,

Program to Calculate the Sum of Natural Numbers

image

To compute the sum of natural numbers from 1 to n (entered by the user), loops can be used. You will learn how to use for loop and while loop to solve this problem.

Output

Enter a positive integer: 100
Sum = 5050

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.