Long Type Questions
Long Type Questions
int main() {
// Variable declarations
int num;
// Code execution
printf("Enter a number: ");
scanf("%d", &num);
return 0;
}
int main() {
int day = 3;
switch(day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
default:
printf("Invalid day\n");
2
}
return 0;
}
int main() {
int num, sum = 0, digit;
while(num > 0) {
digit = num % 10; // Get last digit
sum += digit; // Add it to sum
num /= 10; // Remove last digit
}
return 0;
}
6. Write a C program to find the maximum of three numbers using ternary operator?
#include
int main() {
int a, b, c;
return 0;
}
Control statements dictate the flow of execution within a program based on certain
conditions or iterations.
• Decision-Making Statements: These include if statements and switch statements
that allow programs to make choices based on conditions.
• Looping Statements: These include for loops, while loops, and do-while loops that
enable repeated execution of code blocks until certain conditions are met.
Both types enhance flexibility and functionality by allowing dynamic responses based on
user input or other runtime conditions.
8. WAP to find the sum of digits of a number using function with arguments and with
return type.
#include
while(num > 0) {
sum += num % 10; // Add last digit to sum
num /= 10; // Remove last digit
}
int main() {
int number;
return 0;
}
4
9. Write functions to compute the factorial and power operation?
#include
int main() {
int num;
double base;
int exp;
return 0;
}
12. Write a C program to calculate the grade of a student by considering range marks
using switch-case statement.
#include
int main() {
int marks;
6
switch(marks / 10) { // Integer division gives ranges from grades.
case 9:
case 8:
printf("Grade: O\n");
break;
case 7:
printf("Grade: E\n");
break;
case 6:
printf("Grade: A\n");
break;
case 5:
printf("Grade: B\n");
break;
case 4:
printf("Grade: C\n");
break;
case 3:
printf("Grade: D\n");
break;
default:
if(marks >=0 && marks <=100)
printf("Grade: F\n");
else
printf("Invalid Marks!\n");
}
return 0;
}
int main() {
int n;
7
for(int j =2; j*j <= i; j++) {
if(i % j ==0) {
prime =0;
break;
}
}
if(prime ==1)
printf("%d ", i);
}
return(0);
}
return(a);
}
int main(){
int num1,num2;
return(0);
8
}
int main() {
char ch;
putchar('\n');
}
return(0);
}