Reply to comment

Mobile Robotics Workshop - 3rd Session

Its our third session in Mobile Robotics Workshop. Five problems were given to be programmed in C. Although I prefer GCC (Gnu compiler collection) than Turbo C, I dont have a choice. Its not my pc. Its Windows XP. Not Linux!!! Not GNU!!!
 
Here are the problems:

  1. Write a program to print the squares of numbers from 1 to 10, inclusive.
  2. Write a program to input 5 numbers and print their average.
  3. Write a program to input 5 numbers and print the largest value.
  4. Write a program to input numbers until the user enters 0, and then print the average of all the numbers, not including the 0.
  5. Write a program to show the Fibonacci numbers less than 100.

 

Solution to Problem #1

#include<stdio.h>

int main(){
	int i;

	for(i = 1; i <= 10; i++)

		printf("%i  ", i*i);

	return 0;

}

 

Solution to Problem #2

#include<stdio.h>

int main(){
	int n = 5;

	int i;
	float sum = 0;
	float ave;

	float x;

	for(i = 0; i < n; i++){

		printf("enter number %i:  ", i+1);
		scanf("%f", &x);

		sum = sum + x;
	}

	ave = sum / n;

	printf("average = %.2f", ave);

	return 0;

}

 

Solution to Problem #3

#include<stdio.h>

int main(){
	int i;

	int n = 5;
	float x;
	float max;

	printf("enter number 1: ");
	scanf("%f", &max);

	for(i = 1; i < n; i++){

		printf("enter number %i: ", i+1);
		scanf("%f", &x);

		if( x > max)
			max = x;
	}

	printf("maximum : %.2f", max);
	return 0;

}

 

Solution to Problem #4

#include<stdio.h>

int main(){
	int i = 0;

	float x;
	float ave;
	float sum = 0;

	do{
		i++;
		printf("enter number %i:  ", i);

		scanf("%f", &x);
		sum += x;

	}while( x != 0);

	ave = sum / (i - 1);

	printf("average = %.2f", ave);

	return 0;

}

 

Solution to Problem #5

#include<stdio.h>

int main(){
	int x = 0;

	int y = 1;
	int z = x + y;

	while( z < 100 ){
		z = x + y;

		printf("%i  ", y);
		x = y;

		y = z;
	}

	return 0;

}

Reply

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.