0% found this document useful (0 votes)
20 views11 pages

Normal

The document contains multiple C code snippets demonstrating various programming concepts, including printing patterns with stars and numbers, calculating powers and factorials, and solving quadratic equations. Each code snippet includes user input for the number of rows or values and outputs results based on the logic implemented. The examples illustrate basic control structures such as loops and conditional statements in C.

Uploaded by

antillucifer765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views11 pages

Normal

The document contains multiple C code snippets demonstrating various programming concepts, including printing patterns with stars and numbers, calculating powers and factorials, and solving quadratic equations. Each code snippet includes user input for the number of rows or values and outputs results based on the logic implemented. The examples illustrate basic control structures such as loops and conditional statements in C.

Uploaded by

antillucifer765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Code

#include <stdio.h>

int main() {

int i, j, rows;

char ch = '*';

printf("Enter number of rows: \n");

scanf("%d", &rows);

for(i = 1; i <= rows; i++) {

for(j = 1; j <= i; j++) {

printf("%c", ch);

printf("\n");

return 0;

}
CODE
#include <stdio.h>

int main() {

int i, j, rows;

int num = 1;

printf("Enter number of rows: \n");

scanf("%d", &rows);

for(i = 1; i <= rows; i++) {

for(j = 1; j <= i; j++) {

printf("%d ", num);

num++;

printf("\n");

return 0;

}
code
#include <stdio.h>

int main() {

int i, j, rows;

int num = 1;

printf("Enter number of rows: \n");

scanf("%d", &rows);

for(i = 1; i <= rows; i++) {

for(j = 1; j <= i; j++) {

printf("%d ", num);

num++;

printf("\n");

return 0;

}
code
#include <stdio.h>

int main() {

int i, j, rows;

int num;

printf("Enter number of rows: \n");

scanf("%d", &rows);

for(i = 1; i <= rows; i++) {

num = 1; // Reset num to 1 before each row

for(j = 1; j <= i; j++) {

printf("%d ", num);

num++;

printf("\n");

return 0;

}
code
#include <stdio.h>

int main() {

int i, j, k, rows;

int num = 1;

printf("Enter number of rows: \n");

scanf("%d", &rows);

for(i = 1; i <= rows; i++) {

for(k = rows; k > i; k--) {

printf(" ");

for(j = 1; j <= i; j++) {

printf("%d ", num);

num++;

num = 1;

printf("\n");

return 0;

}
CODE
#include <stdio.h>

int main() {

int i, j, k, rows;

char ch = '*';

printf("Enter number of rows: \n");

scanf("%d", &rows);

for(i = 1; i <= rows; i++) {

for(k = rows; k > i; k--) {

printf(" ");

for(j = 1; j <= i; j++) {

printf("%c ", ch);

printf("\n");

return 0;

}
code
#include <stdio.h>

int power() {

int a, b, i;

int result = 1;

printf("Enter the number: \n");

scanf("%d", &a);

printf("Enter the power of the number: \n");

scanf("%d", &b);

for(i = 1; i <= b; i++) {

result *= a;

return result;

int main() {

int result;

result = power();

printf("The result of your number raised to the power is %d", result);

return 0;

}
code
#include <stdio.h>

int factorial() {

int a, i;

int result = 1;

printf("Enter the number to find factorial: \n");

scanf("%d", &a);

for (i = 1; i <= a; i++) {

result *= i;

return result;

int main() {

int result;

result = factorial();

printf("Factorial of your number is %d", result);

return 0;

}
code
#include <stdio.h>

int factorial(int n) {

if (n == 0 || n == 1) {

return 1;

} else {

return n * factorial(n - 1);

int main() {

int num, result;

printf("Enter a number to find factorial: ");

scanf("%d", &num);

if (num < 0) {

printf("Factorial is not defined for negative numbers.\n");

} else {

result = factorial(num);

printf("Factorial of %d is %d\n", num, result);

return 0;

}
code
#include <stdio.h>

#include <math.h>

void quadratic() {

int a, b, c;

printf("ax^2 + bx + c = 0\nEnter the values of a, b, and c respectively:\n");

scanf("%d%d%d", &a, &b, &c);

float d = b * b - 4 * a * c;

if (d == 0) {

printf("Roots of this equation are real and same.\n");

float root = -b / (2.0 * a);

printf("Root: %.2f\n", root);

} else if (d > 0) {

printf("Roots of this equation are real and different.\n");

float root1 = (-b + sqrt(d)) / (2.0 * a);

float root2 = (-b - sqrt(d)) / (2.0 * a);

printf("Roots: %.2f and %.2f\n", root1, root2);

} else {

printf("Roots of this equation are complex and imaginary.\n");

float realPart = -b / (2.0 * a);


float imagPart = sqrt(-d) / (2.0 * a);

printf("Roots: %.2f + %.2fi and %.2f - %.2fi\n", realPart, imagPart, realPart, imagPart);

int main() {

quadratic();

return 0;

You might also like