0% found this document useful (0 votes)
18 views

WAPT Input 12 Player

Uploaded by

bhamardiwala2005
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

WAPT Input 12 Player

Uploaded by

bhamardiwala2005
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

1) WAPT input 12 player’s age of indian cricket team and find the average of 12 player’s age.

Algorithm:

FLOWCHART

CODE

#include <stdio.h>

int main() {

int ages[12]; // Array to store the ages

int sum = 0; // Variable to store the sum

float average;

// Input ages of 12 players individually

printf("Enter the ages of 12 players:\n");

printf("Enter age of player 1: ");

scanf("%d", &ages[0]);

printf("Enter age of player 2: ");

scanf("%d", &ages[1]);
printf("Enter age of player 3: ");

scanf("%d", &ages[2]);

printf("Enter age of player 4: ");

scanf("%d", &ages[3]);

printf("Enter age of player 5: ");

scanf("%d", &ages[4]);

printf("Enter age of player 6: ");

scanf("%d", &ages[5]);

printf("Enter age of player 7: ");

scanf("%d", &ages[6]);

printf("Enter age of player 8: ");

scanf("%d", &ages[7]);

printf("Enter age of player 9: ");

scanf("%d", &ages[8]);

printf("Enter age of player 10: ");

scanf("%d", &ages[9]);

printf("Enter age of player 11: ");

scanf("%d", &ages[10]);

printf("Enter age of player 12: ");

scanf("%d", &ages[11]);

// Manually calculate the sum

sum = ages[0] + ages[1] + ages[2] + ages[3] + ages[4] + ages[5] +

ages[6] + ages[7] + ages[8] + ages[9] + ages[10] + ages[11];

// Calculate average

average = sum / 12.0;

// Output the average age


printf("The average age of the 12 players is: %.2f\n", average);

return 0;

2) WAPT read and display roll number, three subject marks, total and percentage from user.

FLOWCHART

CODE
#include <stdio.h>

int main() {
int roll_number;
float subject1, subject2, subject3, total, percentage;

// Input roll number


printf("Enter Roll Number: ");
scanf("%d", &roll_number);

// Input marks for three subjects


printf("Enter marks for Subject 1: ");
scanf("%f", &subject1);
printf("Enter marks for Subject 2: ");
scanf("%f", &subject2);
printf("Enter marks for Subject 3: ");
scanf("%f", &subject3);

// Calculate total and percentage


total = subject1 + subject2 + subject3;
percentage = (total / 300) * 100;

// Display roll number, total, and percentage


printf("\nRoll Number: %d\n", roll_number);
printf("Total Marks: %.2f\n", total);
printf("Percentage: %.2f%%\n", percentage);

return 0;
}

3) Program to Find Area of Square (length*length), rectangle (length*breadth) and a


Circle(3.14*r*r).

ALGORITHM

FLOW CHART
CODE

#include <stdio.h>

int main() {

float length, breadth, radius, area_square, area_rectangle, area_circle;

// Input for square

printf("Enter the side length of the square: ");

scanf("%f", &length);

area_square = length * length;

// Input for rectangle

printf("Enter the length and breadth of the rectangle: ");

scanf("%f %f", &length, &breadth);

area_rectangle = length * breadth;

// Input for circle

printf("Enter the radius of the circle: ");

scanf("%f", &radius);

area_circle = 3.14 * radius * radius;

// Display results

printf("\nArea of Square: %.2f\n", area_square);

printf("Area of Rectangle: %.2f\n", area_rectangle);

printf("Area of Circle: %.2f\n", area_circle);

return 0;

}
4) WAPT calculate Simple Interest.(SI=P*R*N) P=principle amount R= rate of interest N=no of year

Code

#include <stdio.h>

int main() {

float P, R, N, SI;

// Input principal amount

printf("Enter the principal amount (P): ");

scanf("%f", &P);

// Input rate of interest

printf("Enter the rate of interest (R): ");

scanf("%f", &R);

// Input number of years

printf("Enter the number of years (N): ");

scanf("%f", &N);
// Calculate Simple Interest

SI = P * R * N;

// Display the result

printf("\nThe Simple Interest (SI) is: %.2f\n", SI);

return 0;

5) WAPT input 2 values and to Changing (swapping) value of two variables using use of third
variable. Eg: a=10 b=20 c=0 Output : a=20 b=10

Code

#include <stdio.h>
int main() {

int a, b, c;

// Input values for a and b

printf("Enter the value of a: ");

scanf("%d", &a);

printf("Enter the value of b: ");

scanf("%d", &b);

// Swapping using third variable

c = a; // Store value of a in c

a = b; // Assign value of b to a

b = c; // Assign value of c to b

// Display swapped values

printf("\nAfter swapping:\n");

printf("a = %d\n", a);

printf("b = %d\n", b);

return 0;

6) WAPT input 2 values and to Changing(swapping) value of two variables without use of third
variable.
#include <stdio.h>

int main() {

int a, b;

// Input values for a and b

printf("Enter the value of a: ");

scanf("%d", &a);

printf("Enter the value of b: ");

scanf("%d", &b);

// Swapping without a third variable

a = a + b; // Step 1: Add both values


b = a - b; // Step 2: Update b to original value of a

a = a - b; // Step 3: Update a to original value of b

// Display swapped values

printf("\nAfter swapping:\n");

printf("a = %d\n", a);

printf("b = %d\n", b);

return 0;

7) WAPT check the number is even or odd.

#include <stdio.h>

int main() {

int num;
// Step 1: Input a number

printf("Enter a number: ");

scanf("%d", &num);

// Step 2: Check if the number is even or odd

if (num % 2 == 0) {

printf("%d is an even number.\n", num);

} else {

printf("%d is an odd number.\n", num);

return 0;

8) WAPT find the distance between 2 cities (in Kilometer) is input through K/B.WAPT convert &
print this distance in meter, inch, feet and centimeter
#include <stdio.h>

int main() {

float distance_km, distance_m, distance_inch, distance_feet, distance_cm;

// Step 1: Input distance in kilometers

printf("Enter the distance between two cities in kilometers: ");

scanf("%f", &distance_km);

// Step 2: Convert the distance to other units

distance_m = distance_km * 1000; // Convert to meters

distance_inch = distance_km * 39370.1; // Convert to inches

distance_feet = distance_km * 3280.84; // Convert to feet

distance_cm = distance_km * 100000; // Convert to centimeters

// Step 3: Output the converted distances

printf("\nDistance in Meters: %.2f", distance_m);

printf("\nDistance in Inches: %.2f", distance_inch);

printf("\nDistance in Feet: %.2f", distance_feet);

printf("\nDistance in Centimeters: %.2f\n", distance_cm);

return 0;

}
9) WAPT find whether the Given Number is a Prime Number.

#include <stdio.h>

#include <math.h> // Required for sqrt function

int main() {

int num, is_prime = 1;

// Step 1: Input the number

printf("Enter a number: ");

scanf("%d", &num);

// Step 2: Check if the number is prime

if (num <= 1) {
is_prime = 0; // Numbers <= 1 are not prime

} else {

for (int i = 2; i <= sqrt(num); i++) {

if (num % i == 0) {

is_prime = 0; // Found a divisor, number is not prime

break;

// Step 3: Output the result

if (is_prime) {

printf("%d is a prime number.\n", num);

} else {

printf("%d is not a prime number.\n", num);

return 0;

10) WAPT Find whether a Number is Palindrome or Not.Ex=(121→121)


11) WAPT check whether the number is +ve, -ve or zero.

#include <stdio.h>

int main() {

int num;

// Step 1: Input the number

printf("Enter a number: ");

scanf("%d", &num);

// Step 2: Check if the number is positive, negative, or zero

if (num > 0) {

printf("%d is a positive number.\n", num);

} else if (num < 0) {

printf("%d is a negative number.\n", num);

} else {
printf("The number is zero.\n");

return 0;

12) WAPT check whether inputted character is vowel or consonants.

#include <stdio.h>

#include <ctype.h> // Required for tolower function

int main() {

char ch;

// Step 1: Input a character

printf("Enter a character: ");

scanf("%c", &ch);
// Step 2: Check if the character is a vowel or consonant

ch = tolower(ch); // Convert to lowercase for uniform comparison

if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {

printf("%c is a vowel.\n", ch);

} else if ((ch >= 'a' && ch <= 'z')) {

printf("%c is a consonant.\n", ch);

} else {

printf("%c is not an alphabetic character.\n", ch);

return 0;

13) WAPT read a cost price, selling price of an item, program to determine whether the seller has
been made profit or loss.
#include <stdio.h>

int main() {

float cp, sp, profit, loss;

// Step 1: Input cost price and selling price

printf("Enter the cost price of the item: ");

scanf("%f", &cp);

printf("Enter the selling price of the item: ");

scanf("%f", &sp);

// Step 2: Determine profit or loss

if (sp > cp) {

profit = sp - cp;

printf("Profit = %.2f\n", profit);

} else if (sp < cp) {

loss = cp - sp;

printf("Loss = %.2f\n", loss);

} else {

printf("No profit, no loss.\n");

return 0;

14) WAPT find inputted year is ‘leap’ or ‘not’.


#i
nclude <stdio.h>

int main() {

int year;

// Step 1: Input the year

printf("Enter a year: ");

scanf("%d", &year);
// Step 2: Check for leap year

if (year % 4 == 0) { // If the year is divisible by 4

if (year % 100 == 0) { // If the year is divisible by 100

if (year % 400 == 0) { // If the year is divisible by 400

printf("%d is a leap year.\n", year);

} else { // This 'else' matches the inner 'if' checking divisibility by 400

printf("%d is not a leap year.\n", year);

} else { // This 'else' matches the second 'if' checking divisibility by 100

printf("%d is a leap year.\n", year);

} else { // This 'else' matches the first 'if' checking divisibility by 4

printf("%d is not a leap year.\n", year);

return 0;

15) WAPT in c to input any character if it is in upper case, lower case, digit or space.
#include <stdio.h>

#include <ctype.h> // For isdigit(), isupper(), islower(), isspace()

int main() {

char ch;

// Step 1: Input a character

printf("Enter a character: ");

scanf("%c", &ch);

// Step 2: Check the type of the character

if (isupper(ch)) {

printf("'%c' is an uppercase letter.\n", ch);

} else if (islower(ch)) {

printf("'%c' is a lowercase letter.\n", ch);

} else if (isdigit(ch)) {

printf("'%c' is a digit.\n", ch);

} else if (isspace(ch)) {
printf("The character is a space.\n");

} else {

printf("'%c' is a special character.\n", ch); // For non-alphabetic, non-digit, non-space

return 0;

16) WAPT read a character from keyboard and print it in reverse case. For example enter the
character: a(lower case) then the output will be return A(upper case)

#incl
ude <stdio.h>

#include <ctype.h> // For toupper() and tolower() functions


int main() {

char ch;

// Step 1: Input a character

printf("Enter a character: ");

scanf("%c", &ch);

// Step 2: Reverse the case

if (islower(ch)) { // If the character is lowercase

ch = toupper(ch); // Convert to uppercase

} else if (isupper(ch)) { // If the character is uppercase

ch = tolower(ch); // Convert to lowercase

// Step 3: Output the reversed case

printf("Reversed case character: %c\n", ch);

return 0;

17) Write a program to calculate result according to following rules. Take input roll no, name, m1,
m2, m3, m4 and calculate percentage, result and class. The class is declared on the following
criteria. If per>=70, class=”Distinction” If per>=60 and per=50 and per=40 and per

18) Program to Check Whether the Given Number is an Armstrong Number or not. Example:153 is
Armstrong number because (1*1*1+5*5*5+3*3*3)=(1+125+27)=153

19) Program to Print the Numbers Which are Divisible by 5 and 7 from First 100 Natural Numbers
#include <stdio.h>

int main() {

// Step 1: Loop through the first 100 natural numbers

printf("Numbers divisible by 5 and 7 from 1 to 100 are:\n");

for (int i = 1; i <= 100; i++) {

// Step 2: Check if the number is divisible by both 5 and 7

if (i % 5 == 0 && i % 7 == 0) {

printf("%d ", i); // Step 3: Print the number

printf("\n"); // Newline after the list of numbers

return 0;

20) Program to Reverse a Given Number. Ex:enter number 1234 revers print 4321

21) WAPT generate following series up to given step:0 1 1 2 3 5 8 13…N

22) WAPT generate following series up to given steps:1 3 6 10 15

You might also like