wollacott 0 Light Poster

the last for loop i declared it inside, which doesnt work as a c program its c++ i need to declare it out side how do i do that?

#include <stdio.h>  
#include <string.h>  
#include <ctype.h>  
  
// Our function declaration saying it takes one string pointer and returns one string pointer.  
char * flipstring(char *stringtoflip);  
  
int main() {  
    // Strings to hold our lines (forward and backward)  
    char string[256];  
    char flipped[256];  
  
    // Our file pointers (one in and one out)  
    FILE * infile;  
    FILE * outfile;  
  
    // Open files to valid txt files  
    infile = fopen("input.txt","r");  
    outfile = fopen("output.txt","w");  
  
    // Loop through the input file reading each line up to 256 chars  
    while (fgets(string,256,infile) != NULL) {  
        printf("The value read in is: %s\n", string);  
  
        // Flip the string and copy it to our "flipped" string  
        strcpy(flipped,flipstring(string));  
  
        // Write "flipped" to output  
        printf("The value written is: %s\n",flipped);  
        fputs(flipped,outfile);  
    }  
  
    // Close files  
    fclose(infile);  
    fclose(outfile);  
  
    return 0;  
}  
  
// Flips strings by taking incoming string, loop in reverse  
// and write each char to reverse string. Return reverse string.  
char * flipstring(char *stringtoflip) {  
    char reverse[256];  
  
    int j = 0;  
  
    // Loop through each char of our string in reverse  
	
    for(int i = strlen(stringtoflip)-1; i>=0; i--)  
    {  
        // If it is a newline, just ignore for now.  
        if (stringtoflip[i] != '\n') {  
            reverse[j]=stringtoflip[i];  
            j++;  
        }  
    }  
  
    // Terminate the new reverse string.  
    reverse[j] = '\0';  
  
    // Return reverse string back to main()  
    return reverse;  
}
wollacott 0 Light Poster

i need my program to read in a file reverse it then write the file out.
i got the reverse correct but its not working.my errors are:
n.c:12: warning: passing argument 1 of 'fopen' from incompatible pointer type
n.c:21: warning: passing argument 1 of 'fopen' from incompatible pointer type
n.c:22: warning: passing argument 1 of 'fputs' from incompatible pointer type
n.c:22: error: too few arguments to function 'fputs'

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
 char string[256];
 char*filename[256];
 char*outfilen[256];
 char c;
 int len;
 FILE * infile=0;
FILE * outfile;
infile=fopen(filename,"r");
 fgets(string, sizeof string, stdin);
 len = (strlen(string) - 1);
 
 printf("Reverse string:\n");
 for(; len >= 0; len--)
        printf("%c",string[len]);

 printf("\n");
outfile=fopen(outfilen,"w");
fputs(outfile);
fclose(infile);
fclose(outfile);
}
wollacott 0 Light Poster

ok heres my code to reverse the string.

int main() {
 char string[256];
 int len;

 
 fgets(file, 256-1, stdin);
 len = (strlen(string) - 1);
 printf("You entered %s \nlength %d:\n", file, len);

 printf("Reverse string:");
 for(; len >= 0; len--)
        printf("%c",file[len]);

 printf("\n");

}
wollacott 0 Light Poster

You will read in a file supplied from the commandline (filename.ext,) and write/overwrite out a file which will be called (filename.ext.mng.)

This file will be essentially the same as the original file, but will have all characters on all lines the reverse of the original. For example:
The original file has:
Jack Spratt
could eat no fat.
His wife
could eat no lean.
The output file will look like:
ttartpS kcaJ
.taf on tae dluoc
efiw siH
.nael on tae dluoc

wollacott 0 Light Poster

aia i did as you said and i got
eof
bus error

wollacott 0 Light Poster

ok thanks so much guys. now with the code below my error now is
it prints
EOF
bus error

char buffer[5456556];

when i delete the above file my errors are
g.c:13: error: 'buffer' undeclared (first use in this function)
g.c:13: error: (Each undeclared identifier is reported only once
g.c:13: error: for each function it appears in.)
which is this line

while(fgets( buffer, sizeof buffer, myfileptr) != NULL)

#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
  FILE *myfileptr;
 char * fgets ( char * sc, int num, FILE * words );
 char buffer[5456556];
 const char* sc = argv[1];

  myfileptr=fopen("words","r");

    // gets() should be fgets. Please read the link posted for the function
 while(fgets( buffer, sizeof buffer, myfileptr) != NULL)
  {
    if(sc)
      printf("%s",sc);
      printf("EOF\n");
     if(strlen(sc)%2==0) printf("Word not palindrom");
  else
  {
    int i;
    for(i = 0; i < strlen(sc); i += 1)
      if(sc[i] != sc[strlen(sc) - 1 - i])
      {
        printf("Word not palindrom");
        break;
      }

    if(i==strlen(sc)) printf("The word is palindrom");
  }
  }
  }
wollacott 0 Light Poster

my error is now
g.c:12: warning: assignment from incompatible pointer type
if i do the follwing
fgets( buffer, sizeof buffer, myfileptr);
i get bus error
any ideas to fix the problem

#include <stdio.h>
#include <string.h>
main(char *sc)
{
  FILE *myfileptr;
 char * fgets ( char * sc, int num, FILE * words );
 char buffer[5456556];

  myfileptr=fopen("words","r");

    // gets() should be fgets. Please read the link posted for the function
  while(myfileptr=fgets( buffer, sizeof buffer, myfileptr));
  {
    if(sc)
      printf("%s",sc);
      printf("EOF\n");
     if(strlen(sc)%2==0) printf("Word not palindrom");
  else
  {
    int i;
    for(i = 0; i < strlen(sc); i += 1)
      if(sc[i] != sc[strlen(sc) - 1 - i])
      {
        printf("Word not palindrom");
        break;
      }

    if(i==strlen(sc)) printf("The word is palindrom");
  }
  }
  }
wollacott 0 Light Poster

g.c:12: warning: passing argument 1 of 'fgets' from incompatible pointer type
g.c:12: error: too few arguments to function 'fgets'
g.c:14: error: 'sc' undeclared (first use in this function)
g.c:14: error: (Each undeclared identifier is reported only once
g.c:14: error: for each function it appears in.)

#include <stdio.h>
#include <string.h>
main()
{
  FILE *myfileptr;
 char * fgets ( char * sc, int num, FILE * words );
 

  myfileptr=fopen("words","r");

    // gets() should be fgets. Please read the link posted for the function
  while((myfileptr=fgets(myfileptr))!=EOF)
  {
    if(sc)
      printf("%s",sc);
      printf("EOF\n");
     if(strlen(sc)%2==0) printf("Word not palindrom");
  else
  {
    int i;
    for(i = 0; i < strlen(sc); i += 1)
      if(sc[i] != sc[strlen(sc) - 1 - i])
      {
        printf("Word not palindrom");
        break;
      }

    if(i==strlen(sc)) printf("The word is palindrom");
  }
}
}
wollacott 0 Light Poster
#include <stdio.h>
#include<string.h>
main()
{

FILE * myfileptr; // a pointer declared to the file stream.
char sc; // a character which will be input from the file.

// main code...

myfileptr=fopen("words","r"); //open the file hopefully

while((sc=getc(myfileptr))!=EOF) //get a char
{

if(sc)printf("%c",sc); //dump it to screen

}
printf("EOF\n");

}




getc("%c",sc);
if(strlen(sc)%2==0) printf("Word not palindrom");
else
{
int i;
for(i=0;i<strlen(sc);i+=1)
if(sc[i]!=sc[strlen(sc)-1-i])
{
printf("Word not palindrom");
break;
}
if(i==strlen(sc)) printf("The word is palindrom");
}
}

i cant get my program to print this way
for example
ada palindrome
back not a palindrome
all i get is the words from the file it is opening.
now i get

g.c:26: error: parse error before string constant
g.c:26: warning: data definition has no type or sto

wollacott 0 Light Poster

need help with my program. it keeps repeating (NULL) instead of preinting hello backwards. if remove ca[5] i get bus error. any help please on how to fix it.

#include <stdio.h>

int main()
{
char ca[10];
ca[0] = 'H';
ca[1] = 'e'; 
ca[2] = 'l';
ca[3] = 'l';
ca[4] = 'o';
ca[5] = '\0';
printf("%s", ca[5],ca[4],ca[3],ca[2],ca[1],ca[0]);
getchar();
return 0;
}
wollacott 0 Light Poster

how would one do that?

wollacott 0 Light Poster

does anyone know how to give the characters of a string numeric variables? so when i can print the numeric variables in decending order so the word is read backwards?
for example
hello h=1 e=2 l=3 l=4 0=5
olleh

your help would be very appreciated, a snippet would be awesome, or a written code would be very great.

wollacott 0 Light Poster

You neglected to explain what the problem is.

the problem is as stated below

You may be familiar with palindromes... This is a word or phrase which is the same whether viewed as is or reversed.

For example:
Ada, is the same viewed either in normal direction or reversed.
Also, Madam, I'm Adam. is the same in either direction as well.
There are some things one has to consider...
Ignore capitalization (change all characters to uppercase, or lowercase.)
Ignore punctuation.
Ignore whitespace characters.
Problem:


You are to define a function int IsPalindromic(char * string) which will return a true value(1) when the passed in string parameter is palindromic, otherwise it will return a false value (0.)

You will test this with the above examples to see if it works (also some other which are not palindromic.)

Then using the following file: words
You will read in each word, and output the word only when it is palindromic.

wollacott 0 Light Poster

can anyone help me make my program work. after it capitalize i want it to reverse the new string. something like palindrome.

#include<stdio.h>
#include<ctype.h>
#include<string.h>
/*program begins here*/
int main()
{
    /**/
    char string[100];
    char *ptr = string;
/*shws the user what to do*/
    printf("Enter string and use a space after a fullstop\n");
/*gets the string that was entered*/
    gets(string);

/* looks at the first letter of string */
    *ptr = toupper(*ptr);
    
    /* going through the string entered*/
    while(*ptr)
    {
        if( isspace(*ptr) )
        {
            *(++ptr) = toupper(*ptr);
            
        }
        ++ptr;
    }
/*shows user the new string*/
    printf("your new string is %s\n",string);


}
// Reverse string function
int ReverseString(char *str)
{
     int x = strlen(str); //takes length of string
     for(int y = x; y >= (x/2)+1; y--) //for loop arranging the string
     {
          swap(str[x-y],str[y-1]); // swaps letters
     }
     return 0; //return
}
wollacott 0 Light Poster

can anyone help me convert my c program so it works on a linux system or mac? thank you.

#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int c;
int a, b;
char d;
pov:system("cls");
printf("Enter the first number\n");
a=getch()-48;
system("cls");
printf("Enter the function:\n");
d=getch();
system("cls");
printf("Enter the second number\n");
b=getch()-48;
system("cls");
while (0==0)
{
if (d=='*')
{
a=a*b;
}
if (d=='/')
{
a=a/b;
}
if (d=='+')
{
a=a+b;
}
if (d=='-')
{
a=a-b;
}
printf("value is %d \n",a);
printf("Press 'q' to quit, or press other key to repeat data input\n");
c=getch();
if((c=='q')||(c=='Q')) return;
goto pov;
}
}
wollacott 0 Light Poster

Write functions to:
void clearscreen(void); /* Clears the screen for update, hint call system("clear") */
float calc(float num1,float num2,char operator); /* calculate the result of num1 operator num2 */
any other functions which you deem necessary.
Write a main program which will display a title line centered at the top of the screen

like: Fred's Calculator

and basically sit and wait for input from the keyboard.

Your program will respond to the numeric keys and form up a number on the result line, below the title (refreshing on every keypress)

Your program will also respond to the basic function keys... + - * / taking the previously entered value and then performing the action on the next entered value... just like your handheld calculator.

The enter key will replace the = key in the program.

The q key will shut down the program cleanly.

Make certain your program is well documented and executes correctly, make certain it accepts all keyboard input but then responds only to the ones listed above and ignores the rest. Use getch() to pull in input from the keyboard on a character by character basis.
heres my program to far:
i need to know how to clear screen and also how to get the numeric keys without pressing enter.

#include<math.h>
#include<stdio.h>
#include<curses.h>

int main(void)
{
float num1,num2,answer,i;
char c;
printf("\t\t\t""kieran's calculator!!!\n");
printf("\t\t\t\t""%f\n",answer);
printf("A Adition\n");
printf("S Subtraction\n");
printf("M Multiplication\n");
printf("D Division\n");
printf("R Squareroot\n"); …
wollacott 0 Light Poster

i have to create a calculator which i have but i cant get it to run yet. i keep getting "12: error: subscripted value is neither array nor pointer" i'll highlight it for you. if anyone can fix it please do thank you.

#include<math.h>
#include<stdio.h>
int main()
{
float num1,num2,answer,i;
char c, menu;

display_menu ();
{
int i;
for (i=0; i<=4;i++)
[B]printf("%s\n",menu [i]);[/B]
}
char menu_item[7][14]={"Adition","Subtraction","Multiplcation","division","squareroot","percentage","Quit"};

get_input();
{
char c;
while (1)
{
display_menu();
printf("enter command\n");
c=getch();
switch (c)
{
case 'A':
case'a': Addition();
printf("enter two numbers:\n");
scanf("%f",&num1);
scanf("%f",&num2);
answer=num1+num2;
break;
case'S':
case's': Subtraction();
printf("Enter two numbers to subtract:\n");
scanf("%f",&num1);
scanf("%f",&num2);
if (num1>num2) {
answer=num1-num2;
}
 else  if (num1<num2){
 answer=num2-num1;
 }
 break;
 case'M':
 case'm': Multiplication();
 printf("enter two numbers to multiply:\n");
 scanf("%f",&num1);
scanf("%f",&num2);
answer=num1*num2;
break;
case'D':
case'd': Division();
printf("enter");
scanf("%f",&num1);
scanf("%f",&num2);
answer=num1/num2;
break;
case'R':
case'r': Squareroot();
printf("enter number to be square rooted:\n");
scanf("%f",&num1);
answer = sqrt(num1);
break;
case'P':
case'p': Percentage();
printf("Enter first number to be the percent and the second number to be\n");
scanf("%f",&num1);
scanf("%f",&num2);
answer = num1*num2/100;
break;
case'Q':
case'q': return;
}
printf("Answer is %f\n",answer);
}
}
}
wollacott 0 Light Poster

ok i need to do a program that inputs a amount of characters. my program has to capitalize the first letter and and letter after a full stop. any ideas and hints how to do it?

wollacott 0 Light Poster

umm no it just wanted to do a fibonacci series using prime

wollacott 0 Light Poster
#include<stdio.h>
main()
{
static int n=0, number=1; 
int fibi (int n, int number);
printf ("Following are the first 40 Numbers of the Fibonacci Series:\n");
printf ("1 ");
fib (n,number);
}
fib (int n, int number)
{
static int i=1; 
int fibo;
if (i==40)
{
printf ("\ndone"); 
}
else 
{
fibo=n+number;
n=number;
number=fibo; 
printf ("\n%d", fibo);
i++; 
fib (n,number); 
}
}

my program shows the following.
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
i want my program to show
1
2 prime
3 prime
5 prime
8
13 prime
21
34
55
89 prime
144
233 prime
377
610
987
1597 prime
2584
4181
6765
10946
17711
28657 prime
please help me!!!!!!

wollacott 0 Light Poster

ok this is my code so far i have to use " isprime" to calculate prime number how do i do thatand where do i put it.thank you

#include<stdio.h>
main()
{
static int n=0, number=1; // static: so value is not lost
int fibi (int n, int number);
printf ("Following are the first 25 Numbers of the Fibonacci Series:\n");
printf ("1 "); //to avoid complexity
fib (n,number);
}
fib (int n, int number)
{
static int i=1; //i is not 0, cuz 1 is already counted in main. 
int fibo;
if (i==40)
{
printf ("\ndone"); //stop after 25 numbers
}
else 
{
fibo=n+number;
n=number; //important steps
number=fibo; 
printf ("\n%d", fibo);
i++; // increment counter 
fib (n,number); //recursion
}
}
wollacott 0 Light Poster

can anyone help me?

Write functions to:
int isprime(int); /* Returns a true value if a is a prime number */
int nextFib(); /* Returns the next fibonacci value (use static variables to track which one was used last call) */
The fibonacci sequence is defined as:
Fib(0)=1

Fib(1)=1

Fib(2)=Fib(1)+Fib(0)

....

Fib(N)=Fib(N-1)+Fib(N-2)

Write a main program which will call nextFib 40 times and the check to see whether the each fibonacci number is prime using isprime.
Your program will then report the sequence number, the fibonacci value, and whether or not the number is prime.

wollacott 0 Light Poster

my program stops right before the while loop

#include <stdio.h>
int main()
{
	int pay_type_1;
	int overtime;
	int num;
	float commissionsale;
	float payperitem;
	float salary;
	float hourrate;
	const float commissionrate=0.057;
	const float commissionpay=250;
	const float overtimerate=1.5;
	printf("paytype1=Managers salary\n");
	printf("paytype2=hourly worker\n");
	printf("paytype3=commision worker\n");
	printf("paytype4=piece worker\n");
	while (pay_type_1 > 0)
	{
		printf("enter pay type number from above\n (-1 to end)");
		scanf("%d",&pay_type_1);
		switch(pay_type_1)
		{
			case 1:
			printf("Enter manager' fixed salary\n");
			scanf("%f",&salary);
			break;
			case 2:
			printf("Enter hourly rate for paytype two worker\n");
			scanf("%f",&hourrate);
			printf("enter overtime hours worked by the paytype two worker\n");
			scanf("%d",&overtime);
			salary=(hourrate*40)+(overtime*(hourrate*overtime));
			break;
			case 3: 
			printf("enter total sales from paytype three worker\n");
			scanf("%f",&commissionsale);
			salary=commissionpay+(commissionsale*commissionrate);
			break;
			case 4:
			printf("enter nuber of item made by paytype four worker\n");
			scanf("%d",&num);
			printf("enter pay per item\n");
			scanf("%f",&payperitem);
			break;
		}
		printf("Salary:%7.2lf\n",salary);
	}
}

can you see and tell me why its not working. thanks

wollacott 0 Light Poster

A company pays its employees as managers (who recieve a fixed weekly salary), hourly workers (who recieve a fixed hourly wage for up to the first 40 hours they work and "time- and a half"-1.5 times their hourly wage-for overtime hours worked), commission workes (who recieve $250 plus 5.7% of their gross weekly sales), or pieceworkers (who recieve a fixed amount of money per item for each of hte items they produce-each pieceworker in this company works on only one type of item). Can anyone help me out with the source code to calculate the weekly pay for each employee. there is no number of employees in advance. each type of employee has its own pay code managers have paycode , hourly workers have pay code 2, commission workers have code 3 and pieceworkers have code 4.I need to use a switch to compute each employees pay according to that employees paycode. within the switch, i need to prompt the user (i.e...the payroll clerk) to enter the appropriate facts it needs to calculate each employee's pay according to that employee's paycode.

#include <stdio.h>
int main()
{
	int employeenum;
	int name;
int paytype;
int paytype1;
int paytype2;
int paytype3;
int paytype4;
int salary;
int overtimehr;
int commsale;
int hrrate;
int commpay= 250;
float commrate=0.057;
int numitems;
int payperitem;
float overtimerate=1.5;
printf("manager=1,workers=2,commison workers=3,piece workers=4\n");
printf("Enter employee name\n");
scanf("%d",&name);
printf("Enter Employee number\n");
scanf("%d",&employeenum);
printf("Enter payrate or salary\n");
scanf("%d",&salary);
printf("Enter hourly rate for worker\n");
scanf("%d",&hrrate);
printf("Enter total sales made by the paycode three …
wollacott 0 Light Poster

i havent tried it yet caz i'm stuck here what shud i put after & so it can work?
printf( "Enter product number \n");
scanf("%f",&);

printf( "Enter quantity : \n" );
scanf("%f",&);

wollacott 0 Light Poster

a mail order hopuse sells five different products whose retail prices are shown below
product number retail price
1-5 2.98,4.50,9.98,4.49,6.87
your program should use a switch statements to help determine the retail price for each product. your program shoulds also calculate and display the total retail value of all products sold last week.

wollacott 0 Light Poster

can anyone help me finish my program please. thank you

#include <stdio.h>
#include <math.h>
int main()

{
int product;
float product1 = 2.98; 
float product2 = 4.50;  
float product3 = 9.98; 
float product4 = 4.49; 
float product5 = 6.87;
float quantity = 1;
double unitprice;
float result;
double total;

printf( "Enter product number \n");
scanf("%f",&);

printf( "Enter quantity : \n" );
scanf("%f",&);

switch(product) {
case 1:
unitprice = 2.98;
break;
case 2:
unitprice = 4.50;
break;
case 3:
unitprice = 9.95;
break;
case 4:
unitprice = 3.89;
case 5:
unitprice = 9.98;
break;
default:



total = unitprice * quantity;
	printf( "total is:",total);
}
}
wollacott 0 Light Poster

ok people i wrote this code myself. i just need your help so this program can accept any digits and print the decimal equivalent. i worte more than i needed too because i wasnt so sure how muchi needed. i dont think it works very well. i tried 1101 and i shud have gotten 13, but i got 8. please help me.

# include<math.h>
# include <stdio.h>
int main()
{
int num;
int fig1,fig2,fig3,fig4,fig5,fig6,fig7,decimal_value,value_1 ,value_2,value_3,value_4,value_5,value_6,value_7;

printf("Enter a binary number:");
scanf("%d",&num);

fig1 =  num /1000000;
num %= 1000000;
fig2 = num/100000;
num %= 100000;
fig3 = num / 10000; 
num %= 10000; 
fig4 = num / 1000; 
num %= 1000; 
fig5 = num / 100; 
num %= 100; 
fig6 = num / 10;
num %= 10;
fig7 = num;

value_1=fig1*64;
value_2=fig2*32;
value_3=fig3*16;
value_4=fig4*8;
value_5=fig5*4;
value_6=fig6*2;
value_7=fig7*1;


decimal_value= value_1 + value_2 + value_3 + value_4,value_5,value_6,value_7;

printf("the decimal value of the binary number entered is: %d",decimal_value);

}
wollacott 0 Light Poster

hey thanks for the help but i keep getting this error

new.c: In function 'base_numeric':
new.c:12: warning: incompatible implicit declaration of built-in function 'pow'
new.c:16: warning: incompatible implicit declaration of built-in function 'printf'
/usr/bin/ld: Undefined symbols:
_main
collect2: ld returned 1 exit status

wollacott 0 Light Poster

Input an integer containing only 0’s and 1’s( ie. “binary” integer) and print its decimal equivalent. {hint: use the remainder and division operators to pick off the binary numbers digits one at a time from right to left. Just as in the decimal number system, in which the right most digit has a positional value of 1, and the next digit has a positional value of 10, then 100, then 1000, and so on, in the binary number system the rightmost digit has a positional value of 1, the next digit left has a positional value of 2, then 4, then 8, and so on. Thus the decimal number 234 can be interpreted as 4*1+3*10+2*100. The decimal equivalent of binary 1101 is 1*1+0*2+1*4+1*8 or 1+0+4+8 or 13.}

#include <stdio.h>


{

int base_numeric() { // works with any base 2..10
int number = 1101; // binary number 
int base = 2; // from base 2

int i = 0;
int r = 0;
while (number > 0) {
int digit = number % 10; // extract 1 digit (no matter base)
int mult = (int) pow (base, i++); // calculate base ^ i (0, 1, 2, etc)
r += digit * mult; // multiply the previous calc with digit
number /= 10; // remove the last digit
}
return r;
}
wollacott 0 Light Poster

Input an integer containing only 0’s and 1’s( ie. “binary” integer) and print its decimal equivalent. {hint: use the remainder and division operators to pick off the binary numbers digits one at a time from right to left. Just as in the decimal number system, in which the right most digit has a positional value of 1, and the next digit has a positional value of 10, then 100, then 1000, and so on, in the binary number system the rightmost digit has a positional value of 1, the next digit left has a positional value of 2, then 4, then 8, and so on. Thus the decimal number 234 can be interpreted as 4*1+3*10+2*100. The decimal equivalent of binary 1101 is 1*1+0*2+1*4+1*8 or 1+0+4+8 or 13.}
int base_numeric() { works with any base 2-10
int number = 1101; binary number
int base = 2; from base 2
int i = 0;
int r = 0;
while (number > 0) {
int digit = number % 10; extract 1 digit (no matter base)
int mult = (int)pow(base, i++); calculate base ^ i (0, 1, 2,
r += digit * mul
number/=10;
}
return r
}

wollacott 0 Light Poster

already got it working. thanks

wollacott 0 Light Poster

what are code tags?

wollacott 0 Light Poster

Write a program that utilizes looping to print the following table of values?

wollacott 0 Light Poster

Input an integer containing only 0’s and 1’s( ie. “binary” integer) and print its decimal equivalent. {hint: use the remainder and division operators to pick off the binary numbers digits one at a time from right to left. Just as in the decimal number system, in which the right most digit has a positional value of 1, and the next digit has a positional value of 10, then 100, then 1000, and so on, in the binary number system the rightmost digit has a positional value of 1, the next digit left has a positional value of 2, then 4, then 8, and so on. Thus the decimal number 234 can be interpreted as 4*1+3*10+2*100. The decimal equivalent of binary 1101 is 1*1+0*2+1*4+1*8 or 1+0+4+8 or 13.}

#include <stdio.h>
int bin;
int dec = 0;
scanf("%d",& bin);
int pos = 1;
while (bin) {
int digit = bin % 10;
dec += digit * pos;
bin /= 10;
pos *= 2;
}
printf("%d", dec);

wollacott 0 Light Poster

N 10*N 100*N 1000* N
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000
6 60 600 6000
7 70 700 7000
8 80 800 8000
9 90 900 9000
10 100 1000 10000


Hi,

#include<stdio.h>


int main()
{
int i;
for(i=1;i<=10;i++)
printf("%d, %d, %d, %d",i,i*10,i*100,i*1000);

}
wollacott 0 Light Poster

but will my code work if i enter one single digit?

wollacott 0 Light Poster

enter 5 digit number s and have them display in single digits,using division and the remainder mod.
This is what i have so far but it doesnt seem to work.
#include <stdio.h>
int main()

{
int num1,num2,num3,num4,num5,number;
printf("enter five digit number");
scanf("%d,%d,%d,%d,%d",&num1,&num2,&num3,&num4,&num5);
num1r=(number-(number%10000))/10000;
num2=(number%10000-(number%1000))/1000;
num3=(number%1000-(number%100))/100;
num4=(number%100-(number%10))/10;
num5=(number%10-(number%1))/1;
printf("first number is %d%d%d%d%d ",num1,num2,num3,num4,num5);
}