Write a program to accept marks of four subjects as input from user. Calculate and display total and percentage marks of student. 

1 Answer

Answer :

#include<stdio.h>

#include<conio.h>

void main() {

float marks[4];

float total=0.0, perc=0.0;

int i;

clrscr();

for(i=1;i<=4;i++) {

printf("Enter marks of subject %d",i);

scanf("%f%",&marks[i]);

}

for(i=1;i<=4;i++){

total=total+marks[i];

}

printf("Total is :%f",total);

perc=total/4;

printf("Percentage is %f",perc);

getch();

}


Related questions

Description : Write a program to accept a string as input from user and determine its length. [Don’t use built in library function strlen()]

Last Answer : #include #include void main(){ char str[50]; int i, len=0; clrscr(); printf("Enter a string"); scanf("%s",&str); for(i=0; str[i]!='\0'; i++){ len++; } printf("The length of string is %d",len); getch(); }

Description : Write a program to declare structure student having rollno, name & marks.

Last Answer : Accept and display data for three students. #include #include void main() { int i; struct student{ int rollno; char name[20]; int marks; } s[3]; clrscr(); for(i=0;i

Description : Write a program to declare structure employee having data member name, age, street and city. Accept data for two employees and display it.

Last Answer : #include<stdio.h> #include<conio.h> struct employee { char name[10],street[10],city[10]; int age; }; void main() { int i; struct employee e[2]; clrscr(); for(i=0;i<2 ... =%s",e[i].street); printf("\n City=%s",e[i].city); } getch(); }

Description : Write a program to accept two numbers from user and perform addition, subtraction, multiplication and division operations using pointer.

Last Answer : #include #include void main() { int no1,no2,*ptr1,*ptr2,result; clrscr(); printf("Enter no1:"); scanf("%d",&no1); printf("\nEnter no2:"); scanf("%d",&no2); ptr1=&no1; ptr2=&no2; ... "\n Multiplication=%d",result); result=*ptr1/(*ptr2); printf("\n Division=%d",result); getch(); }

Description : If the value of a number (N) is entered through keyboard. Write a program using recursion to calculate and display factorial of number (N). 

Last Answer : #include<stdio.h> #include<conio.h> int factorial(int N); void main() { int N,fact; clrscr(); printf("Enter number:"); scanf("%d",&N); fact=factorial(N); printf( ... N) { if(N==1) return(1); else return(N*factorial(N-1)); }

Description : Write a program to accept the value of year as input from the keyboard & print whether it is a leap year or not. 

Last Answer : #include #include void main() { int year; clrscr(); printf("Enter year"); scanf("%d",&year); if(year%4==0) { printf("Year %d is a leap year",year); } else { printf("Year %d is not a leap year",year); } getch(); }

Description : Write a program to Print values of variables and their addresses. Note : 1) Variables can be of any data type. 2)Use of & or pointer to display address shall be considered. 

Last Answer : #include #include void main() { int a,b; clrscr(); a=5; b=10; printf("\n Value of a=%d",a); printf("\n Address of a=%u",&a); printf("\n Value of b=%d",b); printf("\n Address of b=%u",&b); getch(); }

Description : Write a program to add, subtract, multiply and divide two numbers, accepted from user switch case.

Last Answer : #include<stdio.h> #include<conio.h> void main() { int a,b,ch,add,sub,mul,div; clrscr(); printf("\n1 for addition \n2 for substraction"); printf("\n3 for multiplication \ ... break; default: printf("Invalid choice...."); } getch(); }

Description : Draw a flowchart of Do-while loop and write a program to add numbers until user enters zero. 

Last Answer : Flowchart of Do-while loop: Program:- #include<stdio.h> #include<conio.h> void main() { int no,sum=0; clrscr(); do { printf("\n Enter a number:"); scanf( ... no; }while(no!=0); printf("\n Sum of entered numbers =%d",sum); getch(); }

Description : Write a program to calculate sum of all the odd numbers between 1 to 20.

Last Answer : Write a program to calculate sum of all odd element of 1D array

Description : Develop a program to accept an integer number and print whether it is palindrome or not.

Last Answer : #include<stdio.h> #include<conio.h> void main() { int n,num,rev=0,digit,i; clrscr(); printf("Enter the number: "); scanf("%d",&num); n=num ... ;Number is palindrome"); else printf("Number is not palindrome"); getch(); }

Description : Write a program to declare class student having data members name and percentage. Write constructor to initialize these data members. Accept and display this data for one object.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class student { char name[20]; float per; public: student(char n[],float p) { strcpy(name,n); per=p; } ... { student S("Sachin",78.00); clrscr(); S.putdata(); getch(); }

Description : Develop a program using structure to print data of three students having data members name, class, percentage.

Last Answer : #include #include void main() { struct student { char name[20]; char c[20]; int per; } s[3]; int i; clrscr(); for(i=0;i

Description : Write a shell script to accept length and breadth of rectangle from user. Calculate and display area, perimeter, of entered values using choice entered by user.

Last Answer : #!/bin/bash # GNU bash, version 4.3.46 echo "Enter Length of Rectangle: " read length echo "Enter Breadth of Rectangle: " read breadth echo "Which operation you want to perform? 1: area 2: perimeter" read ... ) res=` echo 2 \* $length \* $breadth | bc` ;; esac echo "Result is $res" exit 0

Description : Design a programme in C to read the n numbers of values in an array and display it in reverse order.

Last Answer : #include #include #define max 50 void main() { int a[max],i,n; clrscr(); printf("\n Enter number of elements:"); scanf("%d",&n); printf("\n Enter array element:"); for(i=0;i=0;i--) printf("\t%d",a[i]); getch(); }

Description : Explain User defined function with example.

Last Answer : Functions are basic building blocks in a program. It can be predefined/ library functions or user defined functions. Predefined functions are those which are already available in C library. User defined functions are those which are ... value is: %d",a); } void main() { myFunc(10); getch() }

Description : Write a program to sort elements of an array in ascending order.

Last Answer : #include #include void main() { int a[5],i,j,temp; clrscr(); printf("\n Enter array elements:"); for(i=0;i

Description : Write a program to compute the sum of all elements stored in an array using pointers.

Last Answer : #include #include void main() { int a[5],sum=0,i,*ptr; clrscr(); printf("\n Enter array elements:"); for(i=0;i

Description : Write a program to read two strings and find whether they are equal or not.

Last Answer : #include<stdio.h> #include<conio.h> #include<string.h> void main() { char st1[20],st2[20]; printf( enter string 1 ); scanf( %s ,st1); printf( enter second string ); ... 0) printf( \nboth strings are equal ); else printf( \nstrings are not equal ); }

Description : Write a program to sum all the odd numbers between 1 to 20. 

Last Answer : #include<stdio.h> #include<conio.h> void main() { int sum=0,i; clrscr(); for(i=1;i<=20;i++)  { if(i%2==1) sum=sum+i; }  printf(“sum of odd no“s between 1 to 20 is %d”,sum); getcht); }

Description : Write a program to reverse the number 1234 (i.e. 4321) using function. 

Last Answer : #include #include void findReverse(); void main() { findReverse(); } void findReverse() {  int num, res=0,ans=0; clrscr(); printf("Enter the number"); scanf("%d", &num); while(num!=0) { res=num%10; ans=ans*10+res; num=num/10; } printf("Reverse number is %d", ans); getch(); }

Description : Write a program for addition of two 3 x 3 matrices.

Last Answer : #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j; clrscr(); printf("Enter first matrix elements:\n"); for(i=0;i<3;i++) { for(j=0;j<3 ... (j=0;j<3;j++) { printf("%d\t",c[i][j]); } } getch(); }

Description : Write a program using switch statement to check whether entered character is VOWEL or CONSONANT

Last Answer : #include<stdio.h> #include<conio.h> void main() { char ch; clrscr(); printf("Enter character:"); scanf("%c",&ch); switch(ch) { case 'a': ... break; default: printf("\n Entered character is CONSONANT"); } getch(); }

Description : Write a program to swap two numbers using call be value.

Last Answer : #include<stdio.h> #include<conio.h> void swap(int a, int b) { int temp; temp=a; a=b; b=temp; printf("Numbers after swapping no1=%d and no2=%d",a,b); } void ... ;Numbers before swapping no1=%d and no2= %d",no1, no2); swap(no1,no2); getch(); }

Description : Write a program to sweep the values of variables a = 10, b = 5 using function.

Last Answer : #include #include void swapvalues(int *i, int *j) { int temp; temp=*i; *i=*j; *j=temp; } void main() { int a=10; int b=5; clrscr(); printf("The values before swaping:\na=%d, b=%d",a,b); swapvalues(&a,&b); printf("\nThe values after swaping:\na=%d, b=%d",a,b); getch(); }

Description : Calculate factorial of a number using recursion.

Last Answer : #include #include int factorial(int no) { if(no==1) return(1); else return(no*factorial(no-1)); } void main() { intfact,no; clrscr(); printf("\n Enter number"); scanf("%d",&no); fact=factorial(no); printf("\n Factorial number=%d",fact); getch(); }

Description : Declare a structure student with element roll-no and name.  

Last Answer : struct student { int roll_no; char name[20]; };

Description : Explain how formatted input can be obtain, give suitable example.

Last Answer : Formatted input: When the input data is arranged in a specific format, it is called formatted input. scanf function is used for this purpose in C. General syntax: scanf( control string , arg1, arg2..); Control ... number"); scanf("%d",&i); printf("Entered number is: %d",i); getch(); }

Description : Write a program in C++ to accept a string from a user and display its reverse using pointer.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> void main() { char str[20],*ptr; int l; clrscr(); cout<<"\n Enter a string : "; cin>>str; l=strlen(str); ... (l!=0) { ptr--; cout<<*ptr; l--; } getch(); }

Description : Write a C++ program to declare a class ‘circle’ with data members as radius and area. Declare a function getdata to accept radius and putdata to calculate and display area of circle.

Last Answer : #include<iostream.h> #include<conio.h> class circle { float radius,area; public: void getdata() { cout<<"Enter radius:"; cin>>radius; } void putdata() { area=3 ... { circle c; clrscr(); c.getdata(); c.putdata(); getch(); }

Description : Write a C++ program to declare a class COLLEGE with members as college code. Derive a new class as STUDENT with members as studid. Accept and display details of student along with college for one object of student.

Last Answer : #include<iostream.h> #include<conio.h> class COLLEGE { protected: int collegecode; }; class STUDENT:public COLLEGE { int studid; public: void accept() { cout<<"Enter college ... STUDENT s; clrscr(); s.accept(); s.display(); getch(); }

Description : Write a C++ program to declare a class ‘College’ with data members as name and college code. Derive a new class ‘student’ from the class college with data members as sname and roll no. Accept and display details of one student with college data.

Last Answer : #include<iostream.h> #include<conio.h> class college { char name[10]; int collegecode; public: void getcollege() { cout<<"Enter college name:"; cin>>name; cout< ... (); s.getstudent(); s.putcollege(); s.putstudent(); getch(); }

Description : Develop a program to find diameter, circumference and area of circle using function.

Last Answer : #include<stdio.h> #include<conio.h> void circle(float r) { float diameter,circumference,area; diameter=2*r; printf("\n Diameter=%f",diameter); circumference=2*3.14*r; printf ... :"); scanf("%f",&radius); circle(radius); getch(); }

Description : Develop a program to swap two numbers using pointer and add swaped numbers also print their addition.

Last Answer : #include<stdio.h> void swap(int *a,int *b) {  int temp;  temp=*a;  *a=*b;  *b=temp; } void main() { int x,y,sum; printf("\n Enter value for x:"); scanf(" ... x); printf("\ny=%d",y); sum=x+y; printf("Sum of x+y = %d",sum); }

Description : Implement a program to demonstrate concept of pointers to function.

Last Answer : Pointer to function: include int sum(int x, int y) { return x+y; } int main() { int s; int(*fp)(int, int); fp = sum; s = fp(10,12); printf(“Sum = %d”,s); return 0; }

Description : Give a method to create, declare and initialize structure also develop a program to demonstrate nested structure.

Last Answer : Declaration of structure:- struct structure_name { data_type member 1; data_type member 2; . . . data_type member n; } structure variable 1, structure variable 2,..., structure variable n ... .collegeid); printf("\n College name=%s",s.c.collegename); getch(); }

Description : Implement a program to demonstrate logical AND operator.

Last Answer : #include #include void main() { int i; int j; clrscr(); printf("Enter the values of i and j"); scanf("%d%d",&i,&j); if(i==5 && j==5) { printf("Both i and j are equal to 5"); } else { printf("Both the values are different and either or both are not equal to 5"); } getch(); }

Description : Design a program to print a message 10 times.

Last Answer : #include #include void main() { int i; clrscr(); for(i=0;i

Description : Develop a program to find factorial of a number using recursion.

Last Answer : #include<stdio.h> #include<conio.h> int factorial(int num) { if(num==1) { return 1;  } else { return(num*factorial(num-1));  } } void main() { int ... ;num); result=factorial(num); printf("Factorial of %d is %d",num,result); getch(); }

Description : Develop a simple ‘C’ program for addition and multiplication of two integer numbers.

Last Answer : #include<stdio.h> #include<conio.h> void main() { int a,b,add,mul; clrscr(); printf("Enter value for a and b:"); scanf("%d%d",&a,&b); add=a+b; ... b=%d\n",add); printf("\Multiplication of a and b=%d",mul); getch(); }

Description : How Write javascript program to display multiplication table of 2 without accepting input from user?

Last Answer : Use a counted for loop. On each iteration, multiply the controlvariable by 2 and print the result.

Description : State four arithmetic operations perform on pointer with example.

Last Answer : The pointer arithmetic is done as per the data type of the pointer. The basic operations on pointers are Increment: It is used to increment the pointer. Each time a pointer is incremented, it points to the ... address 1004, Then ptr-2 shows 1004-(2*2) = 1000 as decremented location for an int. 

Description : Explain any four library functions under conio.h header file.

Last Answer : clrscr() -This function is used to clear the output screen. getch() -It reads character from keyboard getche()-It reads character from keyboard and echoes to o/p screen putch - Writes ... function is used to change the text color textbackground()-This function is used to change text background

Description : State any four math functions with its use. 

Last Answer : Math Functions: sqrt() - square root of an integer abs() - absolute value of an integer sin() - compute the sine value of an input value cos()- compute the cosine value of an input value pow() ... the power of a input value floor()- round down the input value ceil()- round up the input value

Description : State any four decision making statement.

Last Answer : Decision making statement: 1. if statement 2. if-else statement 3. if-else-if ladder 4. Nested if-else statement 5. switch statement 6. conditional operator statement (? : operator)

Description : Give any four advantages of pointer.

Last Answer : Advantages of pointer: 1. Pointers reduce the length and complexity of a program. 2. They increase execution speed. 3. A pointer enables us to access a variable that is defined outside the ... strings results in saving of data storage space in memory. 6. It supports dynamic memory management.

Description : Write a program that ask for user input from 5 to 9 then calculate the average

Last Answer : #include "iostream.h" int main() { int MAX = 4; int total = 0; int average; int numb; for (int i=0; i numb; while ( numb9) { cout > numb; } total = total + numb; } average = total/MAX; cout

Description : Write a function to print Fibonacci series starting from 0, 1.

Last Answer : void Fibbo() { inta,b,c,limit,i; printf("\n Enter number:"); scanf("%d",&limit); a=0; b=1; printf("%d\t%d",a,b); for(i=0;i

Description : Write an algorithm to determine the given number is odd or even.

Last Answer : Step 1- Start Step 2- Read / input the number. Step 3- if n%2==0 then number is even. Step 4- else number is odd. Step 5- display the output. Step 6- Stop

Description : Write the syntax of switch case statement. 

Last Answer : switch(variable) { case value1: statements break; case value2: statements; break; . . . default: statements; break; }