C Program Assistant
C Program Assistant
C Program Assistant
---------------------------------------------------------
Test Data
Input 10 numbers from the keyboard and calculate their sum & average.
---------------------------------------------------------
Code:
Copy code
#include <stdio.h>
intmain()
sum =0,;
float average;
achievement
printf("Enter 10 numbers:");
"For(int i=1;i<=10;i++)
printf("Number-%d: ",i);
scanf("%d", &num);
sum+=num;
//
average=(float)sum/10;
-------
",sum);
typeid(" ");
"
"
return 0;
Explanation:
Header:
#include
#include
Definitions:
#define num int n; Using for this purpose will avoid repetition and lengthy codes.
#define average int av; It is the average, this is because it's computation is based on the sum
Ask user: This program will prompt the user to enter 10 numbers
A for loop which iterates 10 times; reads in a number entered, then adds it to sum.
Example Output
Paste code
Input 10 numbers:
Number-1: 2
Number-2: 3
Number-10: 2
2)C
#include <stdio.h>
int main() {
scanf("%f", &basic_salary);
dearness_allowance
= 0.40 * basic_salary;
printf("Gross
salary: %.2f
", gross_salary);
return 0;
Explanation:
Include header: It includes the stdio.h header file for standard input-output operations.
Declare variables:
basic_salary: It stores the basic salary taken as input from the user.
Prompt user : The program prompts the user to input his basic salary .
Compute allowances :
Calculating gross salary: Gross salary = Basic salary + dearness allowance + house rent allowance.
Output:
Exercise:
Assignment: Make above program with following slabs for calculation of income tax:
Hint: There may use of conditional statements like if-else or switch-case for tax slab deduction on the
basis of gross salary.
3)C
#include <stdio.h>
int main () {
scanf("%f",&cost_price);
scanf("%f",&selling_price);
printf("
END
Header : stdio.h is the library that is present in the program to handle standard input and output
functions.
Variable Declaration:
cost_price: It is used for containing the cost price entered by the user.
Selling_price: It is used for containing the selling price entered by the user
User Input :Program looks specifically for the user input of Cost price and Selling price .
If Else statements check whether selling price is more, less or equal to cost price.
Input:
Task:
Task : Change the above code to calculate percentage of profit or percentage of loss from the cost price