1. A simple program for printing a line of text
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { printf("Hello this is my first C program"); getch(); // Linux user - Remove this return 0; }
2. Program to input integer number and display it
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { // variable to take input int n; printf("Enter any number "); scanf("%d",&n); printf("Input number=%d",n);
// holds the output screen defined in header file conio.h getch(); // Linux user - Remove this return 0; }
3. Program to add, subtract, multiply and divide two numbers
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { int a, b; printf("Enter any two number "); scanf("%d",&a); scanf("%d",&b); printf("Sum=%d",a+b); printf("\nSubtracted value=%d",a-b); printf("\nMultiplied value=%d",a*b); printf("\n Division value=%d",a/b); getch(); // Linux user - Remove this return 0; }
4. Program to subtract two numbers without using arithmetic operators ( - )
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { int a, b, r; printf("Enter any two number "); scanf("%d",&a); scanf("%d",&b); r=a+(~b)+1; printf("Subtracted value=%d", r); getch(); // Linux user - Remove this return 0; }
5. Program to find the greatest between 3 integers( numbers ) using ternary or conditional operator
#include<stdio.h>#include<conio.h> // Linux user - Remove this int main() { // Variable for 3 integers and for storing greatest integer int a, b, c, g; // Inputting integers printf("Enter three integers:"); scanf("%d %d %d",&a,&b,&c); // Determining the greatest integer using ternary or conditional operator g=(a>b && b>c) ? a : (b>c && b>a) ? b : (c>a && c>b) ? c : 0; // displaying greatest value if(g!=0) printf("Greagest integer: %d",g); else printf("None is greatest: Two integers have same value" ); getch();// Linux user - Remove this return 0; }