Question 1. Write a C program to get the C version you are using.
Solution :
#include <stdio.h>
int main(int
argc, char** argv)
{
#if
__STDC_VERSION__ >= 201710L
printf("We are using C18!\n");
#elif
__STDC_VERSION__ >= 201112L
printf("We are using C11!\n");
#elif
__STDC_VERSION__ >= 199901L
printf("We are using C99!\n");
#else
printf("We are using C89/C90!\n");
#endif
return 0;
}
you see the solution on the compilerQuestion 2. Write a C program that take input from user and print it on output.
Solution :
#include <stdio.h>
int main()
{
int num;
printf("\n\t---------X-------X--------X--------");
printf("\n\tEnter the number : ");
scanf("%d",&num);
printf("\n\tThe number is : %d",num);
printf("\n\t---------X-------X--------X--------\n");
return 0;
}
Question 3. Write a C program to print the 'X' 'Y' 'Z' in reverse order.
Solution:
int main()
{
char char1 = 'X';
char char2 = 'Y';
char char3 = 'Z';
printf("The
reverse of %c%c%c is %c%c%c\n",
return(0);
}
you see the solution on the compiler
Question 4. Write C program to convert number 1329 into years, week, and days
#include <stdio.h>
int main()
{
int days, years, weeks;
days = 1329;
// Converts days to years, weeks and days
years = days/365;
weeks = (days % 365)/7;
days = days- ((years*365) + (weeks*7));
printf("Years: %d\n", years);
printf("Weeks: %d\n", weeks);
printf("Days: %d \n", days);
return 0;
}
you see the solution on the compiler
Question 5. Write a program that accepts values from the user and then print their sum.
#include <stdio.h>
int main()
{
int
x, y, sum;
printf("\nInput the first integer: ");
scanf("%d", &x);
printf("\nInput the second integer: ");
scanf("%d", &y);
sum = x + y;
printf("\nSum of the above two integers = %d\n", sum);
Question 6. Write the C program to convert the amount (in integer) in the smallest possible bank notes.
#include <stdio.h>
int main()
{
int amt, total;
printf("Input the amount: ");
scanf("%d",&amt);
total = (int)amt/100;
printf("There are: ");
printf("\n%d Note(s) of 100.00\n", total);
amt = amt-(total*100);
total = (int)amt/50;
printf("%d Note(s) of 50.00\n", total);
amt = amt-(total*50);
total = (int)amt/20;
printf("%d Note(s) of 20.00\n", total);
amt = amt-(total*20);
total = (int)amt/10;
printf("%d Note(s) of 10.00\n", total);
amt = amt-(total*10);
total = (int)amt/5;
printf("%d Note(s) of 5.00\n", total);
amt = amt-(total*5);
total = (int)amt/2;
printf("%d Note(s) of 2.00\n", total);
amt = amt-(total*2);
total = (int)amt/1;
printf("%d Note(s) of 1.00\n", total);
return 0;
}
0 Comments
If you are a good learner please leave a challenging question on comment box for us when you visited this website ( Coding with Fun).