Skip to main content

Posts

C program to print Mario game Pyramid .

#include<stdio.h> #include<cs50.h> int main() {     int n ; //declaring a n variable     int i, j, k;     do      //do while loop     {         n = get_int("Height: "); //taking input from the user     }     while (n < 1 || n > 8); //checking condition     for (i = 1; i <= n; i++) //for loop for printing pyramid of blocks     {         for (j = i; j < n; j++)         {             printf(" ");         }         for (k = 1; k <= i; k++)         {             printf("#");         }         printf("  ");         for (k = 1; k <= i; k++)         {             printf("#");         }         printf("\n");     } } Output: Height: 8         #  #       ##  ##      ###  ###     ####  ####    #####  #####   ######  ######  #######  ####### ########  ########
Recent posts

A Program to find day by entering date, month and year.

→ A C++ program by me in which you can get the day of any given date. I have written this code by using some mathematical formulas of finding day using a given date, if you find any error or if you want to give me any suggestion then please let me know. #include<iostream> using namespace std; int main() { int date,month,year; int yc,mc,cc,dn,lyc; cout<<"Enter Date, Month and Year to know the Day:"; cin>>date>>month>>year; if(month>12 || date>31) { cout<<"Wrong input"; } else{ //for year int h=year%100; yc=(h+(h/4))%7; //for leap year if(year%4 ==0) { if(year%100 ==0) { if(year%400 == 0) { lyc=1; } } else { lyc=1; } } if(lyc==1) { if(month>2) { lyc=0; } else { lyc=1; } } //for month if(month==01 || month ==10) { mc=0; } else if(month==05) { mc=1; } else if(month==8) { mc=2; } else if(

How to use array.

→ This program will help you to learn how to implement an array in C. #include<stdio.h> int main() {   int arr[5]; //declaration of an array with maximum five values   int i;   printf("Enter five numbers:");   for(i=0;i<5;i++)   {      scanf("%d",&arr[i]);  //This line will take input in array from index zero to five i.e arr[0] to arr[4]   }   printf("Your numbers are:");   for(i=0;i<5;i++)   {     printf("%d  ",arr[i]);   }   return 0; } Output: Enter five numbers:5 6 9 8 12 Your numbers are:5  6  9  8  12

A simple calculator program.

→ A simple calculator using C language. In this, you can add, multiply, divide and subtract any two number. #include<stdio.h> int main() {    float a,b,c;    char d;    printf("Enter:");    scanf("%f  %c %f",&a,&d,&b);    if(d=='+')    {     c=a+b;     printf("%.2f",c);    }    else if(d=='-')    {     c=a-b;     printf("%.2f",c);    }    else if(d=='*')    {     c=a*b;     printf("%.2f",c);    }    else if(d=='/')    {     c=a/b;     printf("%.2f",c);    } } Output: Enter:  9/4              2.25

C Program to take input from the user.

→ Program to take input from the user- integer, char, string, decimal, and to print all values. #include<stdio.h> int main() {   int a;   char b;   char c[10];   float d;   printf("Enter interger value:");   scanf("%d",&a);   printf("\nEnter a character:");   scanf(" %c",&b);   printf("\nEnter a name:");   scanf("%s",&c);   printf("\nEnter decimal value:");   scanf("%f",&d);   printf("\nInterger value is %d ",a);   printf("\nYour Character is %c ",b);   printf("\nGiven name is %s ",c);   printf("\nDecimal value is %f ",d);   return 0; }