Posts

Pattern #4

Image
Program: #include <stdio.h> void main() {     int i, j, k;          for(i=4;i>=0;i--)     {         for(k=1;k<=i;k++)         {             printf(" ");         }         for(j=k;j<=5;j++)         {             printf("*");         }         printf("\n");     } } Output:     *    **   ***  **** ***** Drafted on 🌏 by, Jal ☮ peace

Pattern #3

Image
Program: #include <stdio.h> void main() {     int i, j;          for(i=1;i<=5;i++)     {         for(j=1;j<=i;j++)         {             printf("%d",j);         }         printf("\n");     } } Output: 1 12 123 1234 12345 Drafted on 🌏 by, Jal ☮ peace

Pattern #2

Image
Program: #include <stdio.h> void main() {     int rows, i, j, number = 1;     printf("Enter the number of rows: ");     scanf("%d", &rows);     for (i = 1; i <= rows; i++)     {         for (j = 1; j <= i; ++j)         {             printf("%d ", number);             ++number;         }         printf("\n");     } } Output: 1 23 456 78910 Drafted on 🌏 by, Jal ☮ peace

Pattern #1

Image
Program: #include <stdio.h> void main() {     int i,j,k=5;          for(i=0;i<5;i++)     {         for(j=0;j<=i;j++)         {             printf("%d",k);             k--;         }         printf("\n");         k=5;     } } Output: 5 54 543 5432 54321 Drafted on 🌏 by, Jal ☮ peace

C program to write a string in the file

Program: #include<stdio.h> void main() {     char str[20]; FILE *out; out=fopen("file1.txt","w"); printf("Enter string: "); gets(str); fputs(str,out); fclose(out); } Output: Enter string: Hello World! Drafted on 🌏 by, Jal ☮ peace

C program to read and display information of N students using an array of structure

Program: #include<stdio.h> struct student {     char name[20];     int rollno;     float cpi; }; void main( ) {     int i,n;     printf("Enter how many records u want to store : ");     scanf("%d",&n);     struct student sarr[n];          for(i=0; i<n; i++)     {         printf("\nEnter %d record : \n",i+1);         printf("Enter Name : ");         scanf("%s",sarr[i].name);         printf("Enter RollNo. : ");         scanf("%d",&sarr[i].rollno);         printf("Enter CPI : ");         scanf("%f",&sarr[i].cpi);     }     printf("\n\tName\t\tRollNo\t\tMarks\t\n");          for(i=0; i<n; i++)     {         printf("\t%s\t\t%d\t\t%.2f\t\n", sarr[i].name,...

C program to read and display book information using structure

Program: #include<stdio.h> struct book {     char title[40];     int pages;     float price;     int ratings; }; int main() {     struct book book1;     printf("Enter Book Title: ");     gets(book1.title);     printf("Enter Book Pages:");     scanf("%d", &book1.pages);     printf("Enter Book Price:");     scanf("%f", &book1.price);     printf("Enter Book Ratings:");     scanf("%d", &book1.ratings);          printf("\nBook using simple structure variable.\n");     printf("Book Title: %s\n", book1.title);     printf("Book Pages: %d\n", book1.pages);     printf("Book Price: %f\n", book1.price);     printf("Book Ratings: %i\n", book1.ratings);  } Output: Enter Book Title: Life of pi Enter Book Pages:401 Enter Book Price:320 Enter Book Ratings:4 Book using simple structure vari...