Skip to main content

Featured

C Program to Check Prime Number Using Efficient Logic

  Introduction A prime number is a number that has exactly two distinct positive divisors: 1 and itself. In this program, we check whether a given number is prime or not using a simple and efficient logic. This type of program is commonly used in mathematics, competitive programming, and basic algorithm learning for beginners in C programming. Problem Statement The task is to write a C program that determines whether a given integer is a prime number or not. The program takes a single integer input from the user and analyzes its divisibility. If the number has no divisors other than 1 and itself, it should be identified as a prime number; otherwise, it is not prime. This problem is important in number theory and has practical relevance in areas such as cryptography, data validation, and algorithm design.  Algorithm / Logic Explanation To check whether a number is prime, we need to verify that it is not divisible by any number other than 1 and itself. The algorithm follows a si...

Student Structure Program in C

Student Structure Program in C

✅ Student Details using Structure in C

#include <stdio.h>

struct student {
    char name[20];
    int roll;
    float marks;
};

int main() {
    struct student s;

    printf("=== ENTER STUDENT DETAILS ===\n");
    printf("Enter the name of the student:\n");
    scanf(" %[^\n]", s.name);  // Accepts spaces

    printf("Roll Number of the student:\n");
    scanf("%d", &s.roll);

    printf("Enter marks of the student:\n");
    scanf("%f", &s.marks);

    printf("\n=== STUDENT DETAILS ===\n");
    printf("Name: %s\n", s.name);
    printf("Roll Number: %d\n", s.roll);
    printf("Marks: %.2f\n", s.marks);

    return 0;
}
  

๐Ÿ“˜ Explanation:

This C program uses a structure to store and print details of a student. The structure contains three members: name (string), roll (integer), and marks (float). The program takes input using scanf, including a method to accept strings with spaces, and then displays the data using printf. This example introduces basic use of structures, string input handling, and formatted output.

๐Ÿงพ Sample Output:

=== ENTER STUDENT DETAILS ===
Enter the name of the student:
John Doe
Roll Number of the student:
101
Enter marks of the student:
87.5

=== STUDENT DETAILS ===
Name: John Doe
Roll Number: 101
Marks: 87.50
  

๐Ÿ”‘ Keywords:

Structure in C, student data structure, scanf with spaces, display student info, C program using struct, formatted output, beginner C example

๐Ÿ“Œ Hashtags:

#CProgramming #StructuresInC #StudentDetails #BeginnerC #PrintfScanf #CProjects #LearnC

Comments

Popular Posts

๐ŸŒ™