You are on page 1of 3

Q.write a C program that will allow the computer to be used as an ordinary desk calculator.

consider only the common arithmetic operations( addition, subtraction, multiplication and division). include a memory that can store one number #include<stdio.h> #include<stdlib.h> #include<string.h> void main() { int a,b,output,ch; float output1; printf("\n\tWEL COME TO MINI COMPUTER:\n"); printf("\n\tMENU\n"); printf("\t********************"); printf("\n\t(1)ADDITION"); printf("\n\t(2)SUBTRACTION"); printf("\n\t(3)MULTIPLICATION"); printf("\n\t(4)DIVISION"); printf("\n\t(0)EXIT"); printf("\n\t********************"); printf("\n\n\tEnter your choice:"); scanf("%d",&ch); if(ch<=4 & ch>0) { printf("Enter any two integer numbers:\n"); scanf("%d%d",&a,&b); } switch(ch) { case 1: output=a+b; printf("\n Addition:%d",output); break; case 2: output=a-b; printf("\n Subtraction:%d",output); break; case 3: output=a*b; printf("\n Multiplication:%d",output); break; case 4: if(b!=0) { output1=a/(float)b; printf("\n Division:%f",output1); } else { printf("Division by zero not possible"); } break; case 0: printf("\n Choice Terminated"); exit(1); break; default: printf("\n Invalid Choice"); } }

Q.write an interactive C program that will accept each students name and exam grades in five modules and determine an average grade for each students, and then display the students name, the individual exam grades and the calculated average. #include<stdio.h> #include<string.h> #include<stdlib.h> /* define student record */ struct student { char name[30]; int marks[5]; /* for 5 subjects */ float avg , total; char grade; }; void main() { int n ; /* select how many students */ struct student stud[100]; /* you can store information about a maximum of 100 students*/ int i , j; float temp; printf("\n\t Enter the number of students in the class :\n\t "); scanf("%d" , &n); for( i = 0 ; i < n ; i++) { printf("Enter student name :"); scanf("%s" ,& stud[i].name); printf("Enter student grade :"); scanf("%s" , &stud[i].grade); printf("Enter 5 subject marks : \n\t"); for(j = 0 ; j<5 ; j++) scanf("%d" , &stud[i].marks[j]); /* calculate total and average for that particular student */ temp = 0; for( j = 0 ; j < 5 ; j++) temp += stud[i].marks[j]; stud[i].total = (float)temp; stud[i].avg = (float)temp/5.0; } printf("Print student info :\n"); for( i = 0 ; i < n ; i++) { printf(" student name :%s\n" , stud[i].name); printf(" student grade :%s\n" , stud[i].grade); printf("5 subject mark :"); for(j = 0 ; j <5 ; j++) printf(" %d" , stud[i].marks[j]); printf("Total = %f\n" , stud[i].total); printf("Average %f\n" , stud[i].avg); } }

You might also like