java questions solution
java questions solution
java questions solution
if (current != NULL) {
printf("The %dth node from the given node is: %d\n", n, current->data);
} else {
printf("The given node doesn't have %d nodes ahead.\n", n);
}
}
int main() {
struct Node* head = NULL;
addNode(&head, 10);
addNode(&head, 20);
addNode(&head, 30);
addNode(&head, 40);
addNode(&head, 50);
addNode(&head, 60);
addNode(&head, 70);
printNthNodeFromGivenNode(head, 6);
return 0;
}
struct Node {
int data;
struct Node* next;
};
free(current);
}
void printList(struct Node* head) {
struct Node* current = head;
while (current != NULL) {
printf("%d -> ", current->data);
current = current->next;
}
printf("NULL\n");
}
int main() {
struct Node* head = NULL;
addNode(&head, 10);
addNode(&head, 20);
addNode(&head, 30);
addNode(&head, 40);
addNode(&head, 50);
addNode(&head, 60);
addNode(&head, 70);
printf("Original list: ");
printList(head);
deleteNode(&head, 30);
return 0;
}
3. Wap to take a character from user and print its pattern using *
#include <stdio.h>
void printA() {
printf(" * \n");
printf(" * * \n");
printf("*****\n");
printf("* *\n");
printf("* *\n");
}
void printB() {
printf("**** \n");
printf("* *\n");
printf("**** \n");
printf("* *\n");
printf("**** \n");
}
void printC() {
printf(" ****\n");
printf("* \n");
printf("* \n");
printf("* \n");
printf(" ****\n");
}
void printD() {
printf("**** \n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("**** \n");
}
void printE() {
printf("*****\n");
printf("* \n");
printf("*****\n");
printf("* \n");
printf("*****\n");
}
void printPattern(char ch) {
switch (ch) {
case 'A':
printA();
break;
case 'B':
printB();
break;
case 'C':
printC();
break;
case 'D':
printD();
break;
case 'E':
printE();
break;
default:
printf("Pattern not available for the given character.\n");
}
}
int main() {
char ch;
printPattern(ch);
return 0;
}