Interesting C programs: Some of the simple and innovative C programs are listed here. These C questions and answers have some interesting point on it. It is very basic source code and it is normally asked in various interviews and placement exams. Example C program codes are given below.
INTERESTING C PROGRAM QUESTIONS:
1) Write a C program to display the computers present date.
#include<stdio.h>
int main()
{
Printf(“Date from your computer: \n”);
// Display an Output
printf("%s",__DATE__);
return 0;
}
2) Write a C program to ADD two integer number values without using “PLUS” operator.
#include<stdio.h>
int main() // Main method
{
int x,y,add1;
printf("Give an input as any of 2 integer Numbers:");
scanf("%d%d",&x,&y);
add1=x-~y-1;
printf("Addition of 2 integer values are:"%d", add1);
return 0;
}
3) Write an example code in C to add two integer values without using Plus (+) operator
#include<stdio.h>
void main()
{
int x,y,add1; // Variables
printf("Give an input values of any 2 integers:");
// Input getting function
scanf("%d%d",&x,&y);
add1=x+~y+1;
printf("Diff., of 2 integer values:%d",add1);
}
4) Write a C code to display the source code of a particular file content as output.
#include<stdio.h>
// Main method
void main()
{
FILE *ks;
char jj;
ks=fopen(__FILE__,"r");
do
{
jj= getc(ks);
putchar(jj);
}
while(jj!=EOF);
fclose(ks);
}
5) Write an example C Program to display the system’s current date & time as output.
// Header files
#include<stdio.h>
#include<time.h>
#include<conio.h>
// Main method definition
int main()
{
time_t V;
time(&V);
clrscr(); // Clear previous O/P screen.
// Display an output
printf("System’s current Date n Time:%s",ctime(&V));
getch();
return 0;
}