Skip to main content

Posts

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; }