#include <stdio.h>
int main()
{
int num1, num2;
printf("Enter the two integer numbers : ");
scanf("%d %d", &num1, &num2);
if (num1 == num2)
printf("nThe two numbers are equal.n");
else
printf("nThe two numbers are not equal.n");
}
Output 1:
Enter the two integer numbers :
10
10
The two numbers are equal.
Output 2:
Enter the two integer numbers :
10
11
The two numbers are not equal.
Computer Science » C Program » Check Whether a Number is Palindrome or Not Program : [php]#include <stdio.h> int main() { int n, reversedN = 0, remainder, originalN; printf("nEnter an integer : "); scanf("%d", &n); originalN = n; // reversed integer is stored in reversedN while (n != 0) { remainder = n % 10; reversedN = reversedN * 10 + remainder; n /= 10; } // palindrome if orignalN and reversedN are equal if (originalN == reversedN) printf("n%d is a palindrome.", originalN); else printf("n%d is not a palindrome.", originalN); return 0; }[/php] Output 1: [php]Enter an integer: 101 101 is a palindrome.[/php] Output 2: [php]Enter an integer: 102 102 is not a palindrome.[/php]
Computer Science » C Program » Rectangle using Line and Special Symbols Program : [php]#include<stdio.h> int main() { int i, j; for (i = 0; i < 10; i++) { printf("n"); for (j = 0; j < 10; j++) { if (i == 0 || i == 9 || j == 0 || j == 9) printf("▲"); else printf("-"); } } return (0); }[/php] Output : [php]▲▲▲▲▲▲▲▲▲▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲--------▲ ▲▲▲▲▲▲▲▲▲▲[/php]
Computer Science » C Program » Print First 10 Natural Numbers Program : [php]#include<stdio.h> int main() { printf("1"); printf("2"); printf("3"); printf("4"); printf("5"); printf("6"); printf("7"); printf("8"); printf("9"); printf("10"); }[/php] Output : [php]12345678910[/php] Program : [php]#include<stdio.h> int main() { int i = 1; for (i = 1; i <= 10; i++) { printf("%d", i); } return (0); }[/php] Output : [php]12345678910[/php] Program : [php]#include<stdio.h> int main() { int i = 1; while (i <= 10) { printf("%d", i); i++; } return (0); }[/php] Output : [php]12345678910[/php] Program : [php]#include<stdio.h> int main() { int i = 1; do { printf("%d", i); i++; } while (i <= 10); return (0); }[/php] Output : [php]12345678910[/php] Program : [php]#include<stdio.h> int main() { int i = 0; Start: i = i + 1; printf("%d", i); if (i < 10) goto Start; }[/php] Output : [php]12345678910[/php]
Computer Science » C Program » Find Average of Two Numbers Program : [php]#include <stdio.h> int main() { int num1, num2; float avg; printf("nEnter first number : "); scanf("%d",&num1); printf("nEnter second number : "); scanf("%d",&num2); avg= (float)(num1+num2)/2; printf("nAverage of %d and %d is : %f",num1,num2,avg); return 0; }[/php] Output : [php]Enter first number : 5 Enter second number : 3 Average of 5 and 3 is : 4.00[/php]
Computer Science » C Program » Check Whether a Number is Prime or Not Program : [php]#include<stdio.h> int main() { int num, i, count = 0; printf("nEnter a number :"); scanf("%d", &num); for (i = 2; i <= num / 2; i++) { if (num % i == 0) { count++; break; } } if (count == 0) printf("n%d is a prime number.", num); else printf("n%d is not a prime number.", num); return 0; }[/php] Output 1: [php]Enter a number : 5 5 is a prime number.[/php] Output 2: [php]Enter a number : 4 4 is not a prime number.[/php]