Friday, January 29, 2016

Matrix Manipulation Using Array & Switch Case

#include<stdio.h>
#include<conio.h>
int main()
{
int row, column,calc,i,j,k,first[10][10],second[10][10], result[10][10];
clrscr();
printf("Enter the number of rows and columns: \n");
scanf("%d%d", &row,&column);

printf("Enter the first element: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
scanf("%d",&first[i][j]);
}
}

printf("Enter the second element: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
scanf("%d",&second[i][j]);
}
}

    printf("\n Matrix Addition            : 1");
    printf("\n Matrix Subtraction         : 2");
    printf("\n Matrix Multiplication      : 3");
    printf("\n Enter Your Choice          : ");
    scanf("%d",&calc);
    switch(calc)
    {
   case 1:
  printf("Result of Matrix Addition: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
result[i][j] = first[i][j]+second[i][j];
printf("%d\t",result[i][j]);
}
printf("\n");
}
break;
   case 2:
  printf("Result of Matrix Subtraction: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
result[i][j] = first[i][j]-second[i][j];
printf("%d\t",result[i][j]);
}
printf("\n");
}
break;
   case 3:
  printf("Result of Matrix Multiplication: \n");
for(i=0;i<row;i++){
for(j=0;j<column;j++){
result[i][j] = 0;
for(k=0;k<row;k++)
{
result[i][j] = result[i][j]+(first[i][k]*second[k][j]);
}
  // result[i][j] = first[i][j]*second[i][j];
  printf("%d\t",result[i][j]);
}
printf("\n");
}
break;
   default:
printf("\nInvalid Choice");
    }
getch();
return 0;
}

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;
}