Posts

Showing posts from July, 2020

C program leap year finder

Image
#include<stdio.h> int main(){ int year; printf("enter the year = "); scanf("%d",&year); if (year % 400 == 0){ printf(" %d is a leap year",year); } else if (year % 100 == 0){ printf("%d is a leap year",year); } else if(year%4==0){ printf("%d is a leap year",year); } else { printf("%d is not a leap year",year); } printf("\n"); main(); }

c program discount calculater

Image
#include<stdio.h> int main(){ int amount; printf("enter the amount=\n"); scanf("%d", &amount); int discount; printf("enter the discount percentage="); scanf("%d",&discount); int savings = amount*discount/100; printf("your savings=%d\n",savings); printf("now you have to pay =rs %d",amount-savings); }

c program tables making

Image
#include<stdio.h> int main (){ int num; printf("which table do you want \n>>"); scanf("%d",&num); printf(" ===%d===\n",num); for (int i =1;i<=10;i++){ printf("%d × %d = %d\n",num,i,num*i); } main(); }

c program number guessing game

Image
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <stdbool.h> int randomnum; int userinput; void generate() { srand(time(NULL)); randomnum = 1 + rand() % 10; } void welcomemeg() { printf("welcome to number guessing game \n"); printf("type number between 1-10\n>>"); generate(); scanf("%d", &userinput); } int main() { bool isgameover = false; welcomemeg(); while(! isgameover) { if (userinput < randomnum) { printf("try some thing big\n"); scanf("%d", &userinput); } else if (userinput > randomnum) { printf("try some thing small\n"); scanf("%d", &userinput); } else { printf("you won the game\n"); printf("try again by typing y or just click enter to exit\n");   getchar(); char userchoice; char y; scanf("%c",&y); userchoice = getchar(); ...

C program using of struct example

Image
#include<stdio.h> #include<string.h> int main(){ struct fruits{ char name[20]; float rate; int quantity; }; struct fruits fruit1,fruit2; strcpy(fruit1.name ," apple");    fruit1.rate= 5.10; fruit1.quantity= 200; strcpy(fruit2.name ," banana");    fruit2.rate= 10.10; fruit2.quantity= 100; printf("name of fruit is = %s \n",fruit1.name); printf("rate of fruit is = Rs.%.2f \n",fruit1.rate); printf("quantity of fruit is = %d \n",fruit1.quantity); printf("name of fruit is = %s \n",fruit2.name); printf("rate of fruit is = Rs.%.2f \n",fruit2.rate); printf("quantity of fruit is = %d \n",fruit2.quantity); }

C program sentence copy maker

Image
#include<stdio.h> int main(){ char *word[40]; int op; printf("welcome to copy making\n"); printf("enter the word to print many times\n>>"); scanf("%[^\n]s",word); printf("how many times do you want to print\n>>"); scanf("%d",&op); for(int i =1;i <=op; i++){ printf("%s\n",word); } main(); }

C program calculater

Image
#include <stdio.h> int dclare; int num1; int num2; void option() { printf("for ' + ' type 1\n for ' - ' type 2 \n for ' * ' type 3\n"); scanf("%d", &dclare); }  void option2() { switch (dclare) { case 1: printf("=%d", num1 + num2); break; case 2: printf("=%d", num1 - num2); break; case 3: printf("=%d", num1 * num2); break; default: printf("enter again"); break; } } int main() { printf("\nenter the first number\n>>"); scanf("%d", &num1); printf("enter the second number\n>>"); scanf("%d", &num2); option(); option2(); main(); }