10 Most Important C Programs for NEB +2 Students
This is my final project report for practical class 12
Table Content
|
S.N. |
Title of Lab Work |
Click to Jump |
|
1 |
Program to get three inputs from the user and then print the greatest number among them. |
|
|
2 |
Program to check whether the given word is palindrome or not. |
|
|
3 |
Program to print Fibonacci series up to the 10th term starting from 1, 1, 2,… 10th term using a user-defined function. |
|
|
4 |
Program to count the vowels and consonants in a given word using a function (passing arguments). |
|
|
5 |
Program to enter 20 employees’ names, ages, and salaries using a structure and print them. |
|
|
6 |
Program to input 300 students’ details (Name, Age, Gender, GPA) and print the list of students with GPA greater than 2.5 and less than 3.00. |
|
|
7 |
Program to get the sum of 3 different numbers using pointers. |
|
|
8 |
Program to swap two integers using pointers. |
|
|
9 |
Program to read the content from the file named “content.txt” and add additional content of students (name, section, roll number) in it. |
|
|
10 |
Program to enter names and addresses of the students and store them in a data file “student.dat”. |
OBJECTIVES
- To introduce students to the basic knowledge of programming fundamentals of C language.
- To impart writing skill of C programming to the students and solving problems.
- To impart the concepts like looping, array, functions, pointers, file, structure.
COURSE OUTCOME
After completing this lab course you will be able to:
- Understand the logic for a given problem.
- Write the algorithm of a given problem.
- Draw a flow chart of a given problem.
- Recognize and understand the syntax and construction.
- Gain experience of procedural language programming.
- Know the steps involved in compiling, linking and debugging C code.
- Understand using header files.
- Learn the methods of iteration or looping and branching.
- Make use of different data-structures like arrays, pointers, structures and files.
- Understand how to access and use library functions.
- Understand function declaration and definition.
- Understand proper use of user defined functions.
- Write programs to print output on the screen as well as in the files.
- Apply all the concepts that have been covered in the theory course.
- Know the alternative ways of providing solutions to a given problem.
Program to get three inputs from the user and then print the greatest number among them
Objective(s):
To find the greatest number among three inputs provided by the user.
Program:
Program to get three inputs from the user and then print the greatest number among them.
Algorithm:
- Start
- Declare three variables (num1, num2, num3) to store the user inputs.
- Display a message prompting the user to enter three numbers.
- Read the three numbers from the user and store them in num1, num2, and num3.
- Compare num1 with num2 and num3 to find the greatest number.
- Display the greatest number.
- End
Code:
#include <stdio.h>
int main() {
int num1, num2, num3;
printf(“Enter three numbers: “);
scanf(“%d %d %d”, &num1, &num2, &num3);
if (num1 >= num2 && num1 >= num3)
printf(“Greatest number: %dn”, num1);
else if (num2 >= num1 && num2 >= num3)
printf(“Greatest number: %dn”, num2);
else
printf(“Greatest number: %dn”, num3);
return 0;
}
Output:
Enter three numbers: 5 10 3
Greatest number: 10
Flowchart:
Program to check whether the given word is palindrome or not
Objective(s):
To determine whether a given word is a palindrome or not.
Program:
Program to check whether the given word is palindrome or not.
Algorithm:
- Start
- Declare a character array to store the input word.
- Display a message prompting the user to enter a word.
- Read the input word from the user and store it in the character array.
- Check if the word is a palindrome.
- Display the result.
- End
Code:
#include <stdio.h>
#include <string.h>
int main() {
char word[100];
int i, length;
int isPalindrome = 1;
printf(“Enter a word: “);
scanf(“%s”, word);
length = strlen(word);
for (i = 0; i < length / 2; i++) {
if (word[i] != word[length – i – 1]) {
isPalindrome = 0;
break;
}
}
if (isPalindrome)
printf(“%s is a palindrome.n”, word);
else
printf(“%s is not a palindrome.n”, word);
return 0;
}
Output:
Enter a word: radar
radar is a palindrome.
Flowchart:
Program to print Fibonacci series up to the 10th term using a user-defined function
Objective(s):
To generate and print the Fibonacci series up to the 10th term.
Program:
Program to print Fibonacci series up to the 10th term using a user-defined function.
Algorithm:
- Start
- Define a function to calculate the nth term of the Fibonacci series.
- Iterate from 1 to 10 and print the Fibonacci series terms using the defined function.
- End
Code:
#include <stdio.h>
int fibonacci(int n) {
if (n <= 1)
return n;
return fibonacci(n – 1) + fibonacci(n – 2);
}
int main() {
int i;
printf(“Fibonacci series up to 10th term:n”);
for (i = 0; i < 10; i++)
printf(“%d “, fibonacci(i));
printf(“n”);
return 0;
}
Output:
Fibonacci series up to 10th term:
0 1 1 2 3 5 8 13 21 34
Flowchart:
Program to count the vowels and consonants in a given word using a function
Objective(s):
To count the number of vowels and consonants in a given word.
Program:
Program to count the vowels and consonants in a given word using a function.
Algorithm:
- Start
- Declare variables to store the counts of vowels and consonants.
- Define a function to check whether a character is a vowel.
- Iterate through each character in the word and increment the respective count.
- Display the counts of vowels and consonants.
- End
Code:
#include <stdio.h>
int isVowel(char c) {
return (c == ‘a’ || c == ‘e’ || c == ‘i’ || c == ‘o’ || c == ‘u’ || c == ‘A’ || c == ‘E’ || c == ‘I’ || c == ‘O’ || c == ‘U’);
}
int main() {
char word[100];
int vowels = 0, consonants = 0, i;
printf(“Enter a word: “);
scanf(“%s”, word);
for (i = 0; word[i] != ‘
