Write a program to evaluate the series 1^2+2^2+3^2+……+n^2
#include<stdio.h>int main() {int n, i, sum = 0;printf("\n Enter Value of n : ");scanf("%d", & n);for (i = 1; i <= n; i++) {sum = sum + (i * i);}printf("\n Sum of Series = %d", sum);return 0;}
Write a C program to find 1+1/2!+1/3!+1/4!+.....+1/n!.
#include <stdio.h>int main(){int n, i, j, fact = 1;float sum = 0;printf("\n Enter Value of n : ");scanf("%d", &n);for (i = 1; i <= n; i++){fact = 1;for (j = i; j > 0; j--){fact = fact * j;}sum = sum + (1.0 / fact);}printf("\n Sum of Series = %f", sum);return 0;}
Write a C program to print following patterns :
i * ii * iii *****
* * * * ****
* * * * * * ***
* * * * * * * * **
* * * * * * * * * * *
(i)
#include <stdio.h>int main(void){int i, j;for (i = 0; i < 5; i++){for (j = 0; j <= i; j++){printf(" *");}printf("\n");}return 0;}
(ii)
#include <stdio.h>int main(void){int i, j;for (i = 0; i < 5; i++){for (j = i + 1; j < 5; j++){printf(" ");}for (j = 0; j <= i; j++){printf(" *");}printf("\n");}return 0;}
(iii)
#include <stdio.h>int main(void){int i, j;for (i = 0; i < 5; i++){for (j = 0; j < i; j++){printf(" ");}for (j = i; j < 5; j++){printf("*");}printf("\n");}return 0;}
Write a C program to display following patterns.
1.
12345
1234
123
12
1
#include <stdio.h>int main(){int i, j;for (i = 0; i < 5; i++){for (j = 0; j < 5 - i; j++){printf("%d", j + 1);}printf("\n");}return 0;}
2.
AAAAA
AAAA
AAA
AA
A
#include <stdio.h>int main(void){int i, j;for (i = 0; i < 5; i++){for (j = 0; j < 5 - i; j++){printf("%c", 'A');}printf("\n");}return 0;}
3.
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
0 Comments