- Write a program for display your name 50 times in C language.#include <stdio.h>int main(){for(int i=0; i<50; i++;){printf(“Suman Adhikari”);}return 0;}
- "Write a program that uses a “for” loop to compute and prints the sum of a given numbers of squares."#include <stdio.h>int main() {int n, sum = 0;// Prompt the user for inputprintf("Enter the number of terms: ");scanf("%d", &n);// Compute the sum of squares using a for loopfor(int i = 1; i <= n; i++) {sum += i * i;}// Print the resultprintf("The sum of the squares of the first %d natural numbers is: %d\n", n, sum);return 0;}
- "Write a program that uses a “while” loop to compute and prints the sum of a given numbers of squares. For example, if 4 is input, then the program will print 30, which is equal to 12+22+32+42.#include <stdio.h>int main() {int n, sum = 0, i = 1;// Input the number of squaresprintf("Enter the number of squares: ");scanf("%d", &n);// Compute the sum of squares using a while loopwhile (i <= n) {sum += i * i;i++;}// Print the resultprintf("Sum of squares: %d\n", sum);return 0;}
- Write a program that uses a “while” loop to compute and prints the sum of a given numbers of squares.For example, if 4 is input, then the program will print 30,which is equal to 12+22+32+42."#include <stdio.h>int main() {int n, sum = 0, i = 1;// Input the numberprintf("Enter the number of squares: ");scanf("%d", &n);// Compute the sum of squares using a while loopwhile (i <= n) {sum += i * i;i++;}// Print the resultprintf("Sum of squares: %d\n", sum);return 0;}
- Write a program to input string and display 20 times.#include <stdio.h>int main() {char str[100];int i;// Input the stringprintf("Enter a string: ");fgets(str, sizeof(str), stdin);// Display the string 20 timesfor (i = 0; i < 20; i++) {printf("%s", str);}return 0;}
0 Comments had been done yet:
Post a Comment