Cheat Sheet For Conttest

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

int limit, common_diff, term, sum = 0

//sum using for-loop


printf("Enter the limit of the series: ");
scanf("%d", &limit);

printf("Enter the common difference: ");


scanf("%d", &common_diff);

printf("\nUsing for loop:\n");


for (term = 1; term <= limit; term++) {
sum += term * common_diff;
}
printf("Sum of the series: %d\n", sum);
//sum using while-loop
printf("\nUsing while loop:\n");
term = 1;
sum = 0;
while (term <= limit) {
sum += term * common_diff;
term++;
}
printf("Sum of the series: %d\n", sum);
//sum using do-while loop
printf("\nUsing do-while loop:\n");
term = 1;
sum = 0;
do {
sum += term * common_diff;
term++;
} while (term <= limit);
printf("Sum of the series: %d\n", sum);
//printing even numbers
for(i=1; i<n; i++) //n is input
{
if(i%2 == 0)
{
printf(“%d”, n);
}
}

//printing uneven/odd numbers


for(i=1; i<n; i+=2) //n is input
{
printf(“%d”, n);
}

//finding a term in a series


For arithmetic series: a+(n-1)d
For geometric series: a x r^(n-1)

//arranging 3 terms in descending order with a as greatest term


If (a<b)
{
Temp = a;
a=b;
b= temp;
}
if(b<c)
{
Temp = b;
b=c;
c= temp;
}
If (a<b)
{
Temp = a;
a=b;
b= temp;
}

//Bhaskara’s formula:

//trapezium formula:

//selection sort:
selectionSort(arr, n);

printf(“Sorted array: “);


printArray(arr, n);

You might also like