Posts

Showing posts with the label for

In C, Prompt User And Draw Box By Given Characters, Height And Width

Image
#include<stdio.h> void main(){ int i, j, wd, hg; char hc, vc, ch; do{ fflush(stdin); printf("Enter horizontal & vertical character: "); scanf("%c %c", &hc, &vc); fflush(stdin); printf("Enter height & width: "); scanf("%d %d", &hg, &wd); printf("Using brutal force: \n"); for(i=wd;i;i--) printf("%c", hc); printf("\n"); for(i=hg-2;i;i--){ printf("%c",vc); for(j=wd-2;j;j--) printf(" "); printf("%c\n", vc); } for(i=wd;i;i--) printf("%c", hc); printf("\n"); fflush(stdin); printf("\nContinue [y/n]: "); scanf("%c", &ch); }while('y' == ch || 'Y' == ch); } Download

Counting vowels in a string with C Sharp

Image
using System; public class CountVowels{ public static void Main(string[]args){ Console.Write("Enter a phrase: "); string line = Console.ReadLine(); if(null == line){ Console.WriteLine("\nError: Missing input phrase!"); return; } int vowels = 0; foreach(char c in line){ switch(c){ case 'a': case 'e': case 'i': case 'o': case 'u': case 'A': case 'E': case 'I': case 'O': case 'U': vowels ++; break; } } Console.WriteLine("{0} vowels found in phrase: \"{1}\"", vowels, line); } } Download

⚡ Cpp Program 🔥 Artist album tracks #tecqmate

Image
#include<iostream> #include<fstream> #include<string> #include<iomanip> using namespace std; int main(){ ifstream in("namedalbuminfo.txt"); if(!in){ cerr << "Failed to load input file!" << endl; return 1; } ofstream out("namedtracklist.txt"); string line; int hours, mins, sum_hrs = 0, sum_mins = 0, count = 0, diff; getline(in, line); out << "Album title: " << line << endl; getline(in, line); out << "Artist: " << line << endl; cout << "Welcome to 's tracklist generator!" << endl; out << "Tracks:" << endl; out << "--------------------------------------------------" << endl; while(!in.eof()){ count ++; getline(in, line); in >> hours >> mins; in.ignore(); out << setfill('0') << setw(2) << count; out << " - " <...

⚡ C Programming 🔥 Ninja's Shopping #tecqmate

Image
#include<stdio.h> void main(){ int shops; printf("How many shops will you be visiting? "); fflush(stdin); scanf("%d", &shops); int inds, shop; float cost, sum, min = 0.0f; for(int i = 1, j; shops >= i; i++){ printf("You are at shop #%d. How many ingredients do you need at shop #%d? ", i, i); scanf("%d", &inds); sum = 0.0f; for(j = 1; inds >= j; j ++){ printf("How much is ingredient #%d? ", j); scanf("%f", &cost); sum += cost; } if(1 == i || min > sum){ min = sum; shop = i; } printf("Your total at shop #%d is $%.2f.\n", i, sum); } printf("Your cheapest order was at shop #%d and cost $%.2f.\n", shop, min); }