Showing posts with label struct. Show all posts
Showing posts with label struct. Show all posts

Wednesday, January 27, 2016

Write A Program To Store N Number Of Students & Find Their Medical and Engineering Cut Off Marks

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define N 2
struct Student{
char student_name[20];
int Reg_no,First_lang,Second_lang,Maths,Phy,Che,Bio,Total,Result;
int Engg_cutoff,Medi_cutoff;
float Average;
};
int main(){
struct Student *stuRecord;
char tempName[20];
int tempTotal = 0,flag = 0,foundIndex,getAction,i,j;
clrscr();
stuRecord = (struct Student*)malloc(N*sizeof(struct Student));
for(i=0;i<N;i++){
printf("\n %d.Name :",(i+1));
scanf("%s",&stuRecord[i].student_name);
printf("\n Register Number :");
scanf("%d",&stuRecord[i].Reg_no);
printf("\n First Language :");
scanf("%d",&stuRecord[i].First_lang);
printf("\n Second Language :");
scanf("%d",&stuRecord[i].Second_lang);
printf("\n Maths :");
scanf("%d",&stuRecord[i].Maths);
printf("\n Physics :");
scanf("%d",&stuRecord[i].Phy);
printf("\n Chemistry :");
scanf("%d",&stuRecord[i].Che);
printf("\n Biology :");
scanf("%d",&stuRecord[i].Bio);
tempTotal=0;
tempTotal = stuRecord[i].First_lang+stuRecord[i].Second_lang+stuRecord[i].Maths+stuRecord[i].Phy+stuRecord[i].Che+stuRecord[i].Bio;
stuRecord[i].Total = tempTotal;
stuRecord[i].Average = tempTotal/6;
if(stuRecord[i].First_lang < 50 ||
stuRecord[i].Second_lang < 50 ||
stuRecord[i].Maths < 50 ||
stuRecord[i].Phy < 50 ||
stuRecord[i].Che < 50 ||
stuRecord[i].Bio < 50)
{
stuRecord[i].Result = 0;
}
else{
stuRecord[i].Result = 1;
stuRecord[i].Medi_cutoff = stuRecord[i].Bio+(stuRecord[i].Phy/2)+(stuRecord[i].Che/2);
stuRecord[i].Engg_cutoff = stuRecord[i].Maths+(stuRecord[i].Phy/2)+(stuRecord[i].Che/2);
}
}

printf("\n Enter the Name to be Searched: ");
scanf("%s",&tempName);
for(i=0;i<N;i++){
if(strcmp(tempName,stuRecord[i].student_name)==0)
{
foundIndex = i;
flag = 1;
break;
}
}
if(flag == 0)
{
printf("Details Not Found");
}
else
{
printf( "Press 1 to Print Result: \n" );
printf( "Press 2 to Print Cut Off Marks: \n" );
scanf( "%d", &getAction );

switch (getAction) {
case 1:
printf("\n Mark of %s are given below... \n",tempName);
printf("\n Register No: %d",stuRecord[foundIndex].Reg_no);
printf("\n First Language: %d",stuRecord[foundIndex].First_lang);
printf("\n Second Language: %d",stuRecord[foundIndex].Second_lang);
printf("\n Maths: %d",stuRecord[foundIndex].Maths);
printf("\n Physics: %d",stuRecord[foundIndex].Phy);
printf("\n Chemistry: %d",stuRecord[foundIndex].Che);
printf("\n Biology: %d",stuRecord[foundIndex].Bio);
printf("\n Total: %d",stuRecord[foundIndex].Total);
printf("\n Average: %f",stuRecord[foundIndex].Average);

if(stuRecord[foundIndex].Result == 1)
{
printf("\n Result: Pass \n");
}
else
{
printf("\n Result: Fail \n");
}
 break;
case 2:
printf("\n Mark of %s are given below... \n",tempName);
printf("\n Register No: %d",stuRecord[foundIndex].Reg_no);
printf("\n Total: %d",stuRecord[foundIndex].Total);
if(stuRecord[foundIndex].Result == 1)
{
printf("\n Result: Pass \n");
if(stuRecord[foundIndex].Medi_cutoff >=175){
printf("\n Medical_CutOff: Eligible \n");
printf("\n Engg_CutOff: Eligible \n");
}
else if(stuRecord[foundIndex].Engg_cutoff >=150){
printf("\n Medical_CutOff: Not Eligible \n");
printf("\n Engg_CutOff: Eligible \n");
}
else{
printf("\n Medical_CutOff: Not Eligible \n");
printf("\n Engg_CutOff: Not Eligible \n");
}
}
else
{
printf("\n Result: Fail \n");
printf("\n Medical_CutOff: Not Eligible \n");
printf("\n Engg_CutOff: Not Eligible \n");
}
 break;

default:
printf("Sorry, You Have Chosen Wrongly \n");
 break;
}
}
getch();
return 0;
}

Wednesday, November 25, 2015

Write a C program to maintain a record of “n” student details using an array of structures with four fields (Roll number, Name, Marks, and Grade). Each field is of an appropriate data type. Print the marks of the student given student name as input

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
struct student{
char name[14];
int rollNo;
int marks[3];
float percentage;
};

int main(){
struct student *stuArray;
int n,i,j;
int tempTotal=0,flag=0,foundIndex;
char tempName[14];
clrscr();
printf("\n No of Students: ");
scanf("%d",&n);
stuArray = (struct student*)malloc(n*sizeof(struct student));
for(i=0;i<n;i++){
printf("\n %d.Name :",(i+1));
scanf("%s",&stuArray[i].name);
printf("\n Roll Number :",(i+1));
scanf("%d",&stuArray[i].rollNo);
tempTotal=0;
for(j=0;j<3;j++)
{
printf("\n Mark %d :",(j+1));
scanf("%d",&stuArray[i].marks[j]);
tempTotal+=stuArray[i].marks[j];
}
stuArray[i].percentage=tempTotal/3;
}

printf("\n Enter the Name to be Searched: ");
scanf("%s",&tempName);
for(i=0;i<n;i++){
if(strcmp(tempName,stuArray[i].name)==0)
{
foundIndex=i;
flag=1;
break;
}
}
if(flag==0)
{
printf("Details Not Found");
}
else
{
printf("\n Mark of %s are given below...",tempName);
for(i=0;i<3;i++)
{
printf("\n Mark %d is %d",(i+1),stuArray[foundIndex].marks[i]);
}
}
getch();
return 0;
}

To Compile Press Alt+f9 
To Run Press Ctrl+f9

Output: