Important Program :
1.write a program to display following pattern
*****
****
***
**
*
#include <stdio.h>
int main() {
int rows = 5; // Number of rows in the pattern
// Outer loop for rows
for(int i = 0; i < rows; i++) {
// Inner loop for printing '*'
for(int j = 0; j < rows - i; j++) {
printf("* ");
}
// Move to the next line after each row
printf("\n");
}
return 0;
}
2. Write a program to identify number entered by use is even and odd.
#include <stdio.h>
int main() {
int number;
// Ask the user to enter a number
printf("Enter an integer: ");
scanf("%d", &number);
// Check if the number is even or odd
if(number % 2 == 0) {
printf("%d is even.\n", number);
} else {
printf("%d is odd.\n", number);
}
return 0;
}
3. Write a Program to print Fibonacci series up to the term entered by the user .
#include <stdio.h>
int main() {
int n, first = 0, second = 1, next;
// Ask the user to enter the number of terms
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series up to %d terms:\n", n);
// Print the first two terms of Fibonacci series
printf("%d, %d, ", first, second);
// Generate and print the rest of the terms
for (int i = 2; i < n; i++) {
next = first + second;
printf("%d, ", next);
first = second;
second = next;
}
printf("\n");
return 0;
}
4. w rite a program to read and print a matrix of 3x3.
#include <stdio.h>
int main() {
int matrix[3][3];
// Ask the user to enter the elements of the matrix
printf("Enter the elements of the 3x3 matrix:\n");
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
printf("Enter element at position (%d, %d): ", i+1, j+1);
scanf("%d", &matrix[i][j]);
}
}
// Display the matrix
printf("\nThe entered matrix is:\n");
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
printf("%d\t", matrix[i][j]);
}
printf("\n");
}
return 0;
}
5. Write a program by using any three string manipulation Function.
#include <stdio.h>
#include <string.h>
int main() {
char str1[50] = "Hello";
char str2[50] = "World";
char str3[100];
// String Length Function (strlen)
printf("Length of str1: %d\n", strlen(str1));
printf("Length of str2: %d\n", strlen(str2));
// String Copy Function (strcpy)
strcpy(str3, str1);
printf("Copied string (str3) after strcpy: %s\n", str3);
// String Concatenation Function (strcat)
strcat(str3, " ");
strcat(str3, str2);
printf("Concatenated string (str3) after strcat: %s\n", str3);
return 0;
}
6. Write a program in c by using a structure to store information of students i.e name .roll
number and Marks and also display it.
#include <stdio.h>
// Define a structure to hold student information
struct Student {
char name[50];
int rollNumber;
float marks;
};
int main() {
// Declare an array of structures to store multiple students' information
struct Student students[3]; // Assuming we have 3 students
// Read student information from the user
for (int i = 0; i < 3; i++) {
printf("Enter details for student %d:\n", i + 1);
printf("Name: ");
scanf("%s", students[i].name);
printf("Roll Number: ");
scanf("%d", &students[i].rollNumber);
printf("Marks: ");
scanf("%f", &students[i].marks);
}
// Display student information
printf("\nStudent Information:\n");
for (int i = 0; i < 3; i++) {
printf("Student %d\n", i + 1);
printf("Name: %s\n", students[i].name);
printf("Roll Number: %d\n", students[i].rollNumber);
printf("Marks: %.2f\n", students[i].marks);
printf("\n");
}
return 0;
}