Predict The Output Decodex
Predict The Output Decodex
int main() {
char str[] = "programming";
int seen[256] = {0};
A) p r o g a m i n
B) p r o g a m
C) p r o g a
D) g r a m
Correct Answer: A
2.How many times will the inner loop execute for the string "Hello"?
#include <stdio.h>
int main() {
char str[] = "Hello";
for (int i = 0; str[i] != '\0'; i++) {
for (int j = 0; j < 2; j++) {
printf("%c ", str[i]);
}
}
return 0;
}
A) 5
B) 10
C) 2
D) 7
Correct Answer: B
#include <stdio.h>
int main() {
char str[] = "Hello";
int sum = 0;
#include <stdio.h>
int main() {
char str[] = "abcde";
char maxChar = str[0];
A) Maximum character is : a
B) Maximum character is : e
C) Maximum character is : d
D) Maximum character is : c
Correct Answer: B
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, World!";
char *ptr;
return 0;
}
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "Good ";
char str2[] = "Morning";
strncpy(str1 + 5, str2, 7); // Copying part of str2 to str1
printf("%s\n", str1);
return(0);
}
A) Good Morning
B) Good Morni
C) Good Mornin
D) Good Morn
Correct Answer: B
#include <stdio.h>
int main() {
float amount, discount;
printf("Enter purchase amount: ");
scanf("%f", &amount);
if (amount > 0) {
if (amount < 100) {
discount = 0;
} else if (amount < 500) {
discount = 0.1 * amount; // 10% discount
} else {
discount = 0.2 * amount; // 20% discount
}
printf("Discount: %.2f\n", discount);
printf("Final amount: %.2f\n", amount - discount);
} else {
printf("Invalid amount\n");
}
return 0;
}
A)
Discount: 0.00
Final amount: 50.00
B)
Discount: 5.00
Final amount: 45.00
C)
Discount: 10.00
Final amount: 40.00
D)
Invalid amount
Correct Answer: A
8.What will be the output if the user inputs the values 5 and 10 for variables a
and b respectively?
#include <stdio.h>
A)
a: 5, b: 10
B)
a: 10, b: 5
C)
a: 15, b: 5
D)
Invalid input
Correct Answer: B
#include <stdio.h>
#include <string.h>
int main(void) {
char string[] = "simplyeasylearning"; // Input string
char temp; // Temporary variable for swapping
int i, j;
int n = strlen(string); // Length of the string
printf("String before sorting: %s\n", string);
A)
String before sorting: simplyeasylearning
B)
String before sorting: learningeasy
C)
String before sorting: aaeegiillmnnprssyy
D)
String before sorting: None
Correct Answer: A
10.