write a c program to Scan the structure variables and print on the screen
BM Balmiki Mandal 16 Dec 2022 4 views 0 comments C Programming

write a c program to Scan the structure variables and print on the screen

To scan the structure variables and print them on the screen, you first need to define a structure that contains the variables you want to scan and print. Here's an example of a structure definition:

struct student {
    char name[50];
    int rollNo;
    float marks;
};

This structure defines a student with three variables: a character array name, an integer rollNo, and a float marks.

Now, to scan the values of these variables from the user, you can use the scanf() function as follows:

#include <stdio.h>

int main() {
    struct student s;

    printf("Enter name: ");
    scanf("%s", s.name);

    printf("Enter roll number: ");
    scanf("%d", &s.rollNo);

    printf("Enter marks: ");
    scanf("%f", &s.marks);

    printf("Student details:\n");
    printf("Name: %s\n", s.name);
    printf("Roll number: %d\n", s.rollNo);
    printf("Marks: %.2f\n", s.marks);

    return 0;
}

In this program, we first define a variable s of the student structure type. Then we prompt the user to enter the name, roll number, and marks of the student using printf() and scanf() functions. Finally, we print the details of the student using printf() function.

Note that when scanning integer and float variables, we use the & operator to get the address of the variable, since scanf() requires the address of the variable to modify its value. However, in the case of a character array like name, we don't need to use the & operator since the array name itself represents the address of the first element of the array.

 

#include<stdio.h>
struct one
{
    int i;
    char ch;
    float f;
};
void main()
{
    struct one s1;
    printf("Enter the Any Number:");
    scanf("%d",&s1.i);
    printf("Enter any charcater:");
    scanf("%s",&s1.ch);
    printf("Enter any Floating Number:");
    scanf("%f",&s1.f);
    printf("%d %c %f\n",s1.i,s1.ch,s1.f);
}

Output:

Enter the Any Number: 10

Enter any character: B

Enter any Floating Number: 23.4

10  B  23.400000

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

C Bitwise Operators Explained: 10 Practice Programs with Output

E.1: Bitwise vs. Logical Operators#include<stdio.h> int main(void){ int x=7,y=19; printf("%d %d ",x&y...

AG Anvesh G 29 Nov 2026
Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026