Monday, February 8, 2016

C program to read and display roll number and percentage from user.

Write a C program to read and display roll number and percentage from user.


Topic to learn: Use of int and float variables in C Program


Following C program will read roll number and percentage from the user and display it on screen. Program shows how to declare and use int and float variables.


#include<stdio.h>
int main()
{
   int rollno;
   float percentage;
 
   printf("Enter your Roll No:");
   scanf("%d", &rollno);
 
   printf("Enter your Percentage:");
   scanf("%f", &percentage);
  
   printf("Your Roll No: %d \n", rollno);
   printf("Your Percentage: %f", percentage); 
   return 0;
}

Output of Program:

Enter your Roll No:101
Enter your Percentage:85
Your Roll No: 101
Your Percentage: 85.000000

Note: By default %f will display up to six decimal points.

No comments:

Post a Comment