Home › Forums › C Programming › Problem solving few assignments in C language

- This topic has 4 replies, 3 voices, and was last updated 14 years, 9 months ago by NAYAN.

- AuthorPosts
- July 19, 2007 at 4:56 am #1987mulayimParticipant
Hey,

I have this problem. I have to 25 assignments in C language but there still are 9 assignments I can’t solve. I’m not good at the C language. In most cases I know what the program is supposed to do but I can’t seem to find the right code to use.

Can somebody help me out?

The Assignments are listed below:

17. Write a program were you put in a number via scanf. The program must give an output (via printf) from the sum of all the numbers from 1 to the number from the input. So if I would enter 5 for the input. The output should be 1+2+3+4+5 = 15

18. Make a program wich determines the sum of a few whole numbers entered via the keybord. The entered numbers must end with a zero. Use a While loop.

19. Write a program using a for loop wich gives the following output:

*

**

***

****

*****

Use for printf only printf(‘*’). so for the number of stars a loop is required.

20. Ajust the last program so the following output apears:

*

**

***

*****

Use the if else statement

21. We start with a function that doesn’t give a value back to the main program. Make a function that recalculates a weight in Kilogram entered by the keybord into gram and print it on the screen.

22. Make a function that asks a number for the input and for the output it should multiply itself. So the quadrat??(don’t know the word in english) of the input.

23. Make a program that calculates the the sum of the numbers 1 till n. The value of n must be entered by the user. Use loops and make youre own function to keep the program clear and easy to read.

24. For straightcorner triangles the pythagoras statement determines. The sum of the quadrates of the straightcorners sides is equal to the quadrate of the length of the long side. Make a prgram that finds al the integers for the sides, just like the familliar triangle 3,4,5(5^2 = 3^2 + 4^2). Limit youre search for sides with a maximum length of 100.

25. The syracusrow is a row of numbers starting with with a positive integer. The next number is determined as below:

If the number isn’t even: next number = number *3+1

If the number is even: Next number = number /2

The syracusrow starting with number 22 looks like this:

22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

First make a complete and clear working design for a program that prints the syracusrow on the screen for the number from the input.

You would really help me with this because I’m like really stressing out right now.Thanks!

Herman - August 10, 2007 at 4:57 am #3235bhavinParticipant
Question 19 answer:

12345678910111213#include<stdio.h><br />#include<conio.h><br />void main(){<br />int i,j;clrscr();<br />for(i=1;i<=5;i++){<br />for(j=1;j<=i;j++){<br />printf("*"); <br />} <br />printf("n");<br />}<br />getch();<br />}<br />output:

*

*****

****

***** - August 10, 2007 at 5:00 am #3236bhavinParticipant
qution no 20: answer

1234567891011121314151617181920<br />#include<stdio.h><br />#include<conio.h><br />void main()<br />{<br />int i,j;<br />clrscr();<br /><br />for(i=1;i<=5;i++)<br />{<br />if(i==4)<br />i=4+1;<br />for(j=1;j<=i;j++)<br />{<br />printf("*");<br />}<br />printf("n");<br />}<br />getch();<br />}output:

*

**

***

***** - August 10, 2007 at 5:14 am #3237bhavinParticipant
Q.21 answer:

12345678910111213141516171819#include<stdio.h><br />#include<conio.h><br />int convert(float a);<br />void main()<br />{<br />float k;<br />clrscr();<br />printf("Enter any wieght in KG:");<br />scanf("%f",&k);<br />convert(k);<br />getch();<br />}<br />int convert(float r)<br />{<br />int a;<br />a=r*1000;<br />printf("nGram Value is = %dgrams",a);<br />return(0);<br />}output:

enter any weight in kg 2gram value is = 2000grams

- August 17, 2007 at 3:25 am #3238NAYANParticipant
question no:17 answer

12345678910111213#include<stdio.h><br />#include<conio.h><br />main()<br />{<br />int n,sum=0,i;<br />printf("enter a number");<br />scnaf("%d",&n);<br />for(i=0;i<n;i++)<br />{<br />sum=sum+i;<br />}<br />printf("n the sum is %d",sum);<br />}

- AuthorPosts

- The forum ‘C Programming’ is closed to new topics and replies.