Simple Codes
Simple Codes
#include <stdio.h>
int main() {
int x = 10;
return 0;
}
Output:
The cube for 10 is 1000
int main() {
int n = 8;
return 0;
}
Output:
The square for 8 is 64
3) Average:
#include <stdio.h>
int main() {
int p = 2, q = 4, r = 6;
float s;
s = (p + q + r) / 3;
return 0;
}
Output:
The average of 2, 4, and 6 is: 4.00
int main() {
int n, i;
return 0;
}
Output:
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5) Swapping:
#include <stdio.h>
int main() {
int x = 5, y = 10, t;
t = x;
x = y;
y = t;
return 0;
}
Output:
Before swapping: x = 5, y = 10
After swapping: x = 10, y = 5
int main() {
int a, b, c;
c = a + b;
return 0;
}
Output:
Enter first no: 15
Enter second no: 10
Sum of 15 and 10 is 25
return 0;
}
Output:
1
1 2
1 2 3
int main() {
int r,i,j;
r = 3;
for(i = 1; i <= r; i++) {
for(j = 1; j <= r-i; j++)
printf(" ");
printf("\n");
}
return 0;
}
Output:
*
* *
* * *
int main()
{
int n;
printf("Enter any number n: ");
scanf("%d", &n);
//logic
if (n % 2 == 0) {
printf("No is even");
}
else {
printf("No is odd");
}
return 0;
}
Output:
Case 1: Enter any number n: 2
No is even
Output:
Enter a character*
Special symbol