C program using of struct example

#include<stdio.h>
#include<string.h>

int main(){
struct fruits{
char name[20];
float rate;
int quantity;
};
struct fruits fruit1,fruit2;
strcpy(fruit1.name ," apple");
   fruit1.rate= 5.10;
fruit1.quantity= 200;
strcpy(fruit2.name ," banana");
   fruit2.rate= 10.10;
fruit2.quantity= 100;
printf("name of fruit is = %s \n",fruit1.name);
printf("rate of fruit is = Rs.%.2f \n",fruit1.rate);
printf("quantity of fruit is = %d \n",fruit1.quantity);
printf("name of fruit is = %s \n",fruit2.name);
printf("rate of fruit is = Rs.%.2f \n",fruit2.rate);
printf("quantity of fruit is = %d \n",fruit2.quantity);
}

Comments

Post a Comment

Popular posts from this blog

Snake game.c

Type declaration

Array with function