Pages

Sunday, August 14, 2016

Use of various Data Types in C program.


Use of various Data Types in C program.


#include<stdio.h>
int main()
{
            int rollno;
            char name[20];
            float age;
            char grade;
                       
            printf("Enter your roll no.:");
            scanf("%d", &rollno);
                       
            printf("Enter your name:");
            scanf("%s", name);
           
            printf("Enter your age:");
            scanf("%f", &age);
           
            printf("Enter your grade:");
            scanf(" %c", &grade);
            //Note: if program not read value properly,
            //leave one space before " %c"
           
            //Logic for Printing output....
            printf("========================\n");
            printf("Your Roll No is %d.\n", rollno);
            printf("Your Name is %s.\n", name);
            printf("Your Age is %.1f.\n", age);
            //Note: "%.1f" will print with one decimal point
            printf("Your Grade is %c.\n", grade);
            printf("========================\n");
            return 0;
}


Output of the Program:

Enter your roll no.:101
Enter your name:ABC
Enter your age:23.5
Enter your grade:A
========================
Your Roll No is 101.
Your Name is ABC.
Your Age is 23.5.
Your Grade is A.
========================


No comments:

Post a Comment