0% found this document useful (0 votes)
3 views2 pages

C Programs Chapter 11

The document contains a series of C programming questions and their corresponding solutions. Each question focuses on basic programming concepts such as checking even/odd numbers, determining positive/negative values, identifying vowels, finding the largest of three numbers, calculating square roots, interpreting temperature, checking leap years, and calculating grades based on percentage. The provided solutions include code snippets demonstrating the implementation of these concepts.

Uploaded by

mehak123ab
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

C Programs Chapter 11

The document contains a series of C programming questions and their corresponding solutions. Each question focuses on basic programming concepts such as checking even/odd numbers, determining positive/negative values, identifying vowels, finding the largest of three numbers, calculating square roots, interpreting temperature, checking leap years, and calculating grades based on percentage. The provided solutions include code snippets demonstrating the implementation of these concepts.

Uploaded by

mehak123ab
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C Programming Practice (Proper Questions &

Solutions)
Question: Write a program that inputs an integer and checks whether it is even or odd.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("Even number");
else
printf("Odd number");
return 0;
}

Question: Write a program that inputs a number and determines whether it is positive, negative, or
zero.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num > 0)
printf("Positive number");
else if (num < 0)
printf("Negative number");
else
printf("Zero");
return 0;
}

Question: Write a program that inputs a character and checks whether it is a vowel or not using
switch statement.
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf(" %c", &ch);
switch(ch) {
case 'a': case 'e': case 'i': case 'o': case 'u':
case 'A': case 'E': case 'I': case 'O': case 'U':
printf("Vowel");
break;
default:
printf("Not a vowel");
}
return 0;
}

Question: Write a program that inputs three numbers and displays the largest number among
them.
#include <stdio.h>
int main() {
int a,b,c;
printf("Enter three numbers: ");
scanf("%d %d %d",&a,&b,&c);
if(a>=b && a>=c)
printf("Largest=%d",a);
else if(b>=a && b>=c)
printf("Largest=%d",b);
else
printf("Largest=%d",c);
return 0;
}
Question: Write a program that inputs a number and calculates its square root.
#include <stdio.h>
#include <math.h>
int main() {
float num;
printf("Enter number: ");
scanf("%f",&num);
printf("Square root = %.2f", sqrt(num));
return 0;
}

Question: Write a program that inputs temperature in Celsius and displays: - 'Hot day' if
temperature is greater than 35 - 'Pleasant day' if temperature is between 25 and 35 (inclusive) -
'Cool day' if temperature is less than 25
#include <stdio.h>
int main() {
float temp;
printf("Enter temperature: ");
scanf("%f",&temp);
if(temp>35)
printf("Hot day");
else if(temp>=25)
printf("Pleasant day");
else
printf("Cool day");
return 0;
}

Question: Write a program that inputs a year and checks whether it is a leap year or not.
#include <stdio.h>
int main() {
int year;
printf("Enter year: ");
scanf("%d",&year);
if((year%4==0 && year%100!=0) || (year%400==0))
printf("Leap year");
else
printf("Not a leap year");
return 0;
}

Question: Write a program that inputs obtained marks (out of 1100), calculates percentage, and
displays grade according to: 80+ A+, 70-79 A, 60-69 B, 50-59 C, 40-49 D, 33-39 E, below 33 F.
#include <stdio.h>
int main() {
float marks, percentage;
printf("Enter obtained marks (out of 1100): ");
scanf("%f",&marks);
percentage = (marks/1100)*100;
printf("Percentage = %.2f\n",percentage);
if(percentage>=80)
printf("Grade: A+");
else if(percentage>=70)
printf("Grade: A");
else if(percentage>=60)
printf("Grade: B");
else if(percentage>=50)
printf("Grade: C");
else if(percentage>=40)
printf("Grade: D");
else if(percentage>=33)
printf("Grade: E");
else
printf("Grade: F");
return 0;
}

You might also like