sailcpu / cprogrammingcurriculum Goto Github PK
View Code? Open in Web Editor NEWC Programming Curriculum
C Programming Curriculum
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
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
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
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"
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
Up:1
Down:2
Right:3
Left:4
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
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
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:)
所添加的数为2或4,随机出现。
void addElementRandom();
int matrix[16];
int score;
int maxNumber;
int line[4];
void display();
void clear();
void update();
void addElementRandom();
void compress();
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
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
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
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
Output:
Enter three numbers: -4.5
3.9
5.6
5.60 is the largest number.
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
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
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
This program asks user to enter a string and computes the length of string manually using for loop.
Output
Enter a string: Programiz
Length of string: 9
2 4 2 2 -> 0 2 4 4
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
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
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
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,
函数接口为:void clear();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.