This is a ReadMe file for SPI Apprenticeship Program 2023-24 (C language)
Q1.
WAP to input two numbers and perform the following operation on them: +, -, /, *, %.
Click here to see the answer!
Q2.
WAP to input time in seconds and convert it into minutes and seconds.
Click here to see the answer!
Q3.
WAP to enter time in seconds and convert it into hours, minutes, and seconds.
Click here to see the answer!
Q4.
WAP to enter days and display output in years, months, and days.
Click here to see the answer!
Q5.
WAP to enter days and display output in years, months, weeks, and days.
Click here to see the answer!
Q6.
WAP to input age and check if you are eligible for voting or not.
Click here to see the answer!
Q7.
WAP to input a number and check if itโs even or odd number; use if-else.
Click here to see the answer!
Q8.
WAP to input two numbers and check if the number is greater or equal to the other number.
Click here to see the answer!
Q9.
WAP to input two numbers and check if a number is greater than the other number or not.
Click here to see the answer!
Q10.
WAP to print week days like Sunday, Monday, etc; use if-else.
Click here to see the answer!
main()
What will happen if we leave the main()
function empty and run it? \
Source Code:
main(){
}
Click here to check the output!
In the given code, this line will through a garbage value.
Source code:
#include <stdio.h>
void main(){
int num;
printf("%d is a number");
scanf("%d", &num);
}
Click here to check the output
ERROR:
Reason is that this statement is missing a parameter to display the variable value, to replace %d
printf("%d is a number");
FIX:
printf("d is a number", num);
In the given code the program will take two integer input and then is expected to take character input, but something else happens when running this code.
ERROR:
This is some kind of compiler error or C language bug in latest version of C.
int num1, num2;
printf("\nEnter first number: ");
scanf("%d", &num1);
printf("\nEnter second number: ");
scanf("%d", &num2);
//operation choice
char choice;
printf("\n Select the operation to perform: ");
scanf("%c",&choice);
Click here to check the output
FIX:
Taking the character input before any integer input will fix this issue. Just change the position of statements used to take inputs.
//operation choice
char choice;
printf("\n Select the operation to perform: ");
scanf("%c",&choice);
int num1, num2;
printf("\nEnter first number: ");
scanf("%d", &num1);
printf("\nEnter second number: ");
scanf("%d", &num2);