Hello Guyz,
Welcome Again To My blog. readers, This Is Second Part Of "
Basic C programs Collection For NewBies". Click Here To Visit First Part. Today I am going To Share Some More Interesting C Programming Codes Wrote When I am newbie in C Programming. Really Very Basic C Program Code Written In C Language. I am Sharing These Codes, Because When i was new, these small codes really help me in Understand C Programming. I hope, these code will also help to new C Programming guys and Those who are just starting learning.
Tried To Implement Python Itertools Product Function In C
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Itertools Product
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Author : Suraj Singh Bisht
// Email : surajsinghbisht054@gmail.com
// Code : C
// Iter Tools Produnct Function
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
// function declearations
int wordlen(string words);
int forloop();
// main function
int main(){
double radius, area;
const float PI = 3.14159;
string words="0123456789";
int a=0,d=0,c=0, repeat=2;
string b="";
while (d<=repeat){
//for i in num:
//... print b,i
//... b=num[c]
//... c=c+1
//... d=len(str(b)+str(i))
//cout << words << endl;
// len
//
//cout << wordlen(words);
//forloop();
//
// Here Creating For i loop
// rough values
int lengthofwords=wordlen(words);
//
for (int x=0; x<lengthofwords; x++){
char raw=words[x];
cout << b+raw << endl;
}
for (char letter; letter<'zx'; letter++){
cout << letter << endl;
}
b=words[c];
c=c+1;
d=51;
}
}
// find string length
int wordlen(string words){
char i;
for(i = 0; words[i] != '\0'; ++i);
return i;
}
int forloop(){
string words="0123456789";
int i=10;
for(int j=0; j<i; j++){
cout << words[j] <<endl;
// here add Your function
}
return 0;
}
Some, Other Tries To Implement Python Like Function in C
// Author : Suraj Singh Bisht
// Email : surajsinghbisht054@gmail.com
// Code : C++
// ====================================================================================
// -------------------------X Trying Python Like Function x--------------------------
// ====================================================================================
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// ====================================================================================
// -----------------------x Function For Repeting Strings x----------------------------
// ====================================================================================
// Usages :
// cout << repeatchar("james", 20);
string repeatchar(char k[80], int times){
string storeobj;
for(int i=0; i<times; i++){
//cout << k << endl;
storeobj=storeobj+k;
}
return storeobj;
}
// ``````````````````````````````````````````````````````````````````````````````````````
// ======================================================================================
// --------------------x Function For Replacing 1 Character x----------------------------
// ======================================================================================
// Usages :
// cout << replacechar("This is suraj singh bisht", "suraj", "sagar")
string replacechar(string raw_data, string text_to_replace, string replace_with)
{
string str = raw_data ;
string str2 = text_to_replace;
if(str.find(str2)!=4294967295){
str.replace(str.find(str2),str2.length(),replace_with);
string storeobj = str;
return storeobj;
}else {
string storeobj = raw_data;
return storeobj;}
}
// ``````````````````````````````````````````````````````````````````````````````````````
// ======================================================================================
// --------------------x Function For Replacing All Character x-------------------------
// ======================================================================================
// Usages :
// cout << replaceall("This is suraj singh bisht", "suraj", "sagar")
string replaceall(string raw_data, string text_to_replace, string replace_with){
string storeobj1=raw_data, storeobj2=text_to_replace, storeobj3=replace_with, storeobj4="Nothing";
while(storeobj1!=storeobj4){
storeobj4=storeobj1;
storeobj1=replacechar(storeobj1,storeobj2, storeobj3);
}
return storeobj4;
}
// ``````````````````````````````````````````````````````````````````````````````````````
// ======================================================================================
// --------------------------x Main Function x-------------------------------
// ======================================================================================
// ``````````````````````````````````````````````````````````````````````````````````````
int main(){
int k=8;
for(int i=0; i<=k; i++){
cout << setw(8) << repeatchar("#", i) << repeatchar("#", i) << endl;
}
}
// =======================================================================================
// -----------------------------x Get String Length x-----------------------------------
// =======================================================================================
int wordlen(string words){
char i;
for(i = 0; words[i] != '\0'; ++i);
printf("Length of string: %d", i);
return 0;
// ========================================================================================
// --------------------------x for i in String x-------------------------------------------
// =========================================================================================
int forloop(){
string words="0123456789";
int i=10;
for(int j=0; j<i; j++){
cout << words[j] <<endl;
// here add Your function
}
return 0;
}
Please Forgive me, If There Is any type of mistake in these code because I Wrote These codes, When I was new in C programming. Actually, I am publishing these code Just to provide some useful examples for new C Programmer.
I hope, this Example Codes Are Helpful For You.
Have A Nice Day.