Skip to main content

Posts

Showing posts from May, 2017

Program That Reads & Sums Data Values Until A Negative Value Is Read [C Programming]

#include<stdio.h> int main() {     int i, sum=0;     while(1)     {         printf("Enter a number: ");         scanf("%d", &i);         if(i>=0)         {             sum += i;         }         else         {             break;         }     }     printf("Sum : %d", sum);     return 0; }

Program to Read The Age of n Persons & Count The Number of Persons Who Are Not in The Age Group 50-60 [C Programming]

#include<stdio.h> int main() {     int i, n, age, count=0;     printf("How many person's age do you want to insert?\n");     scanf("%d", &n);     for(i=1; i<=n; i++)     {         printf("Enter age of person %d: ", i);         scanf("%d", &age);         if(age < 50 || age > 60)         {             count++;         }     }     printf("\nNumber of person(s) who are not in age group 50 - 60 is: %d", count);     return 0; }

Factorial of A Number [C Programming]

#include<stdio.h> int main() {     int i, n, factorial=1;     printf("Enter an integer: ");     scanf("%d", &n);     if(n<0)     {         printf("Factorial of a negative number doesn't exist!");     }     else     {         for(i=1; i<=n; i++)         {             factorial *= i;         }         printf("Factorial of %d is: %d", n, factorial);     }     return 0; }

Classroom Numbers of AIUB [C Programming]

Problem description:  Consider the room numbers of our campus - 423, 432, 441, 234, 534, 132. Here first digit represents campus number, second digit represents floor number and the third number represents room number in that floor. Write a program that will take a three digit number (like 423) and output the Campus, Floor, and Room Number according to the input. INPUT: 423 OUTPUT: Campus 4, Floor 2, Room 3 Code: #include <stdio.h> int main() {     int n, campus, floor, room;     printf("Enter a room number: ");     scanf("%d", &n);     room = n%10;     floor = ((n - room)%100)/10;     campus = n/100;     printf("Campus %d, Floor %d, Room %d", campus, floor, room);     return 0; }

Write A Program That Receives 5 Numbers & Output The Sum & Average of These Numbers [C Programming]

#include <stdio.h> int main() {     float i, n, sum=0, avg;     for(i=0; i<5; i++)     {         printf("Enter a number: ");         scanf("%f", &n);         sum = sum + n;     }     avg = sum / 5;     printf("Sum: %0.2f\n", sum);     printf("Average: %0.2f", avg);     return 0; }

Currency Converter - USD & BDT [C Programming]

#include <stdio.h> void main() {     int i;     float usd, bdt;     printf("Press 1 to convert USD to BDT\nPress 2 to convert BDT to USD\n");     printf("Enter your choice: ");     scanf("%d", &i);     switch(i)     {         case 1:             printf("Enter amount in USD: ");             scanf("%f", &usd);             bdt = usd * 80;             printf("1 USD = 80 BDT\n");             printf("%0.3f USD = %0.3f BDT", usd, bdt);             break;         case 2:   ...

Positive Or Negative Number? [C Programming]

#include <stdio.h> void main() {     int i;     printf("Enter an integer: ");     scanf("%d", &i);     if(i == 0)     {         printf("%d is Zero", i);     }     else if(i>0)     {         printf("%d is Positive", i);     }     else     {         printf("%d is Negative", i);     } }

Odd Or Even Number? [C Programming]

#include <stdio.h> void main() {     int i;     printf("Enter an integer: ");     scanf("%d", &i);     if(i%2 == 0)     {         printf("%d is even", i);     }     else     {         printf("%d is odd", i);     } }

Greater Or Less Than 100? [C Programming]

#include <stdio.h> void main() {     int i;     printf("Enter an integer: ");     scanf("%d", &i);     if(i>100)     {         printf("%d is greater than 100", i);     }     else if(i<100)     {         printf("%d is less than 100", i);     }     else     {         printf("%d is equal to 100", i);     } }

Leap Year [C Programming]

#include <stdio.h> void main() {     int year;     printf("Enter year: ");     scanf("%d", &year);     if((year%4==0 && year%100!=0) || (year%4==0 && year%100==0 && year%400==0))     {         printf("%d is leap year", year);     }     else     {         printf("%d is NOT leap year", year);     } }

Greatest Value Among Three Numbers [C Programming]

#include <stdio.h> void main() {     int a, b, c;     printf("Enter a number in a:");     scanf("%d", &a);     printf("Enter a number in b:");     scanf("%d", &b);     printf("Enter a number in c:");     scanf("%d", &c);     if(a >= b && a >= c) // a > b, a > c     {         printf("%d is largest", a);     }     else if(b >= a && b >= c) // b > a, b > c     {         printf("%d is largest", b);     }     else if(c >= a && c >= b) // c > a, c > b     {         printf("%d is largest", c);     } }

Mark to Letter Grade Converter [C Programming]

#include <stdio.h> void main() {     float a;     printf("Enter marks: ");     scanf("%f", &a);     printf("Grade: ");     if(a >= 90.0) printf("A+");     else if(a >= 80.0) printf("A");     else if(a >= 75.0) printf("B+");     else if(a >= 70.0) printf("B");     else if(a >= 65.0) printf("C+");     else if(a >= 60.0) printf("C");     else if(a >= 55.0) printf("D+");     else if(a >= 50.0) printf("D");     else printf("F"); }

Take Integer, Float, Character as Input & Print Them in Console [C Programming]

#include <stdio.h> void main() {     char ch;     int i;     float f;     printf("Enter a character: ");     scanf("%c", &ch);     printf("Enter an integer: ");     scanf("%d", &i);     printf("Enter a fraction number: ");     scanf("%f", &f);     printf("Character: %c\nInteger: %d\nFloat: %f", ch, i, f); }