The document contains a C programming assignment with seven tasks, each requiring the creation of specific patterns or functionalities using C code. Tasks include creating pyramid and diamond patterns, calculating powers without using the pow() function, reversing a number, and printing hollow rectangles. Each task is accompanied by sample code demonstrating the required functionality.
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 ratings0% found this document useful (0 votes)
10 views7 pages
Asssignment 5
The document contains a C programming assignment with seven tasks, each requiring the creation of specific patterns or functionalities using C code. Tasks include creating pyramid and diamond patterns, calculating powers without using the pow() function, reversing a number, and printing hollow rectangles. Each task is accompanied by sample code demonstrating the required functionality.
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/ 7
C PROGRAMMING ASSIGNMENT
ASSIGNMENT NO 5 AYUSHI SINGH 20243071
1.Write a Program to create a pyramid pattern using C.
#include<stdio.h> int main(){ int i,j,n; printf("enter no of rows\n"); scanf("%d",&n); for(i=0;i<=n;i++) {for(j=0;j<=n-i;j++) {printf(" ");} for(j=n-i;j<=n;j++) {printf("* ");} printf("\n"); } return 0; } 2 Write a program to Print Half half-pyramid pattern. #include<stdio.h> int main(){ int i,j,n; printf("enter no of rows\n"); scanf("%d",&n); for(i=1;i<=n;i++) {for(j=1;j<=i;j++) {printf("%d",i);} printf("\n"); } return 0; } 3.Write a program to find the value of one number raised to the power of another number (do not use pow() function). #include<stdio.h> int main(){ int n1, n2,i,result; printf("enter number\n"); scanf("%d", &n1); printf("enter power\n"); scanf("%d",&n2); result=1; for(i=1;i<=n2;i++){ result=result*n1; } printf("%d", result); return 0; } 4 Write a program that repeatedly asks the user for input until a specific value is entered to break the loop. #include<stdio.h> int main(){ int n; printf("enter number\n"); scanf("%d",&n); while(n!=7){ printf("enter number\n"); scanf("%d",&n);} return 0; } 5 Write a program to obtain the reversed number of a given number. maximum digits in number are 7. #include<stdio.h> int main(){ int n,rem,r=0; printf("enter number\n"); scanf("%d",&n); while(n<=10000000 && n!=0) { rem=n%10; r=r*10+rem; n/=10; } printf("reversed number:%d",r); return 0; } 6 Write a program to print a diamond pattern of stars. #include <stdio.h> int main() { int i, j, n; printf("Enter the number of rows: "); scanf("%d", &n); for(i = 1; i <= n; i++) { for(j = i; j < n; j++) { printf(" "); } for(j = 1; j <= (2*i - 1); j++) { printf("*"); } printf("\n"); } for(i = n - 1; i >= 1; i--) { for(j = n; j > i; j--) { printf(" "); } for(j = 1; j <= (2*i - 1); j++) { printf("*");} printf("\n"); } return 0; } 7. Write a program to print a hollow rectangle pattern using stars. #include <stdio.h> int main() { int i, j, rows, columns; printf("Enter the number of rows: "); scanf("%d", &rows); printf("Enter the number of columns: "); scanf("%d", &columns); for(i = 1; i <= rows; i++) { for(j = 1; j <= columns; j++) { if(i == 1 || i == rows || j == 1 || j == columns) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0; }
Get The Student Details Like Name, Dept, m1, m2, m3. Find The Average and Grade of The Student (O, A, B, C) - Using Switch Case Convert The Grade Into O-Excellent, A - Good, B-Average, C-Fair